| 5321 | } |
| 5322 | |
| 5323 | FILE* OpenDiskFile(const CDiskBlockPos& pos, const char* prefix, bool fReadOnly) |
| 5324 | { |
| 5325 | if (pos.IsNull()) |
| 5326 | return NULL; |
| 5327 | boost::filesystem::path path = GetBlockPosFilename(pos, prefix); |
| 5328 | boost::filesystem::create_directories(path.parent_path()); |
| 5329 | FILE* file = fopen(path.string().c_str(), "rb+"); |
| 5330 | if (!file && !fReadOnly) |
| 5331 | file = fopen(path.string().c_str(), "wb+"); |
| 5332 | if (!file) { |
| 5333 | LogPrintf("Unable to open file %s\n", path.string()); |
| 5334 | return NULL; |
| 5335 | } |
| 5336 | if (pos.nPos) { |
| 5337 | if (fseek(file, pos.nPos, SEEK_SET)) { |
| 5338 | LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string()); |
| 5339 | fclose(file); |
| 5340 | return NULL; |
| 5341 | } |
| 5342 | } |
| 5343 | return file; |
| 5344 | } |
| 5345 | |
| 5346 | FILE* OpenBlockFile(const CDiskBlockPos& pos, bool fReadOnly) |
| 5347 | { |
no test coverage detected