| 4026 | } |
| 4027 | |
| 4028 | static 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 | |
| 4051 | FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly) { |
| 4052 | return OpenDiskFile(pos, "blk", fReadOnly); |
no test coverage detected