From 15a79c73111f0c9738ee81b796f7de5bfeb3aedc Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sun, 2 Mar 2025 13:53:03 +0100 Subject: [PATCH] Use PRI*64 instead of "ll*" in format strings (minimal trial) Old: errmsg("hello %llu", (unsigned long long) x) New: errmsg("hello %" PRIu64, x) And likewise for everything printf-like. In the past we had to use long long so localized format strings remained architecture independent in message catalogs. Although long long is expected to be 64 bit everywhere, if we hadn't also cast the int64 values, we'd have generated compiler warnings on systems where int64 was long. Now that int64 is int64_t, C99 understand how to format them using macros, the casts are not necessary, and the gettext() tools recognize the macros and defer expansion until load time. (And if we ever manage to get -Wformat-signedness to work for us, that'd help with these too, but not the type-system-clobbering casts.) This particular patch converts only pg_checksums.c to the new system, to allow testing of the translation toolchain for everyone. If this works okay, a later patch will convert most of the rest. Author: Thomas Munro Discussion: https://postgr.es/m/b936d2fb-590d-49c3-a615-92c3a88c6c19%40eisentraut.org --- src/bin/pg_checksums/pg_checksums.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c index e1acb6e933d..867aeddc601 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c @@ -141,9 +141,9 @@ progress_report(bool finished) /* Calculate current percentage of size done */ percent = total_size ? (int) ((current_size) * 100 / total_size) : 0; - fprintf(stderr, _("%lld/%lld MB (%d%%) computed"), - (long long) (current_size / (1024 * 1024)), - (long long) (total_size / (1024 * 1024)), + fprintf(stderr, _("%" PRId64 "/%" PRId64 " MB (%d%%) computed"), + (current_size / (1024 * 1024)), + (total_size / (1024 * 1024)), percent); /* @@ -603,11 +603,11 @@ main(int argc, char *argv[]) progress_report(true); printf(_("Checksum operation completed\n")); - printf(_("Files scanned: %lld\n"), (long long) files_scanned); - printf(_("Blocks scanned: %lld\n"), (long long) blocks_scanned); + printf(_("Files scanned: %" PRId64 "\n"), files_scanned); + printf(_("Blocks scanned: %" PRId64 "\n"), blocks_scanned); if (mode == PG_MODE_CHECK) { - printf(_("Bad checksums: %lld\n"), (long long) badblocks); + printf(_("Bad checksums: %" PRId64 "\n"), badblocks); printf(_("Data checksum version: %u\n"), ControlFile->data_checksum_version); if (badblocks > 0) @@ -615,8 +615,8 @@ main(int argc, char *argv[]) } else if (mode == PG_MODE_ENABLE) { - printf(_("Files written: %lld\n"), (long long) files_written); - printf(_("Blocks written: %lld\n"), (long long) blocks_written); + printf(_("Files written: %" PRId64 "\n"), files_written); + printf(_("Blocks written: %" PRId64 "\n"), blocks_written); } }