MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / OpenDiskFile

Function OpenDiskFile

src/persistence/disk.cpp:39–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37// global functions
38
39FILE *OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) {
40 if (pos.IsNull())
41 return nullptr;
42 boost::filesystem::path path = GetDataDir() / "blocks" / strprintf("%s%05u.dat", prefix, pos.nFile);
43 boost::filesystem::create_directories(path.parent_path());
44 FILE *file = fopen(path.string().c_str(), "rb+");
45 if (!file && !fReadOnly)
46 file = fopen(path.string().c_str(), "wb+");
47 if (!file) {
48 LogPrint(BCLog::ERROR, "Unable to open file %s\n", path.string());
49 return nullptr;
50 }
51
52 if (pos.nPos) {
53 if (fseek(file, pos.nPos, SEEK_SET)) {
54 LogPrint(BCLog::ERROR, "Unable to seek to position %u of %s\n", pos.nPos, path.string());
55 fclose(file);
56 return nullptr;
57 }
58 }
59 return file;
60}
61
62FILE *OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly) {
63 return OpenDiskFile(pos, "blk", fReadOnly);

Callers 2

OpenBlockFileFunction · 0.85
OpenUndoFileFunction · 0.85

Calls 2

fopenFunction · 0.85
IsNullMethod · 0.45

Tested by

no test coverage detected