1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-20 00:42:27 +03:00

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
<inttypes.h> 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 <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/b936d2fb-590d-49c3-a615-92c3a88c6c19%40eisentraut.org
This commit is contained in:
Peter Eisentraut 2025-03-02 13:53:03 +01:00
parent 00d61a08c5
commit 15a79c7311

View File

@ -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);
}
}