MCPcopy Create free account
hub / github.com/ElementsProject/elements / ReadBinaryFile

Function ReadBinaryFile

src/util/readwritefile.cpp:13–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#include <utility>
12
13std::pair<bool,std::string> ReadBinaryFile(const fs::path &filename, size_t maxsize=std::numeric_limits<size_t>::max())
14{
15 FILE *f = fsbridge::fopen(filename, "rb");
16 if (f == nullptr)
17 return std::make_pair(false,"");
18 std::string retval;
19 char buffer[128];
20 do {
21 const size_t n = fread(buffer, 1, sizeof(buffer), f);
22 // Check for reading errors so we don't return any data if we couldn't
23 // read the entire file (or up to maxsize)
24 if (ferror(f)) {
25 fclose(f);
26 return std::make_pair(false,"");
27 }
28 retval.append(buffer, buffer+n);
29 } while (!feof(f) && retval.size() <= maxsize);
30 fclose(f);
31 return std::make_pair(true,retval);
32}
33
34bool WriteBinaryFile(const fs::path &filename, const std::string &data)
35{

Callers 3

TorControllerMethod · 0.85
protocolinfo_cbMethod · 0.85

Calls 2

fopenFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected