Skip to content

Commit d87a37a

Browse files
committed
Merge bitcoin/bitcoin#24167: fs: consistently use fsbridge:: for ifstream / ofstream
5e8975e fs: consistently use fsbridge for fopen() (fanquake) 486261d fs: add missing <cassert> include (fanquake) 21f781a fs: consistently use fsbridge for {i,o}fstream (fanquake) Pull request description: These changes are part of #20744, but are also ok to do now, and reduce the diff in that PR. See commit messages for details. Revived from #23857. ACKs for top commit: laanwj: Code review ACK 5e8975e MarcoFalke: ACK 5e8975e 🏕 Tree-SHA512: ee2dc857ce2479b39b65615e689f934b962e580299b0e7a0c6361633402b0d61e6e4479f41f6480e2c46101264d93f330b8f7b57e56df95a7f77e046a4e44697
2 parents 4241c19 + 5e8975e commit d87a37a

File tree

9 files changed

+13
-10
lines changed

9 files changed

+13
-10
lines changed

src/bench/bench.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
#include <bench/bench.h>
66

7+
#include <fs.h>
78
#include <test/util/setup_common.h>
89

910
#include <chrono>
10-
#include <fstream>
1111
#include <functional>
1212
#include <iostream>
1313
#include <map>
@@ -29,7 +29,7 @@ void GenerateTemplateResults(const std::vector<ankerl::nanobench::Result>& bench
2929
// nothing to write, bail out
3030
return;
3131
}
32-
std::ofstream fout(filename);
32+
fsbridge::ofstream fout{fs::PathFromString(filename)};
3333
if (fout.is_open()) {
3434
ankerl::nanobench::render(tpl, benchmarkResults, fout);
3535
} else {

src/bitcoin-tx.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <consensus/consensus.h>
1313
#include <core_io.h>
1414
#include <key_io.h>
15+
#include <fs.h>
1516
#include <policy/policy.h>
1617
#include <policy/rbf.h>
1718
#include <primitives/transaction.h>
@@ -158,7 +159,7 @@ static void RegisterLoad(const std::string& strInput)
158159
std::string key = strInput.substr(0, pos);
159160
std::string filename = strInput.substr(pos + 1, std::string::npos);
160161

161-
FILE *f = fopen(filename.c_str(), "r");
162+
FILE *f = fsbridge::fopen(filename.c_str(), "r");
162163
if (!f) {
163164
std::string strErr = "Cannot open file " + filename;
164165
throw std::runtime_error(strErr);

src/fs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#ifndef WIN32
88
#include <cstring>
99
#include <fcntl.h>
10-
#include <string>
1110
#include <sys/file.h>
1211
#include <sys/utsname.h>
1312
#include <unistd.h>
@@ -20,6 +19,9 @@
2019
#include <windows.h>
2120
#endif
2221

22+
#include <cassert>
23+
#include <string>
24+
2325
namespace fsbridge {
2426

2527
FILE *fopen(const fs::path& p, const char *mode)

src/qt/psbtoperationsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void PSBTOperationsDialog::saveTransaction() {
158158
if (filename.isEmpty()) {
159159
return;
160160
}
161-
std::ofstream out(filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary);
161+
fsbridge::ofstream out{filename.toLocal8Bit().data(), fsbridge::ofstream::out | fsbridge::ofstream::binary};
162162
out << ssTx.str();
163163
out.close();
164164
showStatus(tr("PSBT saved to disk."), StatusLevel::INFO);

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
509509
if (filename.isEmpty()) {
510510
return;
511511
}
512-
std::ofstream out(filename.toLocal8Bit().data(), std::ofstream::out | std::ofstream::binary);
512+
fsbridge::ofstream out{filename.toLocal8Bit().data(), fsbridge::ofstream::out | fsbridge::ofstream::binary};
513513
out << ssTx.str();
514514
out.close();
515515
Q_EMIT message(tr("PSBT saved"), "PSBT saved to disk", CClientUIInterface::MSG_INFORMATION);

src/qt/walletframe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void WalletFrame::gotoLoadPSBT(bool from_clipboard)
210210
Q_EMIT message(tr("Error"), tr("PSBT file must be smaller than 100 MiB"), CClientUIInterface::MSG_ERROR);
211211
return;
212212
}
213-
std::ifstream in(filename.toLocal8Bit().data(), std::ios::binary);
213+
fsbridge::ifstream in{filename.toLocal8Bit().data(), std::ios::binary};
214214
data = std::string(std::istreambuf_iterator<char>{in}, {});
215215
}
216216

src/test/fuzz/fuzz.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void initialize()
8080
}
8181
if (const char* out_path = std::getenv("WRITE_ALL_FUZZ_TARGETS_AND_ABORT")) {
8282
std::cout << "Writing all fuzz target names to '" << out_path << "'." << std::endl;
83-
std::ofstream out_stream(out_path, std::ios::binary);
83+
fsbridge::ofstream out_stream{out_path, std::ios::binary};
8484
for (const auto& t : FuzzTargets()) {
8585
if (std::get<2>(t.second)) continue;
8686
out_stream << t.first << std::endl;

src/test/script_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ BOOST_AUTO_TEST_CASE(script_build)
923923
}
924924

925925
#ifdef UPDATE_JSON_TESTS
926-
FILE* file = fopen("script_tests.json.gen", "w");
926+
FILE* file = fsbridge::fopen("script_tests.json.gen", "w");
927927
fputs(strGen.c_str(), file);
928928
fclose(file);
929929
#endif

src/util/system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes)
146146
}
147147

148148
std::streampos GetFileSize(const char* path, std::streamsize max) {
149-
std::ifstream file(path, std::ios::binary);
149+
fsbridge::ifstream file{path, std::ios::binary};
150150
file.ignore(max);
151151
return file.gcount();
152152
}

0 commit comments

Comments
 (0)