aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2011-08-16 11:24:08 +0300
committerPeter Eisentraut <peter_e@gmx.net>2011-08-16 11:24:08 +0300
commit3b3f09351b48f3081021ce60964c92cec42b7c3d (patch)
tree90e7cd8668d7d50ecba0cb4468c2f5426cba0374
parent005e5c30d162447da81d5d5e118a5ea4613dc944 (diff)
downloadpostgresql-3b3f09351b48f3081021ce60964c92cec42b7c3d.tar.gz
postgresql-3b3f09351b48f3081021ce60964c92cec42b7c3d.zip
Make pg_basebackup progress report translatable
Also fix a potential portability bug, because INT64_FORMAT is only guaranteed to be available with snprintf, not fprintf.
-rw-r--r--src/bin/pg_basebackup/pg_basebackup.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 029c1d76cec..d5934f2e2b5 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -204,10 +204,20 @@ static void
progress_report(int tablespacenum, const char *filename)
{
int percent = (int) ((totaldone / 1024) * 100 / totalsize);
+ char totaldone_str[32];
+ char totalsize_str[32];
if (percent > 100)
percent = 100;
+ /*
+ * Separate step to keep platform-dependent format code out of translatable
+ * strings. And we only test for INT64_FORMAT availability in snprintf,
+ * not fprintf.
+ */
+ snprintf(totaldone_str, sizeof(totaldone_str), INT64_FORMAT, totaldone / 1024);
+ snprintf(totalsize_str, sizeof(totalsize_str), INT64_FORMAT, totalsize);
+
if (verbose)
{
if (!filename)
@@ -217,21 +227,23 @@ progress_report(int tablespacenum, const char *filename)
* call)
*/
fprintf(stderr,
- INT64_FORMAT "/" INT64_FORMAT " kB (100%%) %d/%d tablespaces %35s\r",
- totaldone / 1024, totalsize,
- tablespacenum, tablespacecount, "");
+ ngettext("%s/%s kB (100%%), %d/%d tablespace %35s\r",
+ "%s/%s kB (100%%), %d/%d tablespaces %35s\r",
+ tablespacecount),
+ totaldone_str, totalsize_str, tablespacenum, tablespacecount, "");
else
fprintf(stderr,
- INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces (%-30.30s)\r",
- totaldone / 1024, totalsize,
- percent,
- tablespacenum, tablespacecount, filename);
+ ngettext("%s/%s kB (%d%%), %d/%d tablespace (%-30.30s)\r",
+ "%s/%s kB (%d%%), %d/%d tablespaces (%-30.30s)\r",
+ tablespacecount),
+ totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount, filename);
}
else
- fprintf(stderr, INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces\r",
- totaldone / 1024, totalsize,
- percent,
- tablespacenum, tablespacecount);
+ fprintf(stderr,
+ ngettext("%s/%s kB (%d%%), %d/%d tablespace\r",
+ "%s/%s kB (%d%%), %d/%d tablespaces\r",
+ tablespacecount),
+ totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount);
}