mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
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:
@@ -37,7 +37,7 @@ bool CBanDB::Write(const banmap_t& banSet)
|
||||
|
||||
// open temp output file, and associate with CAutoFile
|
||||
fs::path pathTmp = GetDataDir() / tmpfn;
|
||||
FILE *file = fopen(pathTmp.string().c_str(), "wb");
|
||||
FILE *file = fsbridge::fopen(pathTmp, "wb");
|
||||
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
|
||||
if (fileout.IsNull())
|
||||
return error("%s: Failed to open file %s", __func__, pathTmp.string());
|
||||
@@ -62,7 +62,7 @@ bool CBanDB::Write(const banmap_t& banSet)
|
||||
bool CBanDB::Read(banmap_t& banSet)
|
||||
{
|
||||
// open input file, and associate with CAutoFile
|
||||
FILE *file = fopen(pathBanlist.string().c_str(), "rb");
|
||||
FILE *file = fsbridge::fopen(pathBanlist, "rb");
|
||||
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
|
||||
if (filein.IsNull())
|
||||
return error("%s: Failed to open file %s", __func__, pathBanlist.string());
|
||||
@@ -134,7 +134,7 @@ bool CAddrDB::Write(const CAddrMan& addr)
|
||||
|
||||
// open temp output file, and associate with CAutoFile
|
||||
fs::path pathTmp = GetDataDir() / tmpfn;
|
||||
FILE *file = fopen(pathTmp.string().c_str(), "wb");
|
||||
FILE *file = fsbridge::fopen(pathTmp, "wb");
|
||||
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
|
||||
if (fileout.IsNull())
|
||||
return error("%s: Failed to open file %s", __func__, pathTmp.string());
|
||||
@@ -159,7 +159,7 @@ bool CAddrDB::Write(const CAddrMan& addr)
|
||||
bool CAddrDB::Read(CAddrMan& addr)
|
||||
{
|
||||
// open input file, and associate with CAutoFile
|
||||
FILE *file = fopen(pathAddr.string().c_str(), "rb");
|
||||
FILE *file = fsbridge::fopen(pathAddr, "rb");
|
||||
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
|
||||
if (filein.IsNull())
|
||||
return error("%s: Failed to open file %s", __func__, pathAddr.string());
|
||||
|
||||
Reference in New Issue
Block a user