|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
#include <errno.h> |
|
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
|
|
#include "common/util.h" |
|
|
|
|
|
|
|
|
@ -51,11 +52,20 @@ std::string read_file(const std::string& fn) { |
|
|
|
|
std::ifstream ifs(fn, std::ios::binary | std::ios::ate); |
|
|
|
|
if (ifs) { |
|
|
|
|
std::ifstream::pos_type pos = ifs.tellg(); |
|
|
|
|
std::string result; |
|
|
|
|
result.resize(pos); |
|
|
|
|
ifs.seekg(0, std::ios::beg); |
|
|
|
|
ifs.read(result.data(), pos); |
|
|
|
|
if (ifs) return result; |
|
|
|
|
if (pos != std::ios::beg) { |
|
|
|
|
std::string result; |
|
|
|
|
result.resize(pos); |
|
|
|
|
ifs.seekg(0, std::ios::beg); |
|
|
|
|
ifs.read(result.data(), pos); |
|
|
|
|
if (ifs) { |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// handle files created on read, e.g. procfs
|
|
|
|
|
std::stringstream buffer; |
|
|
|
|
buffer << ifs.rdbuf(); |
|
|
|
|
return buffer.str(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|