Skip to content

Commit 0b2774b

Browse files
committed
Refactor: Replace fprintf with tfm::format
> The locale dependent function fprintf(...) appears to be used...
1 parent c6e2bab commit 0b2774b

12 files changed

+19
-19
lines changed

depends/patches/libzip/nonrandomopentest.c.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
fd = open("/dev/urandom", O_RDONLY);
1111
+ #endif
1212
if (fd < 0) {
13-
fprintf(stderr, "can't open /dev/urandom: %s\n", strerror(errno));
13+
tfm::format(std::cerr, "can't open /dev/urandom: %s\n", strerror(errno));
1414
exit(1);

src/gridcoinresearchd.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool AppInit(int argc, char* argv[])
3939
SetupEnvironment();
4040
SetupServerArgs();
4141

42-
// Note every function above the InitLogging() call must use fprintf or similar.
42+
// Note every function above the InitLogging() call must use tfm::format or similar.
4343

4444
ThreadHandlerPtr threads = std::make_shared<ThreadHandler>();
4545
bool fRet = false;
@@ -73,7 +73,7 @@ bool AppInit(int argc, char* argv[])
7373

7474
if (gArgs.IsArgSet("-version"))
7575
{
76-
fprintf(stdout, "%s", VersionMessage().c_str());
76+
tfm::format(std::cout, "%s", VersionMessage().c_str());
7777

7878
return false;
7979
}

src/init.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ bool AppInit2(ThreadHandlerPtr threads)
938938
pid_t pid = fork();
939939
if (pid < 0)
940940
{
941-
fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
941+
tfm::format(std::cerr, "Error: fork() returned %d errno %d\n", pid, errno);
942942
return false;
943943
}
944944
if (pid > 0)
@@ -953,7 +953,7 @@ bool AppInit2(ThreadHandlerPtr threads)
953953

954954
pid_t sid = setsid();
955955
if (sid < 0)
956-
fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
956+
tfm::format(std::cerr, "Error: setsid() returned %d errno %d\n", sid, errno);
957957
}
958958
#endif
959959

@@ -980,7 +980,7 @@ bool AppInit2(ThreadHandlerPtr threads)
980980
}
981981

982982
if (fDaemon)
983-
fprintf(stdout, "Gridcoin server starting\n");
983+
tfm::format(std::cout, "Gridcoin server starting\n");
984984

985985
// ********************************************************* Step 5: verify database integrity
986986

src/noui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
static int noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style)
1313
{
1414
LogPrintf("%s: %s", caption, message);
15-
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
15+
tfm::format(std::cerr, "%s: %s\n", caption.c_str(), message.c_str());
1616
return 4;
1717
}
1818

@@ -26,7 +26,7 @@ static int noui_UpdateMessageBox(const std::string& version, const std::string&
2626
std::string caption = _("Gridcoin Update Available");
2727

2828
LogPrintf("%s:\r\n%s", caption, message);
29-
fprintf(stderr, "\r\n%s:\r\n%s\r\n%s\r\n", caption.c_str(), version.c_str(), message.c_str());
29+
tfm::format(std::cerr, "\r\n%s:\r\n%s\r\n%s\r\n", caption.c_str(), version.c_str(), message.c_str());
3030

3131
return 0;
3232
}

src/qt/bitcoin.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void ThreadSafeMessageBox(const std::string& message, const std::string&
118118
else
119119
{
120120
LogPrintf("%s: %s", caption, message);
121-
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
121+
tfm::format(std::cerr, "%s: %s\n", caption.c_str(), message.c_str());
122122
}
123123
}
124124

@@ -199,7 +199,7 @@ static void UpdateMessageBox(const std::string& version, const std::string& mess
199199
else
200200
{
201201
LogPrintf("\r\n%s:\r\n%s", caption, message);
202-
fprintf(stderr, "\r\n%s:\r\n%s\r\n", caption.c_str(), message.c_str());
202+
tfm::format(std::cerr, "\r\n%s:\r\n%s\r\n", caption.c_str(), message.c_str());
203203
}
204204
}
205205

@@ -251,7 +251,7 @@ int main(int argc, char *argv[])
251251
SetupServerArgs();
252252
SetupUIArgs(gArgs);
253253

254-
// Note every function above the InitLogging() call must use fprintf or similar.
254+
// Note every function above the InitLogging() call must use tfm::format or similar.
255255

256256
// Command-line options take precedence:
257257
// Before this would of been done in main then config file loaded.

src/qt/guiutil.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ void HelpMessageBox::printToConsole()
705705
{
706706
// On other operating systems, the expected action is to print the message to the console.
707707
QString strUsage = header + "\n" + options;
708-
fprintf(stdout, "%s", strUsage.toStdString().c_str());
708+
tfm::format(std::cout, "%s", strUsage.toStdString().c_str());
709709
}
710710

711711
void HelpMessageBox::showOrPrint()

src/qt/qtipcserver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static bool ipcScanCmd(int argc, char *argv[], bool fRelay)
5656
// the first start of the first instance
5757
if (ex.get_error_code() != boost::interprocess::not_found_error || !fRelay)
5858
{
59-
fprintf(stderr, "main() - boost interprocess exception #%d: %s", ex.get_error_code(), ex.what());
59+
tfm::format(std::cerr, "main() - boost interprocess exception #%d: %s", ex.get_error_code(), ex.what());
6060
break;
6161
}
6262
}

src/rpc/client.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ int CommandLineRPC(int argc, char *argv[])
351351

352352
if (strPrint != "")
353353
{
354-
fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
354+
tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint.c_str());
355355
}
356356
return nRet;
357357
}

src/sync.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine,
148148
for (const std::pair<void*, CLockLocation> & i : *lockstack)
149149
if (i.first == cs)
150150
return;
151-
fprintf(stderr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
151+
tfm::format(std::cerr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
152152
abort();
153153
}
154154

src/txdb-leveldb.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ bool CTxDB::LoadBlockIndex()
415415
_("Blocks Loaded"),
416416
(100 * nLoaded / nHighest)));
417417

418-
fprintf(stdout,"%d ",nLoaded); fflush(stdout);
418+
tfm::format(std::cout,"%d ",nLoaded); fflush(stdout);
419419
}
420420
}
421421

src/util.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void CreatePidFile(const fs::path &path, pid_t pid)
287287
FILE* file = fsbridge::fopen(path, "w");
288288
if (file)
289289
{
290-
fprintf(file, "%d\n", pid);
290+
tfm::format(file, "%d\n", pid);
291291
fclose(file);
292292
}
293293
}

src/util/system.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ void PrintException(std::exception* pex, const char* pszThread)
689689
{
690690
std::string message = FormatException(pex, pszThread);
691691
LogPrintf("\n\n************************\n%s", message);
692-
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
692+
tfm::format(std::cerr, "\n\n************************\n%s\n", message.c_str());
693693
strMiscWarning = message;
694694
throw;
695695
}
@@ -698,7 +698,7 @@ void PrintExceptionContinue(std::exception* pex, const char* pszThread)
698698
{
699699
std::string message = FormatException(pex, pszThread);
700700
LogPrintf("\n\n************************\n%s", message);
701-
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
701+
tfm::format(std::cerr, "\n\n************************\n%s\n", message.c_str());
702702
strMiscWarning = message;
703703
}
704704

0 commit comments

Comments
 (0)