Hi Reuben, > gnulib can #define __USE_MINGW_ANSI_STDIO so that %z is implemented, but > warnings are still generated for xasprintf (not for printf). > > As far as I can tell, this is because the > _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM machinery to choose the correct > attribute (__gnu_printf__ or __printf__) for printf-like functions needs to > be used in xvasprintf.h and hence vasnprintf.h as well as in stdio.h. > > I guess this applies to all printf-like functions in gnulib that ultimately > use the system printf, that is, in verror.h, xprintf.h and argp.h (which > depend on xvasprintf or stdio).
Indeed, we did not really pay attention to the distinction between __gnu_printf__ (which denotes standards-compliant format strings) and __printf__ (which denotes the MSVCRT format strings). The interfaces in Gnulib fall in three categories: * Those that take standards-compliant format strings: c_snprintf -> c_vasnprintf -> vasnprintf c_vasnprintf -> vasnprintf c_asprintf -> c_vasprintf -> c_vasnprintf -> vasnprintf c_vasprintf -> c_vasnprintf -> vasnprintf c_vsnprintf -> c_vasnprintf -> vasnprintf c_xasprintf -> c_xvasprintf -> c_vasprintf -> c_vasnprintf -> vasnprintf c_xvasprintf -> c_vasprintf -> c_vasnprintf -> vasnprintf verror, verror_at_line -> xvasprintf -> vasprintf -> vasnprintf asnprintf -> vasnprintf vasnprintf xasprintf -> xvasprintf -> vasprintf -> vasnprintf xvasprintf -> vasprintf -> vasnprintf ostream_printf -> vasprintf -> vasnprintf * Those that use vfprintf and therefore take whatever the vfprintf function takes: argp_error, argp_failure -> vfprintf error, error_at_line -> vfprintf xfprintf -> xvfprintf -> vfprintf xvfprintf -> vfprintf * Those that use vprintf and therefore take whatever the vprintf function takes: xprintf -> xvprintf -> vprintf xvprintf -> vprintf This patch corrects the attributes. I'm not really happy that the API does not use standards-compliant format strings everywhere. But I'm not sure it's worth fixing. Note: You may get warnings when you use format strings that contain the PRI* macros from <inttypes.h>. This is because the mingw headers do ugly things with these macros, and there are no two PRIdMAX macros (one for __gnu_printf__ and one for __printf__) but only one. 2020-11-23 Bruno Haible <br...@clisp.org> Use the correct printf format attribute for mingw. Reported by Reuben Thomas <r...@sc3d.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-11/msg00133.html>. * modules/vfprintf-posix (configure.ac): Define GNULIB_VFPRINTF_POSIX. * modules/vprintf-posix (configure.ac): Define GNULIB_VPRINTF_POSIX. * lib/stdio.in.h (_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM): New macros. (_GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD): Renamed from _GL_ATTRIBUTE_FORMAT_PRINTF. Use _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. (_GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM): Use _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM. * modules/vasnprintf (Depends-on): Add stdio. * lib/vasnprintf.h: Include <stdio.h>. (asnprintf, vasnprintf): Use the standard printf format attribute. * modules/xvasprintf (Depends-on): Add stdio. * lib/xvasprintf.h: Include <stdio.h>. (xasprintf, xvasprintf): Use the standard printf format attribute. * modules/xprintf (Depends-on): List stdio first. * lib/xprintf.h (xprintf, xvprintf): Use a printf format attribute that depends on GNULIB_VPRINTF_POSIX. (xfprintf, xvfprintf): Use a printf format attribute that depends on GNULIB_VFPRINTF_POSIX. * modules/c-vasnprintf (Depends-on): Add stdio. * lib/c-vasnprintf.h: Include <stdio.h>. (c_vasnprintf): Use the standard printf format attribute. * modules/c-vasprintf (Depends-on): Add stdio. * lib/c-vasprintf.h: Include <stdio.h>. (c_asprintf, c_vasprintf): Use the standard printf format attribute. * modules/c-vsnprintf (Depends-on): Add stdio. * lib/c-vsnprintf.h: Include <stdio.h>. (c_vsnprintf): Use the standard printf format attribute. * modules/c-snprintf (Depends-on): Add stdio. * lib/c-snprintf.h: Include <stdio.h>. (c_snprintf): Use the standard printf format attribute. * modules/c-xvasprintf (Depends-on): Add stdio. * lib/c-xvasprintf.h: Include <stdio.h>. (c_xasprintf, c_xvasprintf): Use the standard printf format attribute. * modules/error (Depends-on): Depend on stdio always. * lib/error.h: Include <stdio.h>. (_GL_ATTRIBUTE_SPEC_PRINTF): Remove macro. (error, error_at_line): Use a printf format attribute that depends on GNULIB_VFPRINTF_POSIX. * lib/error.c (_GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD): Renamed from _GL_ATTRIBUTE_FORMAT_PRINTF. * modules/verror (Depends-on): Add stdio. * lib/verror.h: Include <stdio.h>. Don't include "error.h". (verror, verror_at_line): Use the standard printf format attribute. * lib/verror.c: Include "error.h". * modules/argp (Depends-on): Add stdio. * lib/argp.h (argp_error, __argp_error, argp_failure, __argp_failure): Use a printf format attribute that depends on GNULIB_VFPRINTF_POSIX. * modules/libtextstyle-optional (Depends-on): Add stdio. * lib/textstyle.in.h (ostream_printf, ostream_vprintf): Use the standard printf format attribute. * tests/test-nonblocking-misc.h (dbgfprintf): Use the standard printf format attribute. diff --git a/lib/argp.h b/lib/argp.h index c71dd96..77a6bd2 100644 --- a/lib/argp.h +++ b/lib/argp.h @@ -521,10 +521,20 @@ extern void __argp_usage (const struct argp_state *__state); message, then exit (1). */ extern void argp_error (const struct argp_state *__restrict __state, const char *__restrict __fmt, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 2, 3)) +#endif + ; extern void __argp_error (const struct argp_state *__restrict __state, const char *__restrict __fmt, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 2, 3)) +#endif + ; /* Similar to the standard gnu error-reporting function error(), but will respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print @@ -537,11 +547,21 @@ extern void __argp_error (const struct argp_state *__restrict __state, extern void argp_failure (const struct argp_state *__restrict __state, int __status, int __errnum, const char *__restrict __fmt, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 4, 5)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 4, 5)) +#endif + ; extern void __argp_failure (const struct argp_state *__restrict __state, int __status, int __errnum, const char *__restrict __fmt, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 4, 5)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 4, 5)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 4, 5)) +#endif + ; #if _LIBC /* Returns true if the option OPT is a valid short option. */ diff --git a/lib/c-snprintf.h b/lib/c-snprintf.h index e03ef88..43e5a05 100644 --- a/lib/c-snprintf.h +++ b/lib/c-snprintf.h @@ -20,13 +20,16 @@ /* Get size_t. */ #include <stddef.h> +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> + #ifdef __cplusplus extern "C" { #endif extern int c_snprintf (char *restrict str, size_t size, const char *format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4)); #ifdef __cplusplus } diff --git a/lib/c-vasnprintf.h b/lib/c-vasnprintf.h index b9853f6..9411ba8 100644 --- a/lib/c-vasnprintf.h +++ b/lib/c-vasnprintf.h @@ -23,6 +23,9 @@ /* Get size_t. */ #include <stddef.h> +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> + #ifdef __cplusplus extern "C" { #endif @@ -56,7 +59,7 @@ extern "C" { */ extern char *c_vasnprintf (char *restrict resultbuf, size_t *lengthp, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0)); #ifdef __cplusplus } diff --git a/lib/c-vasprintf.h b/lib/c-vasprintf.h index 588fbf0..c14b62e 100644 --- a/lib/c-vasprintf.h +++ b/lib/c-vasprintf.h @@ -20,6 +20,9 @@ /* Get va_list. */ #include <stdarg.h> +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> + #ifdef __cplusplus extern "C" { #endif @@ -28,9 +31,9 @@ extern "C" { is, the decimal point used in floating-point formatting directives is always '.'. */ int c_asprintf (char **resultp, const char *format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3)); int c_vasprintf (char **resultp, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0)); #ifdef __cplusplus } diff --git a/lib/c-vsnprintf.h b/lib/c-vsnprintf.h index 6e39102..f6be164 100644 --- a/lib/c-vsnprintf.h +++ b/lib/c-vsnprintf.h @@ -23,13 +23,16 @@ /* Get va_list. */ #include <stdarg.h> +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> + #ifdef __cplusplus extern "C" { #endif extern int c_vsnprintf (char *restrict str, size_t size, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0)); #ifdef __cplusplus } diff --git a/lib/c-xvasprintf.h b/lib/c-xvasprintf.h index 1d3a551..238bcf3 100644 --- a/lib/c-xvasprintf.h +++ b/lib/c-xvasprintf.h @@ -20,6 +20,9 @@ /* Get va_list. */ #include <stdarg.h> +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> + #ifdef __cplusplus extern "C" { #endif @@ -35,9 +38,9 @@ extern "C" { Formatting takes place in the C locale, that is, the decimal point used in floating-point formatting directives is always '.'. */ extern char *c_xasprintf (const char *format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 2)); extern char *c_xvasprintf (const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 0)); #ifdef __cplusplus } diff --git a/lib/error.c b/lib/error.c index 3657b51..2fc7901 100644 --- a/lib/error.c +++ b/lib/error.c @@ -40,7 +40,7 @@ # include <wchar.h> # define mbsrtowcs __mbsrtowcs # define USE_UNLOCKED_IO 0 -# define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b) +# define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(a, b) # define _GL_ARG_NONNULL(a) #else # include "getprogname.h" @@ -202,7 +202,7 @@ print_errno_message (int errnum) #endif } -static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3)) +static void _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3)) error_tail (int status, int errnum, const char *message, va_list args) { #if _LIBC diff --git a/lib/error.h b/lib/error.h index a351606..6f6c90e 100644 --- a/lib/error.h +++ b/lib/error.h @@ -19,15 +19,8 @@ #ifndef _ERROR_H #define _ERROR_H 1 -/* On mingw, the flavor of printf depends on whether the extensions module - * is in use; the check for <stdio.h> determines the witness macro. */ -#ifndef _GL_ATTRIBUTE_SPEC_PRINTF -# if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU -# define _GL_ATTRIBUTE_SPEC_PRINTF __gnu_printf__ -# else -# define _GL_ATTRIBUTE_SPEC_PRINTF __printf__ -# endif -#endif +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM. */ +#include <stdio.h> #ifdef __cplusplus extern "C" { @@ -38,11 +31,21 @@ extern "C" { If STATUS is nonzero, terminate the program with 'exit (STATUS)'. */ extern void error (int __status, int __errnum, const char *__format, ...) - _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF, 3, 4)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 3, 4)) +#endif + ; extern void error_at_line (int __status, int __errnum, const char *__fname, unsigned int __lineno, const char *__format, ...) - _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF, 5, 6)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 5, 6)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 5, 6)) +#endif + ; /* If NULL, error will flush stdout, then print on stderr the program name, a colon and a space. Otherwise, error will call this diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 0db5111..341246a 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -70,30 +70,44 @@ # endif #endif -/* _GL_ATTRIBUTE_FORMAT_PRINTF - indicates to GCC that the function takes a format string and arguments, - where the format string directives are the ones standardized by ISO C99 - and POSIX. */ +/* An __attribute__ __format__ specifier for a function that takes a format + string and arguments, where the format string directives are the ones + standardized by ISO C99 and POSIX. + _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD */ +/* __gnu_printf__ is supported in GCC >= 4.4. */ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT ((__gnu_printf__, formatstring_parameter, first_argument)) +# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __gnu_printf__ #else -# define _GL_ATTRIBUTE_FORMAT_PRINTF(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) +# define _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD __printf__ #endif -/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF, - except that it indicates to GCC that the supported format string directives - are the ones of the system printf(), rather than the ones standardized by - ISO C99 and POSIX. */ +/* An __attribute__ __format__ specifier for a function that takes a format + string and arguments, where the format string directives are the ones of the + system printf(), rather than the ones standardized by ISO C99 and POSIX. + _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM */ +/* On mingw, Gnulib sets __USE_MINGW_ANSI_STDIO in order to get closer to + the standards. The macro GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU indicates + whether this change is effective. On older mingw, it is not. */ #if GNULIB_PRINTF_ATTRIBUTE_FLAVOR_GNU -# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT_PRINTF (formatstring_parameter, first_argument) +# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD #else -# define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ - _GL_ATTRIBUTE_FORMAT ((__printf__, formatstring_parameter, first_argument)) +# define _GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM __printf__ #endif +/* _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD + indicates to GCC that the function takes a format string and arguments, + where the format string directives are the ones standardized by ISO C99 + and POSIX. */ +#define _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, formatstring_parameter, first_argument)) + +/* _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM is like _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD, + except that it indicates to GCC that the supported format string directives + are the ones of the system printf(), rather than the ones standardized by + ISO C99 and POSIX. */ +#define _GL_ATTRIBUTE_FORMAT_PRINTF_SYSTEM(formatstring_parameter, first_argument) \ + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, formatstring_parameter, first_argument)) + /* _GL_ATTRIBUTE_FORMAT_SCANF indicates to GCC that the function takes a format string and arguments, where the format string directives are the ones standardized by ISO C99 @@ -174,13 +188,13 @@ # define dprintf rpl_dprintf # endif _GL_FUNCDECL_RPL (dprintf, int, (int fd, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((2))); _GL_CXXALIAS_RPL (dprintf, int, (int fd, const char *restrict format, ...)); # else # if !@HAVE_DPRINTF@ _GL_FUNCDECL_SYS (dprintf, int, (int fd, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((2))); # endif _GL_CXXALIAS_SYS (dprintf, int, (int fd, const char *restrict format, ...)); @@ -351,7 +365,7 @@ _GL_WARN_ON_USE (fopen, "fopen on native Windows platforms is not POSIX complian # if @GNULIB_FPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ _GL_FUNCDECL_RPL (fprintf, int, (FILE *restrict fp, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); # else _GL_FUNCDECL_RPL (fprintf, int, @@ -861,7 +875,7 @@ struct obstack; # endif _GL_FUNCDECL_RPL (obstack_printf, int, (struct obstack *obs, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (obstack_printf, int, (struct obstack *obs, const char *format, ...)); @@ -869,7 +883,7 @@ _GL_CXXALIAS_RPL (obstack_printf, int, # if !@HAVE_DECL_OBSTACK_PRINTF@ _GL_FUNCDECL_SYS (obstack_printf, int, (struct obstack *obs, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (obstack_printf, int, @@ -882,7 +896,7 @@ _GL_CXXALIASWARN (obstack_printf); # endif _GL_FUNCDECL_RPL (obstack_vprintf, int, (struct obstack *obs, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (obstack_vprintf, int, (struct obstack *obs, const char *format, va_list args)); @@ -890,7 +904,7 @@ _GL_CXXALIAS_RPL (obstack_vprintf, int, # if !@HAVE_DECL_OBSTACK_PRINTF@ _GL_FUNCDECL_SYS (obstack_vprintf, int, (struct obstack *obs, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (obstack_vprintf, int, @@ -974,7 +988,7 @@ _GL_FUNCDECL_RPL_1 (__printf__, int, (const char *restrict format, ...) __asm__ (@ASM_SYMBOL_PREFIX@ _GL_STDIO_MACROEXPAND_AND_STRINGIZE(rpl_printf)) - _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2) _GL_ARG_NONNULL ((1))); # else _GL_FUNCDECL_RPL_1 (__printf__, int, @@ -991,7 +1005,7 @@ _GL_CXXALIAS_RPL_1 (printf, __printf__, int, (const char *format, ...)); # endif _GL_FUNCDECL_RPL (printf, int, (const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (1, 2) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2) _GL_ARG_NONNULL ((1))); _GL_CXXALIAS_RPL (printf, int, (const char *restrict format, ...)); # endif @@ -1182,7 +1196,7 @@ _GL_CXXALIASWARN (scanf); _GL_FUNCDECL_RPL (snprintf, int, (char *restrict str, size_t size, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4) _GL_ARG_NONNULL ((3))); _GL_CXXALIAS_RPL (snprintf, int, (char *restrict str, size_t size, @@ -1192,7 +1206,7 @@ _GL_CXXALIAS_RPL (snprintf, int, _GL_FUNCDECL_SYS (snprintf, int, (char *restrict str, size_t size, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 4) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 4) _GL_ARG_NONNULL ((3))); # endif _GL_CXXALIAS_SYS (snprintf, int, @@ -1226,7 +1240,7 @@ _GL_WARN_ON_USE (snprintf, "snprintf is unportable - " # endif _GL_FUNCDECL_RPL (sprintf, int, (char *restrict str, const char *restrict format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (sprintf, int, (char *restrict str, const char *restrict format, ...)); @@ -1282,7 +1296,7 @@ _GL_WARN_ON_USE (tmpfile, "tmpfile is not usable on mingw - " # endif _GL_FUNCDECL_RPL (asprintf, int, (char **result, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (asprintf, int, (char **result, const char *format, ...)); @@ -1290,7 +1304,7 @@ _GL_CXXALIAS_RPL (asprintf, int, # if !@HAVE_VASPRINTF@ _GL_FUNCDECL_SYS (asprintf, int, (char **result, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (asprintf, int, @@ -1303,7 +1317,7 @@ _GL_CXXALIASWARN (asprintf); # endif _GL_FUNCDECL_RPL (vasprintf, int, (char **result, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (vasprintf, int, (char **result, const char *format, va_list args)); @@ -1311,7 +1325,7 @@ _GL_CXXALIAS_RPL (vasprintf, int, # if !@HAVE_VASPRINTF@ _GL_FUNCDECL_SYS (vasprintf, int, (char **result, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); # endif _GL_CXXALIAS_SYS (vasprintf, int, @@ -1327,7 +1341,7 @@ _GL_CXXALIASWARN (vasprintf); # endif _GL_FUNCDECL_RPL (vdprintf, int, (int fd, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((2))); _GL_CXXALIAS_RPL (vdprintf, int, (int fd, const char *restrict format, va_list args)); @@ -1335,7 +1349,7 @@ _GL_CXXALIAS_RPL (vdprintf, int, # if !@HAVE_VDPRINTF@ _GL_FUNCDECL_SYS (vdprintf, int, (int fd, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((2))); # endif /* Need to cast, because on Solaris, the third parameter will likely be @@ -1365,7 +1379,7 @@ _GL_WARN_ON_USE (vdprintf, "vdprintf is unportable - " _GL_FUNCDECL_RPL (vfprintf, int, (FILE *restrict fp, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); # else _GL_FUNCDECL_RPL (vfprintf, int, @@ -1432,7 +1446,7 @@ _GL_CXXALIASWARN (vfscanf); # define GNULIB_overrides_vprintf 1 # if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VFPRINTF_POSIX@ _GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (1, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0) _GL_ARG_NONNULL ((1))); # else _GL_FUNCDECL_RPL (vprintf, int, (const char *restrict format, va_list args) @@ -1487,7 +1501,7 @@ _GL_CXXALIASWARN (vscanf); _GL_FUNCDECL_RPL (vsnprintf, int, (char *restrict str, size_t size, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3))); _GL_CXXALIAS_RPL (vsnprintf, int, (char *restrict str, size_t size, @@ -1497,7 +1511,7 @@ _GL_CXXALIAS_RPL (vsnprintf, int, _GL_FUNCDECL_SYS (vsnprintf, int, (char *restrict str, size_t size, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (3, 0) _GL_ARG_NONNULL ((3))); # endif _GL_CXXALIAS_SYS (vsnprintf, int, @@ -1523,7 +1537,7 @@ _GL_WARN_ON_USE (vsnprintf, "vsnprintf is unportable - " _GL_FUNCDECL_RPL (vsprintf, int, (char *restrict str, const char *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 0) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0) _GL_ARG_NONNULL ((1, 2))); _GL_CXXALIAS_RPL (vsprintf, int, (char *restrict str, diff --git a/lib/textstyle.in.h b/lib/textstyle.in.h index b888378..ffcd332 100644 --- a/lib/textstyle.in.h +++ b/lib/textstyle.in.h @@ -116,7 +116,7 @@ ostream_write_str (ostream_t stream, const char *string) static inline ptrdiff_t ostream_printf (ostream_t stream, const char *format, ...) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined __clang__ - __attribute__ ((__format__ (__printf__, 2, 3))) + __attribute__ ((__format__ (_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3))) #endif ; static inline ptrdiff_t @@ -141,7 +141,7 @@ ostream_printf (ostream_t stream, const char *format, ...) static inline ptrdiff_t ostream_vprintf (ostream_t stream, const char *format, va_list args) #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || defined __clang__ - __attribute__ ((__format__ (__printf__, 2, 0))) + __attribute__ ((__format__ (_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0))) #endif ; static inline ptrdiff_t diff --git a/lib/vasnprintf.h b/lib/vasnprintf.h index 5be0553..c6fee3c 100644 --- a/lib/vasnprintf.h +++ b/lib/vasnprintf.h @@ -23,6 +23,9 @@ /* Get size_t. */ #include <stddef.h> +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> + #ifdef __cplusplus extern "C" { #endif @@ -57,10 +60,10 @@ extern "C" { #endif extern char * asnprintf (char *restrict resultbuf, size_t *lengthp, const char *format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 4)); extern char * vasnprintf (char *restrict resultbuf, size_t *lengthp, const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0)); #ifdef __cplusplus } diff --git a/lib/verror.c b/lib/verror.c index 6bd365e..38d5880 100644 --- a/lib/verror.c +++ b/lib/verror.c @@ -18,13 +18,16 @@ #include <config.h> +/* Specification. */ #include "verror.h" -#include "xvasprintf.h" #include <errno.h> #include <stdarg.h> #include <stdlib.h> +#include "error.h" +#include "xvasprintf.h" + #if ENABLE_NLS # include "gettext.h" # define _(msgid) gettext (msgid) diff --git a/lib/verror.h b/lib/verror.h index 3343585..6c22866 100644 --- a/lib/verror.h +++ b/lib/verror.h @@ -19,7 +19,8 @@ #include <stdarg.h> -#include "error.h" /* for _GL_ATTRIBUTE_FORMAT */ +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> #ifdef __cplusplus extern "C" { @@ -33,7 +34,7 @@ extern "C" { extern void verror (int __status, int __errnum, const char *__format, va_list __args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 3, 0)); /* Print a message with 'vfprintf (stderr, FORMAT, ARGS)'; if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM). @@ -45,7 +46,7 @@ extern void verror (int __status, int __errnum, const char *__format, extern void verror_at_line (int __status, int __errnum, const char *__fname, unsigned int __lineno, const char *__format, va_list __args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 5, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 5, 0)); #ifdef __cplusplus } diff --git a/lib/xprintf.h b/lib/xprintf.h index d0615b4..8931638 100644 --- a/lib/xprintf.h +++ b/lib/xprintf.h @@ -21,13 +21,36 @@ #include <stdio.h> extern int xprintf (char const *restrict format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2)); +#if GNULIB_VPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 2)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 1, 2)) +#endif + ; + extern int xvprintf (char const *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0)); +#if GNULIB_VPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 0)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 1, 0)) +#endif + ; + extern int xfprintf (FILE *restrict stream, char const *restrict format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 3)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 3)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 2, 3)) +#endif + ; + extern int xvfprintf (FILE *restrict stream, char const *restrict format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 2, 0)); +#if GNULIB_VFPRINTF_POSIX + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 2, 0)) +#else + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_SYSTEM, 2, 0)) +#endif + ; #endif diff --git a/lib/xvasprintf.h b/lib/xvasprintf.h index ff43d1b..a43a901 100644 --- a/lib/xvasprintf.h +++ b/lib/xvasprintf.h @@ -20,6 +20,9 @@ /* Get va_list. */ #include <stdarg.h> +/* Get _GL_ATTRIBUTE_SPEC_PRINTF_STANDARD. */ +#include <stdio.h> + #ifdef __cplusplus extern "C" { #endif @@ -32,9 +35,9 @@ extern "C" { - [EILSEQ] error during conversion between wide and multibyte characters, return NULL. */ extern char *xasprintf (const char *format, ...) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 2)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 2)); extern char *xvasprintf (const char *format, va_list args) - _GL_ATTRIBUTE_FORMAT ((__printf__, 1, 0)); + _GL_ATTRIBUTE_FORMAT ((_GL_ATTRIBUTE_SPEC_PRINTF_STANDARD, 1, 0)); #ifdef __cplusplus } diff --git a/modules/argp b/modules/argp index 50fde11..38a7905 100644 --- a/modules/argp +++ b/modules/argp @@ -37,6 +37,7 @@ extensions vsnprintf sleep stdalign +stdio strerror memchr memmove diff --git a/modules/c-snprintf b/modules/c-snprintf index 2449b01..456691d 100644 --- a/modules/c-snprintf +++ b/modules/c-snprintf @@ -6,6 +6,7 @@ lib/c-snprintf.h lib/c-snprintf.c Depends-on: +stdio c-vasnprintf configure.ac: diff --git a/modules/c-vasnprintf b/modules/c-vasnprintf index 5fe1fa7..129f591 100644 --- a/modules/c-vasnprintf +++ b/modules/c-vasnprintf @@ -23,6 +23,7 @@ m4/exponentd.m4 Depends-on: attribute +stdio isnand-nolibm isnanl-nolibm frexpl-nolibm diff --git a/modules/c-vasprintf b/modules/c-vasprintf index 78e4119..868dc16 100644 --- a/modules/c-vasprintf +++ b/modules/c-vasprintf @@ -7,6 +7,7 @@ lib/c-asprintf.c lib/c-vasprintf.c Depends-on: +stdio c-vasnprintf configure.ac: diff --git a/modules/c-vsnprintf b/modules/c-vsnprintf index b227e92..eb62fd9 100644 --- a/modules/c-vsnprintf +++ b/modules/c-vsnprintf @@ -7,6 +7,7 @@ lib/c-vsnprintf.h lib/c-vsnprintf.c Depends-on: +stdio c-vasnprintf configure.ac: diff --git a/modules/c-xvasprintf b/modules/c-xvasprintf index 6650dda..b952128 100644 --- a/modules/c-xvasprintf +++ b/modules/c-xvasprintf @@ -7,6 +7,7 @@ lib/c-xasprintf.c lib/c-xvasprintf.c Depends-on: +stdio c-vasprintf xalloc-die diff --git a/modules/error b/modules/error index 15fb940..33116ec 100644 --- a/modules/error +++ b/modules/error @@ -12,8 +12,8 @@ lib/error.c m4/error.m4 Depends-on: +stdio getprogname -stdio [test $ac_cv_lib_error_at_line = no] strerror [test $ac_cv_lib_error_at_line = no] unistd [test $ac_cv_lib_error_at_line = no] msvc-nothrow [test $ac_cv_lib_error_at_line = no] diff --git a/modules/libtextstyle-optional b/modules/libtextstyle-optional index 1ee8270..c0935e1 100644 --- a/modules/libtextstyle-optional +++ b/modules/libtextstyle-optional @@ -8,6 +8,7 @@ m4/libtextstyle-optional.m4 Depends-on: libtextstyle stdbool +stdio unistd fsync vasprintf-posix diff --git a/modules/vasnprintf b/modules/vasnprintf index 893ce97..96cd300 100644 --- a/modules/vasnprintf +++ b/modules/vasnprintf @@ -21,6 +21,7 @@ m4/math_h.m4 m4/exponentd.m4 Depends-on: +stdio alloca-opt attribute float diff --git a/modules/verror b/modules/verror index 6b837e9..e183f68 100644 --- a/modules/verror +++ b/modules/verror @@ -11,6 +11,7 @@ lib/verror.h lib/verror.c Depends-on: +stdio error xvasprintf diff --git a/modules/vfprintf-posix b/modules/vfprintf-posix index 0433b29..c23fdef 100644 --- a/modules/vfprintf-posix +++ b/modules/vfprintf-posix @@ -33,6 +33,7 @@ errno [test $REPLACE_VFPRINTF = 1] configure.ac: gl_FUNC_VFPRINTF_POSIX gl_STDIO_MODULE_INDICATOR([vfprintf-posix]) +gl_MODULE_INDICATOR([vfprintf-posix]) Makefile.am: diff --git a/modules/vprintf-posix b/modules/vprintf-posix index 16e6cbe..afa2de2 100644 --- a/modules/vprintf-posix +++ b/modules/vprintf-posix @@ -20,6 +20,7 @@ vfprintf-posix [test $REPLACE_VPRINTF = 1] configure.ac: gl_FUNC_VPRINTF_POSIX gl_STDIO_MODULE_INDICATOR([vprintf-posix]) +gl_MODULE_INDICATOR([vprintf-posix]) Makefile.am: diff --git a/modules/xprintf b/modules/xprintf index 186e3b0..de61260 100644 --- a/modules/xprintf +++ b/modules/xprintf @@ -12,11 +12,11 @@ lib/xprintf.h lib/xprintf.c Depends-on: +stdio error exitfail gettext-h stdarg -stdio configure.ac: m4_ifdef([AM_XGETTEXT_OPTION], diff --git a/modules/xvasprintf b/modules/xvasprintf index 59d9a6e..373c1fa 100644 --- a/modules/xvasprintf +++ b/modules/xvasprintf @@ -13,6 +13,7 @@ lib/xalloc.h m4/xvasprintf.m4 Depends-on: +stdio vasprintf xalloc xalloc-die diff --git a/tests/test-nonblocking-misc.h b/tests/test-nonblocking-misc.h index 00af630..6101a7c 100644 --- a/tests/test-nonblocking-misc.h +++ b/tests/test-nonblocking-misc.h @@ -41,7 +41,7 @@ init_data (size_t data_block_size) #if ENABLE_DEBUGGING # include <stdarg.h> static int dbgfprintf (FILE *fp, const char *format, ...) - _GL_ATTRIBUTE_FORMAT_PRINTF (2, 3); + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3); static int dbgfprintf (FILE *fp, const char *format, ...) {