Re: [PATCH] build: avoid use of C11 specific %t format size spec
On 02/08/2023 00:11, Paul Eggert wrote: On 2023-08-01 06:28, Pádraig Brady wrote: perhaps we can now use %j, %t, and %z now? I hope so, particularly as we haven't seen any issues with Coreutils 9.1 or later. I haven't run into problems using these printf formats for a while. Gnulib doc is ambiguous, but suggests it could be an issue on AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9, Cygwin 1.5.24, mingw, MSVC 14. Of these, the only platforms that are not obsolete are mingw and MSVC 14, and Stack Overflow[1] suggests that this is only with older MS-Windows versions and can be worked around easily on those older versions by whoever's doing the port. Diffutils doesn't work on MS-Windows now anyway, as per Bug#64811, so I'll cc to that bug report to give Gisle Vanem a heads-up about this other issue. [1]: https://stackoverflow.com/questions/44382862/how-to-printf-a-size-t-without-warning-in-mingw-w64-gcc-7-1 Thanks for the info. I'll apply the following to allow use of all C99 size specs so. cheers, PádraigFrom 322530bd433996f8a4f2086c0229facf41c6c709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Sat, 12 Aug 2023 11:21:50 +0100 Subject: [PATCH] maint: allow use of printf C99 integer size specifiers Older systems that had issues with these like HPUX and Solaris 8 are no longer supported, or can apply patches to provide support. Also we've used %td since coreutils 9.1, with no reported issues. * cfg.mk (sc_prohibit-c99-printf-format): Remove to allow use of %[jtz] size specifiers, which allows for cleaner code by avoiding the need to cast to PRI?MAX etc. --- cfg.mk | 11 --- 1 file changed, 11 deletions(-) diff --git a/cfg.mk b/cfg.mk index 630251b65..6db0daf71 100644 --- a/cfg.mk +++ b/cfg.mk @@ -299,17 +299,6 @@ sc_check-I18N-AUTHORS: '$$(LIBICONV)' 1>&2; exit 1; }; \ done -# Disallow the C99 printf size specifiers %z and %j 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; } \ - || : - # Ensure the alternative __attribute (keyword) form isn't used as # that form is not elided where required. Also ensure that we don't # directly use attributes already defined by gnulib. -- 2.41.0
Re: [PATCH] build: avoid use of C11 specific %t format size spec
On 2023-08-01 06:28, Pádraig Brady wrote: perhaps we can now use %j, %t, and %z now? I hope so, particularly as we haven't seen any issues with Coreutils 9.1 or later. I haven't run into problems using these printf formats for a while. Gnulib doc is ambiguous, but suggests it could be an issue on AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9, Cygwin 1.5.24, mingw, MSVC 14. Of these, the only platforms that are not obsolete are mingw and MSVC 14, and Stack Overflow[1] suggests that this is only with older MS-Windows versions and can be worked around easily on those older versions by whoever's doing the port. Diffutils doesn't work on MS-Windows now anyway, as per Bug#64811, so I'll cc to that bug report to give Gisle Vanem a heads-up about this other issue. [1]: https://stackoverflow.com/questions/44382862/how-to-printf-a-size-t-without-warning-in-mingw-w64-gcc-7-1
Re: [PATCH] build: avoid use of C11 specific %t format size spec
%t is C99 -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: [PATCH] build: avoid use of C11 specific %t format size spec
On 01/08/2023 14:07, Pádraig Brady wrote: * 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. Actually I see that we've used %td since coreutils 9.1 I'm surprised we've not hit build issues with that, but perhaps we can now use %j, %t, and %z now? cheers, Pádraig
[PATCH] build: avoid use of C11 specific %t format size spec
* 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 ?