[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] build: avoid use of C11 specific %t format size spec
From: |
Pádraig Brady |
Subject: |
[PATCH] build: avoid use of C11 specific %t format size spec |
Date: |
Tue, 1 Aug 2023 14:07:11 +0100 |
* cfg.mk (sc_prohibit-c11-printf-format): Renamed and updated
from sc_prohibit-c99-printf-format.
* src/dd.c: Adjust %td -> %"PRIdMAX".
* src/dircolors.c: Likewise.
* src/du.c: Likewise.
* src/join.c: Likewise.
* src/od.c: Likewise.
* src/pathchk.c: Likewise.
---
cfg.mk | 8 ++++----
src/dd.c | 17 +++++++++--------
src/dircolors.c | 8 ++++----
src/du.c | 10 ++++++----
src/join.c | 3 ++-
src/od.c | 4 ++--
src/pathchk.c | 9 +++++----
7 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index 630251b65..1a0affd4b 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -299,15 +299,15 @@ sc_check-I18N-AUTHORS:
'$$(LIBICONV)' 1>&2; exit 1; }; \
done
-# Disallow the C99 printf size specifiers %z and %j as they're not portable.
+# Disallow the C11 printf size specifiers %z, %j and %t as they're not
portable.
# The gnulib printf replacement does support them, however the printf
# replacement is not currently explicitly depended on by the gnulib error()
# module for example. Also we use fprintf() in a few places to output simple
# formats but don't use the gnulib module as it is seen as overkill at present.
# We'd have to adjust the above gnulib items before disabling this.
-sc_prohibit-c99-printf-format:
- @cd $(srcdir)/src && GIT_PAGER= git grep -n '%[0*]*[jz][udx]' *.c \
- && { echo '$(ME): Use PRI*MAX instead of %j or %z' 1>&2; exit 1; } \
+sc_prohibit-c11-printf-format:
+ @cd $(srcdir)/src && GIT_PAGER= git grep -n '%[0*]*[tjz][udx]' *.c \
+ && { echo '$(ME): Use PRI*MAX instead of %j, %t or %z' 1>&2;exit 1; }\
|| :
# Ensure the alternative __attribute (keyword) form isn't used as
diff --git a/src/dd.c b/src/dd.c
index 21f7a4ede..ecf678780 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -675,8 +675,9 @@ alloc_ibuf (void)
{
char hbuf[LONGEST_HUMAN_READABLE + 1];
error (EXIT_FAILURE, 0,
- _("memory exhausted by input buffer of size %td bytes (%s)"),
- input_blocksize,
+ _("memory exhausted by input buffer of size %"PRIdMAX
+ " bytes (%s)"),
+ (intmax_t) input_blocksize,
human_readable (input_blocksize, hbuf,
human_opts | human_base_1024, 1, 1));
}
@@ -697,9 +698,9 @@ alloc_obuf (void)
{
char hbuf[LONGEST_HUMAN_READABLE + 1];
error (EXIT_FAILURE, 0,
- _("memory exhausted by output buffer of size %td"
+ _("memory exhausted by output buffer of size %"PRIdMAX
" bytes (%s)"),
- output_blocksize,
+ (intmax_t) output_blocksize,
human_readable (output_blocksize, hbuf,
human_opts | human_base_1024, 1, 1));
}
@@ -1136,9 +1137,9 @@ iread (int fd, char *buf, idx_t size)
{
idx_t prev = prev_nread;
if (status_level != STATUS_NONE)
- diagnose (0, ngettext (("warning: partial read (%td byte); "
+ diagnose (0, ngettext (("warning: partial read (%"PRIdMAX" byte); "
"suggest iflag=fullblock"),
- ("warning: partial read (%td bytes); "
+ ("warning: partial read (%"PRIdMAX" bytes);
"
"suggest iflag=fullblock"),
select_plural (prev)),
prev);
@@ -2484,8 +2485,8 @@ main (int argc, char **argv)
error (EXIT_FAILURE, 0,
_("offset too large: "
"cannot truncate to a length of seek=%"PRIdMAX""
- " (%td-byte) blocks"),
- seek_records, output_blocksize);
+ " (%"PRIdMAX"-byte) blocks"),
+ seek_records, (intmax_t) output_blocksize);
/* Open the output file with *read* access only if we might
need to read to satisfy a 'seek=' request. If we can't read
diff --git a/src/dircolors.c b/src/dircolors.c
index 8a86efb76..a47ff95e8 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -322,8 +322,8 @@ dc_parse_stream (FILE *fp, char const *filename)
if (arg == nullptr)
{
- error (0, 0, _("%s:%td: invalid line; missing second token"),
- quotef (filename), line_number);
+ error (0, 0, _("%s:%"PRIdMAX": invalid line; missing second token"),
+ quotef (filename), (intmax_t) line_number);
ok = false;
free (keywd);
continue;
@@ -377,9 +377,9 @@ dc_parse_stream (FILE *fp, char const *filename)
if (unrecognized && (state == ST_TERMSURE || state == ST_TERMYES))
{
- error (0, 0, _("%s:%td: unrecognized keyword %s"),
+ error (0, 0, _("%s:%"PRIdMAX": unrecognized keyword %s"),
(filename ? quotef (filename) : _("<internal>")),
- line_number, keywd);
+ (intmax_t) line_number, keywd);
ok = false;
}
diff --git a/src/du.c b/src/du.c
index 1e88b29ba..eb6f54e81 100644
--- a/src/du.c
+++ b/src/du.c
@@ -940,8 +940,9 @@ main (int argc, char **argv)
if (opt_summarize_only && max_depth_specified && max_depth != 0)
{
- error (0, 0, _("warning: summarizing conflicts with --max-depth=%td"),
- max_depth);
+ error (0, 0, _("warning: summarizing conflicts with "
+ "--max-depth=%"PRIdMAX),
+ (intmax_t) max_depth);
usage (EXIT_FAILURE);
}
@@ -1108,8 +1109,9 @@ main (int argc, char **argv)
not totally appropriate, since NUL is the separator, not NL,
but it might be better than nothing. */
idx_t file_number = argv_iter_n_args (ai);
- error (0, 0, "%s:%td: %s", quotef (files_from),
- file_number, _("invalid zero-length file name"));
+ error (0, 0, "%s:%"PRIdMAX": %s", quotef (files_from),
+ (intmax_t) file_number,
+ _("invalid zero-length file name"));
}
skip_file = true;
}
diff --git a/src/join.c b/src/join.c
index 0bcfa75d6..969e4ac7a 100644
--- a/src/join.c
+++ b/src/join.c
@@ -915,7 +915,8 @@ set_join_field (ptrdiff_t *var, idx_t val)
{
if (0 <= *var && *var != val)
error (EXIT_FAILURE, 0,
- _("incompatible join fields %td, %td"), *var, val);
+ _("incompatible join fields %"PRIdMAX", %"PRIdMAX),
+ (intmax_t) *var, (intmax_t) val);
*var = val;
}
diff --git a/src/od.c b/src/od.c
index df7fe9eb8..b5e8ce59f 100644
--- a/src/od.c
+++ b/src/od.c
@@ -1927,8 +1927,8 @@ main (int argc, char **argv)
bytes_per_block = desired_width;
else
{
- error (0, 0, _("warning: invalid width %td; using %d instead"),
- desired_width, l_c_m);
+ error (0, 0, _("warning: invalid width %"PRIdMAX"; using %d
instead"),
+ (intmax_t) desired_width, l_c_m);
bytes_per_block = l_c_m;
}
}
diff --git a/src/pathchk.c b/src/pathchk.c
index 3a29c3d28..8689d780e 100644
--- a/src/pathchk.c
+++ b/src/pathchk.c
@@ -320,8 +320,9 @@ validate_file_name (char *file, bool
check_basic_portability,
if (maxsize <= filelen)
{
- error (0, 0, _("limit %td exceeded by length %td of file name %s"),
- maxsize - 1, filelen, quoteaf (file));
+ error (0, 0, _("limit %"PRIdMAX" exceeded by "
+ "length %"PRIdMAX" of file name %s"),
+ (intmax_t) maxsize - 1, (intmax_t) filelen, quoteaf (file));
return false;
}
}
@@ -404,9 +405,9 @@ validate_file_name (char *file, bool
check_basic_portability,
char c = start[length];
start[length] = '\0';
error (0, 0,
- _("limit %td exceeded by length %td "
+ _("limit %"PRIdMAX" exceeded by length %"PRIdMAX" "
"of file name component %s"),
- name_max, length, quote (start));
+ (intmax_t) name_max, (intmax_t) length, quote (start));
start[length] = c;
return false;
}
--
2.41.0
- [PATCH] build: avoid use of C11 specific %t format size spec,
Pádraig Brady <=