Use fsbridge for fopen and freopen

Abstracts away how a path is opened to a `FILE*`.

Reduces the number of places where path is converted to a string
for anything else but printing.
This commit is contained in:
Wladimir J. van der Laan
2017-03-01 16:28:39 +00:00
parent bac5c9cf64
commit 2a5f574762
5 changed files with 19 additions and 19 deletions

View File

@@ -3414,9 +3414,9 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
return NULL;
fs::path path = GetBlockPosFilename(pos, prefix);
fs::create_directories(path.parent_path());
FILE* file = fopen(path.string().c_str(), "rb+");
FILE* file = fsbridge::fopen(path, "rb+");
if (!file && !fReadOnly)
file = fopen(path.string().c_str(), "wb+");
file = fsbridge::fopen(path, "wb+");
if (!file) {
LogPrintf("Unable to open file %s\n", path.string());
return NULL;
@@ -4164,7 +4164,7 @@ static const uint64_t MEMPOOL_DUMP_VERSION = 1;
bool LoadMempool(void)
{
int64_t nExpiryTimeout = GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60;
FILE* filestr = fopen((GetDataDir() / "mempool.dat").string().c_str(), "rb");
FILE* filestr = fsbridge::fopen(GetDataDir() / "mempool.dat", "rb");
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
if (file.IsNull()) {
LogPrintf("Failed to open mempool file from disk. Continuing anyway.\n");
@@ -4244,7 +4244,7 @@ void DumpMempool(void)
int64_t mid = GetTimeMicros();
try {
FILE* filestr = fopen((GetDataDir() / "mempool.dat.new").string().c_str(), "wb");
FILE* filestr = fsbridge::fopen(GetDataDir() / "mempool.dat.new", "wb");
if (!filestr) {
return;
}