aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <[email protected]>2019-06-13 09:43:24 -0400
committerMarcoFalke <[email protected]>2019-06-18 15:50:40 -0400
commit79745d1752d0d1a95f073a04d6f4b9715745cf17 (patch)
tree21de08b84a5a1d87ea1322a2f9e9cbec1a75e138
parentscripted-diff: Replace fprintf with tfm::format (diff)
downloaddiscoin-79745d1752d0d1a95f073a04d6f4b9715745cf17.tar.xz
discoin-79745d1752d0d1a95f073a04d6f4b9715745cf17.zip
Replace remaining fprintf with tfm::format manually
Github-Pull: #16205 Rebased-From: fa8f195195945ce6258199af0461e3fbfbc1236d
-rw-r--r--src/bitcoin-cli.cpp2
-rw-r--r--src/bitcoin-tx.cpp2
-rw-r--r--src/init.cpp7
-rwxr-xr-xtest/lint/lint-format-strings.sh1
-rwxr-xr-xtest/lint/lint-locale-dependence.sh6
5 files changed, 8 insertions, 10 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 774a255b6..76cc19cc8 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -499,7 +499,7 @@ static 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;
}
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index 6a7a22fb1..dcf6dddf2 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -827,7 +827,7 @@ static int CommandLineRawTx(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;
}
diff --git a/src/init.cpp b/src/init.cpp
index 1ed44821e..557102efc 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -106,14 +106,13 @@ static fs::path GetPidFile()
NODISCARD static bool CreatePidFile()
{
- FILE* file = fsbridge::fopen(GetPidFile(), "w");
+ fsbridge::ofstream file{GetPidFile()};
if (file) {
#ifdef WIN32
- fprintf(file, "%d\n", GetCurrentProcessId());
+ tfm::format(file, "%d\n", GetCurrentProcessId());
#else
- fprintf(file, "%d\n", getpid());
+ tfm::format(file, "%d\n", getpid());
#endif
- fclose(file);
return true;
} else {
return InitError(strprintf(_("Unable to create the PID file '%s': %s"), GetPidFile().string(), std::strerror(errno)));
diff --git a/test/lint/lint-format-strings.sh b/test/lint/lint-format-strings.sh
index c994ae3f4..cb630c78a 100755
--- a/test/lint/lint-format-strings.sh
+++ b/test/lint/lint-format-strings.sh
@@ -13,6 +13,7 @@ export LC_ALL=C
FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS=(
"FatalError,0"
"fprintf,1"
+ "tfm::format,1" # Assuming tfm::::format(std::ostream&, ...
"LogConnectFailure,1"
"LogPrint,1"
"LogPrintf,0"
diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh
index 2b6c78c2c..9a1aa766f 100755
--- a/test/lint/lint-locale-dependence.sh
+++ b/test/lint/lint-locale-dependence.sh
@@ -8,7 +8,6 @@ KNOWN_VIOLATIONS=(
"src/dbwrapper.cpp:.*vsnprintf"
"src/httprpc.cpp.*trim"
"src/init.cpp:.*atoi"
- "src/init.cpp:.*fprintf"
"src/qt/rpcconsole.cpp:.*atoi"
"src/rest.cpp:.*strtol"
"src/test/dbwrapper_tests.cpp:.*snprintf"
@@ -85,7 +84,7 @@ LOCALE_DEPENDENT_FUNCTIONS=(
mbtowc # LC_CTYPE
mktime
normalize # boost::locale::normalize
-# printf # LC_NUMERIC
+ printf # LC_NUMERIC
putwc
putwchar
scanf # LC_NUMERIC
@@ -189,8 +188,7 @@ GIT_GREP_OUTPUT=$(git grep -E "[^a-zA-Z0-9_\`'\"<>](${REGEXP_LOCALE_DEPENDENT_FU
EXIT_CODE=0
for LOCALE_DEPENDENT_FUNCTION in "${LOCALE_DEPENDENT_FUNCTIONS[@]}"; do
MATCHES=$(grep -E "[^a-zA-Z0-9_\`'\"<>]${LOCALE_DEPENDENT_FUNCTION}(_r|_s)?[^a-zA-Z0-9_\`'\"<>]" <<< "${GIT_GREP_OUTPUT}" | \
- grep -vE "\.(c|cpp|h):\s*(//|\*|/\*|\").*${LOCALE_DEPENDENT_FUNCTION}" | \
- grep -vE 'fprintf\(.*(stdout|stderr)')
+ grep -vE "\.(c|cpp|h):\s*(//|\*|/\*|\").*${LOCALE_DEPENDENT_FUNCTION}")
if [[ ${REGEXP_IGNORE_EXTERNAL_DEPENDENCIES} != "" ]]; then
MATCHES=$(grep -vE "${REGEXP_IGNORE_EXTERNAL_DEPENDENCIES}" <<< "${MATCHES}")
fi