Skip to content

Commit fa8f195

Browse files
author
MarcoFalke
committed
Replace remaining fprintf with tfm::format manually
1 parent fac03ec commit fa8f195

File tree

6 files changed

+9
-11
lines changed

6 files changed

+9
-11
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ static int CommandLineRPC(int argc, char *argv[])
495495
}
496496

497497
if (strPrint != "") {
498-
fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
498+
tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint.c_str());
499499
}
500500
return nRet;
501501
}

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ static int CommandLineRawTx(int argc, char* argv[])
828828
}
829829

830830
if (strPrint != "") {
831-
fprintf((nRet == 0 ? stdout : stderr), "%s\n", strPrint.c_str());
831+
tfm::format(nRet == 0 ? std::cout : std::cerr, "%s\n", strPrint.c_str());
832832
}
833833
return nRet;
834834
}

src/init.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,13 @@ static fs::path GetPidFile()
108108

109109
NODISCARD static bool CreatePidFile()
110110
{
111-
FILE* file = fsbridge::fopen(GetPidFile(), "w");
111+
fsbridge::ofstream file{GetPidFile()};
112112
if (file) {
113113
#ifdef WIN32
114-
fprintf(file, "%d\n", GetCurrentProcessId());
114+
tfm::format(file, "%d\n", GetCurrentProcessId());
115115
#else
116-
fprintf(file, "%d\n", getpid());
116+
tfm::format(file, "%d\n", getpid());
117117
#endif
118-
fclose(file);
119118
return true;
120119
} else {
121120
return InitError(strprintf(_("Unable to create the PID file '%s': %s"), GetPidFile().string(), std::strerror(errno)));

src/sync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct CLockLocation {
5757

5858
std::string ToString() const
5959
{
60-
return tfm::format(
60+
return strprintf(
6161
"%s %s:%s%s (in thread %s)",
6262
mutexName, sourceFile, itostr(sourceLine), (fTry ? " (TRY)" : ""), m_thread_name);
6363
}

test/lint/lint-format-strings.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export LC_ALL=C
1313
FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS=(
1414
"FatalError,0"
1515
"fprintf,1"
16+
"tfm::format,1" # Assuming tfm::::format(std::ostream&, ...
1617
"LogConnectFailure,1"
1718
"LogPrint,1"
1819
"LogPrintf,0"

test/lint/lint-locale-dependence.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ KNOWN_VIOLATIONS=(
88
"src/dbwrapper.cpp:.*vsnprintf"
99
"src/httprpc.cpp.*trim"
1010
"src/init.cpp:.*atoi"
11-
"src/init.cpp:.*fprintf"
1211
"src/qt/rpcconsole.cpp:.*atoi"
1312
"src/rest.cpp:.*strtol"
1413
"src/test/dbwrapper_tests.cpp:.*snprintf"
@@ -85,7 +84,7 @@ LOCALE_DEPENDENT_FUNCTIONS=(
8584
mbtowc # LC_CTYPE
8685
mktime
8786
normalize # boost::locale::normalize
88-
# printf # LC_NUMERIC
87+
printf # LC_NUMERIC
8988
putwc
9089
putwchar
9190
scanf # LC_NUMERIC
@@ -189,8 +188,7 @@ GIT_GREP_OUTPUT=$(git grep -E "[^a-zA-Z0-9_\`'\"<>](${REGEXP_LOCALE_DEPENDENT_FU
189188
EXIT_CODE=0
190189
for LOCALE_DEPENDENT_FUNCTION in "${LOCALE_DEPENDENT_FUNCTIONS[@]}"; do
191190
MATCHES=$(grep -E "[^a-zA-Z0-9_\`'\"<>]${LOCALE_DEPENDENT_FUNCTION}(_r|_s)?[^a-zA-Z0-9_\`'\"<>]" <<< "${GIT_GREP_OUTPUT}" | \
192-
grep -vE "\.(c|cpp|h):\s*(//|\*|/\*|\").*${LOCALE_DEPENDENT_FUNCTION}" | \
193-
grep -vE 'fprintf\(.*(stdout|stderr)')
191+
grep -vE "\.(c|cpp|h):\s*(//|\*|/\*|\").*${LOCALE_DEPENDENT_FUNCTION}")
194192
if [[ ${REGEXP_IGNORE_EXTERNAL_DEPENDENCIES} != "" ]]; then
195193
MATCHES=$(grep -vE "${REGEXP_IGNORE_EXTERNAL_DEPENDENCIES}" <<< "${MATCHES}")
196194
fi

0 commit comments

Comments
 (0)