| 3774 | } |
| 3775 | |
| 3776 | FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) |
| 3777 | { |
| 3778 | if (pos.IsNull()) |
| 3779 | return NULL; |
| 3780 | boost::filesystem::path path = GetBlockPosFilename(pos, prefix); |
| 3781 | boost::filesystem::create_directories(path.parent_path()); |
| 3782 | FILE* file = fopen(path.string().c_str(), "rb+"); |
| 3783 | if (!file && !fReadOnly) |
| 3784 | file = fopen(path.string().c_str(), "wb+"); |
| 3785 | if (!file) { |
| 3786 | LogPrintf("Unable to open file %s\n", path.string()); |
| 3787 | return NULL; |
| 3788 | } |
| 3789 | if (pos.nPos) { |
| 3790 | if (fseek(file, pos.nPos, SEEK_SET)) { |
| 3791 | LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string()); |
| 3792 | fclose(file); |
| 3793 | return NULL; |
| 3794 | } |
| 3795 | } |
| 3796 | return file; |
| 3797 | } |
| 3798 | |
| 3799 | FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly) { |
| 3800 | return OpenDiskFile(pos, "blk", fReadOnly); |
no test coverage detected