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

Function OpenDiskFile

src/validation.cpp:4028–4049  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4026}
4027
4028static FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
4029{
4030 if (pos.IsNull())
4031 return nullptr;
4032 fs::path path = GetBlockPosFilename(pos, prefix);
4033 fs::create_directories(path.parent_path());
4034 FILE* file = fsbridge::fopen(path, fReadOnly ? "rb": "rb+");
4035 if (!file && !fReadOnly)
4036 file = fsbridge::fopen(path, "wb+");
4037 if (!file) {
4038 LogPrintf("Unable to open file %s\n", path.string());
4039 return nullptr;
4040 }
4041 if (pos.nPos) {
4042 if (fseek(file, pos.nPos, SEEK_SET)) {
4043 LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
4044 fclose(file);
4045 return nullptr;
4046 }
4047 }
4048 return file;
4049}
4050
4051FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly) {
4052 return OpenDiskFile(pos, "blk", fReadOnly);

Callers 2

OpenBlockFileFunction · 0.85
OpenUndoFileFunction · 0.85

Calls 3

GetBlockPosFilenameFunction · 0.85
fopenFunction · 0.85
IsNullMethod · 0.45

Tested by

no test coverage detected