From: Joel Rosdahl Date: Mon, 3 Aug 2020 14:58:47 +0000 (+0200) Subject: Use fmt::print instead of (f)printf X-Git-Tag: v4.0~229 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=db5d2501a4f66cceba1bd11a49b4990ddf823db0;p=thirdparty%2Fccache.git Use fmt::print instead of (f)printf --- diff --git a/src/Logging.cpp b/src/Logging.cpp index e51e5fc72..65072a8c0 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -69,10 +69,10 @@ bool debug_log_enabled = false; print_fatal_error_and_exit() { // Note: Can't call fatal() since that would lead to recursion. - fprintf(stderr, - "ccache: error: Failed to write to %s: %s\n", - logfile_path.c_str(), - strerror(errno)); + fmt::print(stderr, + "ccache: error: Failed to write to {}: {}\n", + logfile_path, + strerror(errno)); exit(EXIT_FAILURE); } diff --git a/src/ccache.cpp b/src/ccache.cpp index 13b00772a..e51e8da43 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -72,7 +72,7 @@ using nonstd::optional; using nonstd::string_view; static const char VERSION_TEXT[] = - R"(%s version %s + R"({} version {} Copyright (C) 2002-2007 Andrew Tridgell Copyright (C) 2009-2020 Joel Rosdahl and other contributors @@ -396,7 +396,7 @@ static void print_included_files(const Context& ctx, FILE* fp) { for (const auto& item : ctx.included_files) { - fprintf(fp, "%s\n", item.first.c_str()); + fmt::print(fp, "{}\n", item.first); } } @@ -1747,12 +1747,12 @@ create_initial_config_file(Config& config) return; } if (max_files != 0) { - fprintf(f, "max_files = %u\n", max_files); + fmt::print(f, "max_files = {}\n", max_files); config.set_max_files(max_files); } if (max_size != 0) { std::string size = Util::format_parsable_size_with_suffix(max_size); - fprintf(f, "max_size = %s\n", size.c_str()); + fmt::print(f, "max_size = {}\n", size); config.set_max_size(max_size); } fclose(f); @@ -2223,7 +2223,7 @@ handle_main_options(int argc, const char* const* argv) clean_old( ctx, [&](double progress) { progress_bar.update(progress); }, seconds); if (isatty(STDOUT_FILENO)) { - printf("\n"); + fmt::print("\n"); } break; } @@ -2259,7 +2259,7 @@ handle_main_options(int argc, const char* const* argv) clean_up_all(ctx.config, [&](double progress) { progress_bar.update(progress); }); if (isatty(STDOUT_FILENO)) { - printf("\n"); + fmt::print("\n"); } break; } @@ -2269,7 +2269,7 @@ handle_main_options(int argc, const char* const* argv) ProgressBar progress_bar("Clearing..."); wipe_all(ctx, [&](double progress) { progress_bar.update(progress); }); if (isatty(STDOUT_FILENO)) { - printf("\n"); + fmt::print("\n"); } break; } @@ -2287,7 +2287,7 @@ handle_main_options(int argc, const char* const* argv) Config::set_value_in_file( ctx.config.primary_config_path(), "max_files", arg); if (files == 0) { - printf("Unset cache file limit\n"); + fmt::print("Unset cache file limit\n"); } else { fmt::print("Set cache file limit to {}\n", files); } @@ -2299,7 +2299,7 @@ handle_main_options(int argc, const char* const* argv) Config::set_value_in_file( ctx.config.primary_config_path(), "max_size", arg); if (size == 0) { - printf("Unset cache size limit\n"); + fmt::print("Unset cache size limit\n"); } else { fmt::print("Set cache size limit to {}\n", Util::format_human_readable_size(size)); @@ -2329,7 +2329,7 @@ handle_main_options(int argc, const char* const* argv) break; case 'V': // --version - fprintf(stdout, VERSION_TEXT, MYNAME, CCACHE_VERSION); + fmt::print(VERSION_TEXT, MYNAME, CCACHE_VERSION); exit(EXIT_SUCCESS); case 'x': // --show-compression @@ -2363,7 +2363,7 @@ handle_main_options(int argc, const char* const* argv) case 'z': // --zero-stats stats_zero(ctx); - printf("Statistics zeroed\n"); + fmt::print("Statistics zeroed\n"); break; default: diff --git a/src/compopt.cpp b/src/compopt.cpp index 1a0aabd0b..4b84d8bf1 100644 --- a/src/compopt.cpp +++ b/src/compopt.cpp @@ -18,6 +18,8 @@ #include "compopt.hpp" +#include "third_party/fmt/core.h" + // The option it too hard to handle at all. #define TOO_HARD (1 << 0) @@ -191,9 +193,9 @@ compopt_verify_sortedness_and_flags() { for (size_t i = 0; i < ARRAY_SIZE(compopts); i++) { if (compopts[i].type & TOO_HARD && compopts[i].type & TAKES_CONCAT_ARG) { - fprintf(stderr, - "type (TOO_HARD | TAKES_CONCAT_ARG) not allowed, used by %s\n", - compopts[i].name); + fmt::print(stderr, + "type (TOO_HARD | TAKES_CONCAT_ARG) not allowed, used by {}\n", + compopts[i].name); return false; } @@ -202,10 +204,10 @@ compopt_verify_sortedness_and_flags() } if (strcmp(compopts[i - 1].name, compopts[i].name) >= 0) { - fprintf(stderr, - "compopt_verify_sortedness: %s >= %s\n", - compopts[i - 1].name, - compopts[i].name); + fmt::print(stderr, + "compopt_verify_sortedness: {} >= {}\n", + compopts[i - 1].name, + compopts[i].name); return false; } } diff --git a/src/compress.cpp b/src/compress.cpp index a1e421910..d4be1c13c 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -180,7 +180,7 @@ compress_stats(const Config& config, progress_receiver); if (isatty(STDOUT_FILENO)) { - printf("\n\n"); + fmt::print("\n\n"); } double ratio = compr_size > 0 ? ((double)compr_orig_size) / compr_size : 0.0; @@ -253,6 +253,6 @@ compress_recompress(Context& ctx, progress_receiver); if (isatty(STDOUT_FILENO)) { - printf("\n"); + fmt::print("\n"); } }