MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ReadBinaryFile

Function ReadBinaryFile

src/util/readwritefile.cpp:15–34  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

TorControllerMethod · 0.85
protocolinfo_cbMethod · 0.85
BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 2

fopenFunction · 0.85
sizeMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68