Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Replace fprintf with tfm::format #2262

Merged
merged 1 commit into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/gridcoinresearchd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool AppInit(int argc, char* argv[])
SetupEnvironment();
SetupServerArgs();

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

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

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

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ bool AppInit2(ThreadHandlerPtr threads)
pid_t pid = fork();
if (pid < 0)
{
fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
tfm::format(std::cerr, "Error: fork() returned %d errno %d\n", pid, errno);
return false;
}
if (pid > 0)
Expand All @@ -953,7 +953,7 @@ bool AppInit2(ThreadHandlerPtr threads)

pid_t sid = setsid();
if (sid < 0)
fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
tfm::format(std::cerr, "Error: setsid() returned %d errno %d\n", sid, errno);
}
#endif

Expand All @@ -980,7 +980,7 @@ bool AppInit2(ThreadHandlerPtr threads)
}

if (fDaemon)
fprintf(stdout, "Gridcoin server starting\n");
tfm::format(std::cout, "Gridcoin server starting\n");

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

Expand Down
4 changes: 2 additions & 2 deletions src/noui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
static int noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, int style)
{
LogPrintf("%s: %s", caption, message);
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
tfm::format(std::cerr, "%s: %s\n", caption.c_str(), message.c_str());
return 4;
}

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

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

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void ThreadSafeMessageBox(const std::string& message, const std::string&
else
{
LogPrintf("%s: %s", caption, message);
fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());
tfm::format(std::cerr, "%s: %s\n", caption.c_str(), message.c_str());
}
}

Expand Down Expand Up @@ -199,7 +199,7 @@ static void UpdateMessageBox(const std::string& version, const std::string& mess
else
{
LogPrintf("\r\n%s:\r\n%s", caption, message);
fprintf(stderr, "\r\n%s:\r\n%s\r\n", caption.c_str(), message.c_str());
tfm::format(std::cerr, "\r\n%s:\r\n%s\r\n", caption.c_str(), message.c_str());
}
}

Expand Down Expand Up @@ -251,7 +251,7 @@ int main(int argc, char *argv[])
SetupServerArgs();
SetupUIArgs(gArgs);

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

// Command-line options take precedence:
// Before this would of been done in main then config file loaded.
Expand Down
2 changes: 1 addition & 1 deletion src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ void HelpMessageBox::printToConsole()
{
// On other operating systems, the expected action is to print the message to the console.
QString strUsage = header + "\n" + options;
fprintf(stdout, "%s", strUsage.toStdString().c_str());
tfm::format(std::cout, "%s", strUsage.toStdString().c_str());
}

void HelpMessageBox::showOrPrint()
Expand Down
2 changes: 1 addition & 1 deletion src/qt/qtipcserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static bool ipcScanCmd(int argc, char *argv[], bool fRelay)
// the first start of the first instance
if (ex.get_error_code() != boost::interprocess::not_found_error || !fRelay)
{
fprintf(stderr, "main() - boost interprocess exception #%d: %s", ex.get_error_code(), ex.what());
tfm::format(std::cerr, "main() - boost interprocess exception #%d: %s", ex.get_error_code(), ex.what());
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int CommandLineRPC(int argc, char *argv[])

if (strPrint != "")
{
fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint.c_str());
}
return nRet;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine,
for (const std::pair<void*, CLockLocation> & i : *lockstack)
if (i.first == cs)
return;
fprintf(stderr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
tfm::format(std::cerr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
abort();
}

Expand Down
2 changes: 1 addition & 1 deletion src/txdb-leveldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ bool CTxDB::LoadBlockIndex()
_("Blocks Loaded"),
(100 * nLoaded / nHighest)));

fprintf(stdout,"%d ",nLoaded); fflush(stdout);
tfm::format(std::cout,"%d ",nLoaded); fflush(stdout);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ bool WildcardMatch(const string& str, const string& mask)
#ifndef WIN32
void CreatePidFile(const fs::path &path, pid_t pid)
{
FILE* file = fsbridge::fopen(path, "w");
fsbridge::ofstream file{path};
if (file)
{
fprintf(file, "%d\n", pid);
fclose(file);
tfm::format(file, "%d\n", pid);
}
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/util/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ void PrintException(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
LogPrintf("\n\n************************\n%s", message);
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
tfm::format(std::cerr, "\n\n************************\n%s\n", message.c_str());
strMiscWarning = message;
throw;
}
Expand All @@ -698,7 +698,7 @@ void PrintExceptionContinue(std::exception* pex, const char* pszThread)
{
std::string message = FormatException(pex, pszThread);
LogPrintf("\n\n************************\n%s", message);
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
tfm::format(std::cerr, "\n\n************************\n%s\n", message.c_str());
strMiscWarning = message;
}

Expand Down