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

Method Open

src/flatfile.cpp:35–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33}
34
35FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool read_only) const
36{
37 if (pos.IsNull()) {
38 return nullptr;
39 }
40 fs::path path = FileName(pos);
41 fs::create_directories(path.parent_path());
42 FILE* file = fsbridge::fopen(path, read_only ? "rb": "rb+");
43 if (!file && !read_only)
44 file = fsbridge::fopen(path, "wb+");
45 if (!file) {
46 LogError("Unable to open file %s", fs::PathToString(path));
47 return nullptr;
48 }
49 if (pos.nPos && fseek(file, pos.nPos, SEEK_SET)) {
50 LogError("Unable to seek to position %u of %s", pos.nPos, fs::PathToString(path));
51 if (fclose(file) != 0) {
52 LogError("Unable to close file %s", fs::PathToString(path));
53 }
54 return nullptr;
55 }
56 return file;
57}
58
59size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_of_space) const
60{

Callers

nothing calls this directly

Calls 3

fopenFunction · 0.85
PathToStringFunction · 0.85
IsNullMethod · 0.45

Tested by

no test coverage detected