Handle unsuccessful fseek(...)
:s.
Note to reviewers: What is the most appropriate course of actions for each of these unsuccessful fseek(...)
:s?
Handle unsuccessful fseek(...)
:s.
Note to reviewers: What is the most appropriate course of actions for each of these unsuccessful fseek(...)
:s?
886@@ -887,7 +887,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
887 // Fallback version
888 // TODO: just write one byte per block
889 static const char buf[65536] = {};
890- fseek(file, offset, SEEK_SET);
891+ if (fseek(file, offset, SEEK_SET)) {
892+ return;
253@@ -254,7 +254,10 @@ void BCLog::Logger::ShrinkDebugFile()
254 {
255 // Restart the file with some of the end
256 std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
257- fseek(file, -((long)vch.size()), SEEK_END);
258+ if (fseek(file, -((long)vch.size()), SEEK_END)) {
267@@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
268 CBlockHeader header;
269 try {
270 file >> header;
271- fseek(file.Get(), postx.nTxOffset, SEEK_CUR);
272+ if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
273+ return error("%s: fseek(...) failed", __func__);
ShrinkDebugFile()
would be even better).
@laanwj @jonasschnelli Regarding logging in ShrinkDebugFile(…)
– what about the following:
0diff --git a/src/logging.cpp b/src/logging.cpp
1index 2a55d36..b57b17e 100644
2--- a/src/logging.cpp
3+++ b/src/logging.cpp
4@@ -255,6 +255,7 @@ void BCLog::Logger::ShrinkDebugFile()
5 // Restart the file with some of the end
6 std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
7 if (fseek(file, -((long)vch.size()), SEEK_END)) {
8+ LogPrintf("Failed to shrink debug file: fseek(...) failed\n");
9 fclose(file);
10 return;
11 }
Looks good?