From 2bb894abc6dd417e094aa63774a2bc8b04acb965 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 6 May 2007 15:29:04 +0000 Subject: [PATCH] Work around lack of support of grouping flag. --- ChangeLog | 30 +++++++++++++ doc/functions/fprintf.texi | 6 +-- doc/functions/printf.texi | 6 +-- doc/functions/snprintf.texi | 6 +-- doc/functions/sprintf.texi | 6 +-- doc/functions/vfprintf.texi | 6 +-- doc/functions/vprintf.texi | 6 +-- doc/functions/vsnprintf.texi | 6 +-- doc/functions/vsprintf.texi | 6 +-- lib/vasnprintf.c | 6 +++ m4/fprintf-posix.m4 | 12 +++-- m4/printf.m4 | 102 ++++++++++++++++++++++++++++-------------- m4/snprintf-posix.m4 | 22 +++++---- m4/sprintf-posix.m4 | 12 +++-- m4/vasnprintf-posix.m4 | 16 ++++--- m4/vasnprintf.m4 | 17 ++++++- m4/vasprintf-posix.m4 | 16 ++++--- m4/vfprintf-posix.m4 | 12 +++-- m4/vsnprintf-posix.m4 | 22 +++++---- m4/vsprintf-posix.m4 | 12 +++-- tests/test-snprintf-posix.h | 10 +++++ tests/test-sprintf-posix.h | 10 +++++ tests/test-vasnprintf-posix.c | 12 +++++ tests/test-vasprintf-posix.c | 12 +++++ 24 files changed, 275 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index 67d2feaa1..3bae344b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2007-05-06 Bruno Haible + + * lib/vasnprintf.c (VASNPRINTF) [NEED_PRINTF_FLAG_GROUPING]: Don't + pass the ' flag character to sprintf or snprintf. + * m4/printf.m4 (gl_PRINTF_FLAG_GROUPING): New macro. + * m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_FLAG_GROUPING): New macro. + * m4/snprintf-posix.m4 (gl_FUNC_SNPRINTF_POSIX): Invoke + gl_PRINTF_FLAG_GROUPING and test its result. Invoke + gl_PREREQ_VASNPRINTF_FLAG_GROUPING. + * m4/sprintf-posix.m4 (gl_FUNC_SPRINTF_POSIX): Likewise. + * m4/fprintf-posix.m4 (gl_FUNC_FPRINTF_POSIX): Likewise. + * m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_POSIX): Likewise. + * m4/vasprintf-posix.m4 (gl_FUNC_VASPRINTF_POSIX): Likewise. + * m4/vfprintf-posix.m4 (gl_FUNC_VFPRINTF_POSIX): Likewise. + * m4/vsnprintf-posix.m4 (gl_FUNC_VSNPRINTF_POSIX): Likewise. + * m4/vsprintf-posix.m4 (gl_FUNC_VSPRINTF_POSIX): Likewise. + * tests/test-snprintf-posix.h (test_function): Also check the grouping + flag. + * tests/test-sprintf-posix.h (test_function): Likewise. + * tests/test-vasnprintf-posix.c (test_function): Likewise. + * tests/test-vasprintf-posix.c (test_function): Likewise. + * doc/functions/fprintf.texi: Update. + * doc/functions/printf.texi: Update. + * doc/functions/snprintf.texi: Update. + * doc/functions/sprintf.texi: Update. + * doc/functions/vfprintf.texi: Update. + * doc/functions/vprintf.texi: Update. + * doc/functions/vsnprintf.texi: Update. + * doc/functions/vsprintf.texi: Update. + 2007-05-01 Bruno Haible * tests/test-argp-2.sh (func_compare): Drop .exe suffix. diff --git a/doc/functions/fprintf.texi b/doc/functions/fprintf.texi index 86ea0bff4..476c31cab 100644 --- a/doc/functions/fprintf.texi +++ b/doc/functions/fprintf.texi @@ -23,14 +23,14 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin, mingw, This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. +@item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/doc/functions/printf.texi b/doc/functions/printf.texi index e2f1fa469..f794c8011 100644 --- a/doc/functions/printf.texi +++ b/doc/functions/printf.texi @@ -23,14 +23,14 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin, mingw, This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. +@item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/doc/functions/snprintf.texi b/doc/functions/snprintf.texi index 688e88de2..5a41a67d9 100644 --- a/doc/functions/snprintf.texi +++ b/doc/functions/snprintf.texi @@ -31,6 +31,9 @@ This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. @item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. +@item This function does not truncate the result as specified in C99 on some platforms: mingw. @item @@ -48,9 +51,6 @@ OSF/1 5.1. Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/doc/functions/sprintf.texi b/doc/functions/sprintf.texi index c38a79027..0760dd5dc 100644 --- a/doc/functions/sprintf.texi +++ b/doc/functions/sprintf.texi @@ -23,14 +23,14 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin, mingw, This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. +@item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/doc/functions/vfprintf.texi b/doc/functions/vfprintf.texi index 1fc3c9277..d5eeef276 100644 --- a/doc/functions/vfprintf.texi +++ b/doc/functions/vfprintf.texi @@ -23,14 +23,14 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin, mingw, This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. +@item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/doc/functions/vprintf.texi b/doc/functions/vprintf.texi index d9ee5c6fa..430dab203 100644 --- a/doc/functions/vprintf.texi +++ b/doc/functions/vprintf.texi @@ -23,14 +23,14 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin, mingw, This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. +@item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/doc/functions/vsnprintf.texi b/doc/functions/vsnprintf.texi index 6c8590787..3e6171672 100644 --- a/doc/functions/vsnprintf.texi +++ b/doc/functions/vsnprintf.texi @@ -31,6 +31,9 @@ This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. @item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. +@item This function does not truncate the result as specified in C99 on some platforms: mingw. @item @@ -48,9 +51,6 @@ HP-UX 11, OSF/1 5.1. Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/doc/functions/vsprintf.texi b/doc/functions/vsprintf.texi index a9bfe727e..6ec8e1bbc 100644 --- a/doc/functions/vsprintf.texi +++ b/doc/functions/vsprintf.texi @@ -23,14 +23,14 @@ NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, OSF/1 5.1, Solaris 9, Cygwin, mingw, This function does not support format directives that access arguments in an arbitrary order, such as @code{"%2$s"}, on some platforms: NetBSD 3.0, mingw, BeOS. +@item +This function doesn't support the @code{'} flag on some platforms: +NetBSD 3.0, mingw. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function doesn't support the @code{'} flag on some platforms: -mingw. -@item printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded with zeroes) on some platforms: FreeBSD 6.0. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index e11f1e998..205200b65 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -1012,8 +1012,14 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *lengthp, const CHAR_T *format, va_list ar sprintf. */ p = buf; *p++ = '%'; +#if NEED_PRINTF_FLAG_GROUPING + /* The underlying implementation doesn't support the ' flag. + Produce no grouping characters in this case; this is + acceptable because the grouping is locale dependent. */ +#else if (dp->flags & FLAG_GROUP) *p++ = '\''; +#endif if (dp->flags & FLAG_LEFT) *p++ = '-'; if (dp->flags & FLAG_SHOWSIGN) diff --git a/m4/fprintf-posix.m4 b/m4/fprintf-posix.m4 index 027147da6..c63815805 100644 --- a/m4/fprintf-posix.m4 +++ b/m4/fprintf-posix.m4 @@ -1,4 +1,4 @@ -# fprintf-posix.m4 serial 3 +# fprintf-posix.m4 serial 4 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_fprintf_posix=no case "$gl_cv_func_printf_sizes_c99" in *yes) @@ -23,8 +24,12 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - # fprintf exists and is already POSIX compliant. - gl_cv_func_fprintf_posix=yes + case "$gl_cv_func_printf_flag_grouping" in + *yes) + # fprintf exists and is already POSIX compliant. + gl_cv_func_fprintf_posix=yes + ;; + esac ;; esac ;; @@ -38,6 +43,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX], if test $gl_cv_func_fprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF gl_REPLACE_FPRINTF fi diff --git a/m4/printf.m4 b/m4/printf.m4 index 3387d8467..e09c9d880 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 7 +# printf.m4 serial 8 dnl Copyright (C) 2003, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -284,6 +284,40 @@ changequote([,])dnl ]) ]) +dnl Test whether the *printf family of functions supports POSIX/XSI format +dnl strings with the ' flag for grouping of decimal digits. (POSIX:2001) +dnl Result is gl_cv_func_printf_flag_grouping. + +AC_DEFUN([gl_PRINTF_FLAG_GROUPING], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the grouping flag], + [gl_cv_func_printf_flag_grouping], + [ + AC_TRY_RUN([ +#include +#include +static char buf[100]; +int main () +{ + if (sprintf (buf, "%'d %d", 1234567, 99) < 0 + || buf[strlen (buf) - 1] != '9') + return 1; + return 0; +}], [gl_cv_func_printf_flag_grouping=yes], [gl_cv_func_printf_flag_grouping=no], + [ +changequote(,)dnl + case "$host_os" in + netbsd*) gl_cv_func_printf_flag_grouping="guessing no";; + mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";; + *) gl_cv_func_printf_flag_grouping="guessing yes";; + esac +changequote([,])dnl + ]) + ]) +]) + dnl Test whether the snprintf function exists. (ISO C99, POSIX:2001) dnl Result is ac_cv_func_snprintf. @@ -590,44 +624,46 @@ dnl 2 = gl_PRINTF_DIRECTIVE_A dnl 3 = gl_PRINTF_DIRECTIVE_F dnl 4 = gl_PRINTF_DIRECTIVE_N dnl 5 = gl_PRINTF_POSITIONS -dnl 6 = gl_SNPRINTF_PRESENCE -dnl 7 = gl_SNPRINTF_TRUNCATION_C99 -dnl 8 = gl_SNPRINTF_RETVAL_C99 -dnl 9 = gl_SNPRINTF_DIRECTIVE_N -dnl 10 = gl_VSNPRINTF_ZEROSIZE_C99 +dnl 6 = gl_PRINTF_FLAG_GROUPING +dnl 7 = gl_SNPRINTF_PRESENCE +dnl 8 = gl_SNPRINTF_TRUNCATION_C99 +dnl 9 = gl_SNPRINTF_RETVAL_C99 +dnl 10 = gl_SNPRINTF_DIRECTIVE_N +dnl 11 = gl_VSNPRINTF_ZEROSIZE_C99 dnl dnl 1 = checking whether printf supports size specifiers as in C99... dnl 2 = checking whether printf supports the 'a' and 'A' directives... dnl 3 = checking whether printf supports the 'F' directive... dnl 4 = checking whether printf supports the 'n' directive... dnl 5 = checking whether printf supports POSIX/XSI format strings with positions... -dnl 6 = checking for snprintf... -dnl 7 = checking whether snprintf truncates the result as in C99... -dnl 8 = checking whether snprintf returns a byte count as in C99... -dnl 9 = checking whether snprintf fully supports the 'n' directive... -dnl 10 = checking whether vsnprintf respects a zero size as in C99... +dnl 6 = checking whether printf supports the grouping flag... +dnl 7 = checking for snprintf... +dnl 8 = checking whether snprintf truncates the result as in C99... +dnl 9 = checking whether snprintf returns a byte count as in C99... +dnl 10 = checking whether snprintf fully supports the 'n' directive... +dnl 11 = checking whether vsnprintf respects a zero size as in C99... dnl dnl . = yes, # = no. dnl -dnl 1 2 3 4 5 6 7 8 9 10 -dnl glibc 2.5 . . . . . . . . . . -dnl glibc 2.3.6 . # . . . . . . . . -dnl FreeBSD 5.4, 6.1 . ? . . . . . . . . -dnl MacOS X 10.3.9 . # . . . . . . . . -dnl OpenBSD 3.9, 4.0 . # ? . . . . . ? ? -dnl Cygwin 2007 . # # . . . . . . ? -dnl Cygwin 2006 # # # . . . . . . ? -dnl Solaris 10 . # . . . . . . . . -dnl Solaris 2.6 ... 9 # # # . . . . . . . -dnl Solaris 2.5.1 # # # . . # # # # # -dnl AIX 5.2 . # . . . . . . . . -dnl AIX 4.3.2, 5.1 # # # . . . . . . . -dnl HP-UX 11.31 . # . . . . . # # . -dnl HP-UX 10.20, 11.00, 11.11, 11.23 # # # . . . . # # # -dnl IRIX 6.5 # # # . . . . # . . -dnl OSF/1 5.1 # # # . . . . # . # -dnl OSF/1 4.0d # # # . . # # # # # -dnl NetBSD 4.0 . ? ? . . . . . ? ? -dnl NetBSD 3.0 . # # . # . . . . . -dnl BeOS # # # . # . . . . . -dnl mingw # # # . # . # # # . +dnl 1 2 3 4 5 6 7 8 9 10 11 +dnl glibc 2.5 . . . . . . . . . . . +dnl glibc 2.3.6 . # . . . . . . . . . +dnl FreeBSD 5.4, 6.1 . ? . . . . . . . . . +dnl MacOS X 10.3.9 . # . . . . . . . . . +dnl OpenBSD 3.9, 4.0 . # ? . . ? . . . ? ? +dnl Cygwin 2007 . # # . . ? . . . . ? +dnl Cygwin 2006 # # # . . ? . . . . ? +dnl Solaris 10 . # . . . . . . . . . +dnl Solaris 2.6 ... 9 # # # . . . . . . . . +dnl Solaris 2.5.1 # # # . . . # # # # # +dnl AIX 5.2 . # . . . . . . . . . +dnl AIX 4.3.2, 5.1 # # # . . . . . . . . +dnl HP-UX 11.31 . # . . . . . . # # . +dnl HP-UX 10.20, 11.00, 11.11, 11.23 # # # . . . . . # # # +dnl IRIX 6.5 # # # . . . . . # . . +dnl OSF/1 5.1 # # # . . . . . # . # +dnl OSF/1 4.0d # # # . . . # # # # # +dnl NetBSD 4.0 . ? ? . . ? . . . ? ? +dnl NetBSD 3.0 . # # . # # . . . . . +dnl BeOS # # # . # . . . . . . +dnl mingw # # # . # # . # # # . diff --git a/m4/snprintf-posix.m4 b/m4/snprintf-posix.m4 index 9e9ef1dfe..6208adcd4 100644 --- a/m4/snprintf-posix.m4 +++ b/m4/snprintf-posix.m4 @@ -1,4 +1,4 @@ -# snprintf-posix.m4 serial 4 +# snprintf-posix.m4 serial 5 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_snprintf_posix=no AC_CHECK_FUNCS([snprintf]) if test $ac_cv_func_snprintf = yes; then @@ -29,17 +30,21 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - case "$gl_cv_func_snprintf_truncation_c99" in + case "$gl_cv_func_printf_flag_grouping" in *yes) - case "$gl_cv_func_snprintf_retval_c99" in + case "$gl_cv_func_snprintf_truncation_c99" in *yes) - case "$gl_cv_func_snprintf_directive_n" in + case "$gl_cv_func_snprintf_retval_c99" in *yes) - case "$gl_cv_func_vsnprintf_zerosize_c99" in + case "$gl_cv_func_snprintf_directive_n" in *yes) - # snprintf exists and is already POSIX - # compliant. - gl_cv_func_snprintf_posix=yes + case "$gl_cv_func_vsnprintf_zerosize_c99" in + *yes) + # snprintf exists and is already + # POSIX compliant. + gl_cv_func_snprintf_posix=yes + ;; + esac ;; esac ;; @@ -62,6 +67,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX], if test $gl_cv_func_snprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF gl_REPLACE_SNPRINTF fi diff --git a/m4/sprintf-posix.m4 b/m4/sprintf-posix.m4 index c0c1d4aa1..bb354d1ef 100644 --- a/m4/sprintf-posix.m4 +++ b/m4/sprintf-posix.m4 @@ -1,4 +1,4 @@ -# sprintf-posix.m4 serial 3 +# sprintf-posix.m4 serial 4 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_sprintf_posix=no case "$gl_cv_func_printf_sizes_c99" in *yes) @@ -23,8 +24,12 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - # sprintf exists and is already POSIX compliant. - gl_cv_func_sprintf_posix=yes + case "$gl_cv_func_printf_flag_grouping" in + *yes) + # sprintf exists and is already POSIX compliant. + gl_cv_func_sprintf_posix=yes + ;; + esac ;; esac ;; @@ -38,6 +43,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX], if test $gl_cv_func_sprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF gl_REPLACE_SPRINTF fi diff --git a/m4/vasnprintf-posix.m4 b/m4/vasnprintf-posix.m4 index b570c1c8a..34eee29c8 100644 --- a/m4/vasnprintf-posix.m4 +++ b/m4/vasnprintf-posix.m4 @@ -1,4 +1,4 @@ -# vasnprintf-posix.m4 serial 4 +# vasnprintf-posix.m4 serial 5 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_vasnprintf_posix=no AC_CHECK_FUNCS_ONCE([vasnprintf]) case "$gl_cv_func_printf_sizes_c99" in @@ -24,10 +25,14 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - if test $ac_cv_func_vasnprintf = yes; then - # vasnprintf exists and is already POSIX compliant. - gl_cv_func_vasnprintf_posix=yes - fi + case "$gl_cv_func_printf_flag_grouping" in + *yes) + if test $ac_cv_func_vasnprintf = yes; then + # vasnprintf exists and is already POSIX compliant. + gl_cv_func_vasnprintf_posix=yes + fi + ;; + esac ;; esac ;; @@ -41,6 +46,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX], if test $gl_cv_func_vasnprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF fi ]) diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4 index 79886e75f..773c92f96 100644 --- a/m4/vasnprintf.m4 +++ b/m4/vasnprintf.m4 @@ -1,4 +1,4 @@ -# vasnprintf.m4 serial 13 +# vasnprintf.m4 serial 14 dnl Copyright (C) 2002-2004, 2006-2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -90,6 +90,21 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F], esac ]) +# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag. +AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING], +[ + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) + case "$gl_cv_func_printf_flag_grouping" in + *yes) + ;; + *) + AC_DEFINE([NEED_PRINTF_FLAG_GROUPING], 1, + [Define if the vasnprintf implementation needs special code for the + ' flag.]) + ;; + esac +]) + # Prerequisites of lib/asnprintf.c. AC_DEFUN([gl_PREREQ_ASNPRINTF], [ diff --git a/m4/vasprintf-posix.m4 b/m4/vasprintf-posix.m4 index 46ffc34f4..43151632e 100644 --- a/m4/vasprintf-posix.m4 +++ b/m4/vasprintf-posix.m4 @@ -1,4 +1,4 @@ -# vasprintf-posix.m4 serial 4 +# vasprintf-posix.m4 serial 5 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_vasprintf_posix=no AC_CHECK_FUNCS([vasprintf]) case "$gl_cv_func_printf_sizes_c99" in @@ -24,10 +25,14 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - if test $ac_cv_func_vasprintf = yes; then - # vasprintf exists and is already POSIX compliant. - gl_cv_func_vasprintf_posix=yes - fi + case "$gl_cv_func_printf_flag_grouping" in + *yes) + if test $ac_cv_func_vasprintf = yes; then + # vasprintf exists and is already POSIX compliant. + gl_cv_func_vasprintf_posix=yes + fi + ;; + esac ;; esac ;; @@ -41,6 +46,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX], if test $gl_cv_func_vasprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF gl_REPLACE_VASPRINTF fi diff --git a/m4/vfprintf-posix.m4 b/m4/vfprintf-posix.m4 index c217eb21f..669ae2008 100644 --- a/m4/vfprintf-posix.m4 +++ b/m4/vfprintf-posix.m4 @@ -1,4 +1,4 @@ -# vfprintf-posix.m4 serial 3 +# vfprintf-posix.m4 serial 4 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_vfprintf_posix=no case "$gl_cv_func_printf_sizes_c99" in *yes) @@ -23,8 +24,12 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - # vfprintf exists and is already POSIX compliant. - gl_cv_func_vfprintf_posix=yes + case "$gl_cv_func_printf_flag_grouping" in + *yes) + # vfprintf exists and is already POSIX compliant. + gl_cv_func_vfprintf_posix=yes + ;; + esac ;; esac ;; @@ -38,6 +43,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX], if test $gl_cv_func_vfprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF gl_REPLACE_VFPRINTF fi diff --git a/m4/vsnprintf-posix.m4 b/m4/vsnprintf-posix.m4 index f2cb58232..941cf515b 100644 --- a/m4/vsnprintf-posix.m4 +++ b/m4/vsnprintf-posix.m4 @@ -1,4 +1,4 @@ -# vsnprintf-posix.m4 serial 4 +# vsnprintf-posix.m4 serial 5 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_vsnprintf_posix=no AC_CHECK_FUNCS([vsnprintf]) if test $ac_cv_func_vsnprintf = yes; then @@ -30,17 +31,21 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - case "$gl_cv_func_snprintf_truncation_c99" in + case "$gl_cv_func_printf_flag_grouping" in *yes) - case "$gl_cv_func_snprintf_retval_c99" in + case "$gl_cv_func_snprintf_truncation_c99" in *yes) - case "$gl_cv_func_snprintf_directive_n" in + case "$gl_cv_func_snprintf_retval_c99" in *yes) - case "$gl_cv_func_vsnprintf_zerosize_c99" in + case "$gl_cv_func_snprintf_directive_n" in *yes) - # vsnprintf exists and is already POSIX - # compliant. - gl_cv_func_vsnprintf_posix=yes + case "$gl_cv_func_vsnprintf_zerosize_c99" in + *yes) + # vsnprintf exists and is already + # POSIX compliant. + gl_cv_func_vsnprintf_posix=yes + ;; + esac ;; esac ;; @@ -63,6 +68,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX], if test $gl_cv_func_vsnprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF gl_REPLACE_VSNPRINTF fi diff --git a/m4/vsprintf-posix.m4 b/m4/vsprintf-posix.m4 index 9c45ceba3..626da1eef 100644 --- a/m4/vsprintf-posix.m4 +++ b/m4/vsprintf-posix.m4 @@ -1,4 +1,4 @@ -# vsprintf-posix.m4 serial 3 +# vsprintf-posix.m4 serial 4 dnl Copyright (C) 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -12,6 +12,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX], AC_REQUIRE([gl_PRINTF_DIRECTIVE_F]) AC_REQUIRE([gl_PRINTF_DIRECTIVE_N]) AC_REQUIRE([gl_PRINTF_POSITIONS]) + AC_REQUIRE([gl_PRINTF_FLAG_GROUPING]) gl_cv_func_vsprintf_posix=no case "$gl_cv_func_printf_sizes_c99" in *yes) @@ -23,8 +24,12 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX], *yes) case "$gl_cv_func_printf_positions" in *yes) - # vsprintf exists and is already POSIX compliant. - gl_cv_func_vsprintf_posix=yes + case "$gl_cv_func_printf_flag_grouping" in + *yes) + # vsprintf exists and is already POSIX compliant. + gl_cv_func_vsprintf_posix=yes + ;; + esac ;; esac ;; @@ -38,6 +43,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX], if test $gl_cv_func_vsprintf_posix = no; then gl_PREREQ_VASNPRINTF_DIRECTIVE_A gl_PREREQ_VASNPRINTF_DIRECTIVE_F + gl_PREREQ_VASNPRINTF_FLAG_GROUPING gl_REPLACE_VASNPRINTF gl_REPLACE_VSPRINTF fi diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h index 36212dcee..7b1370b88 100644 --- a/tests/test-snprintf-posix.h +++ b/tests/test-snprintf-posix.h @@ -1006,4 +1006,14 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...)) ASSERT (strcmp (result, "55 33") == 0); ASSERT (retval == strlen (result)); } + + /* Test the support of the grouping flag. */ + + { + char result[100]; + int retval = + my_snprintf (result, sizeof (result), "%'d %d", 1234567, 99); + ASSERT (result[strlen (result) - 1] == '9'); + ASSERT (retval == strlen (result)); + } } diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h index fbb22ddcd..f6d70e617 100644 --- a/tests/test-sprintf-posix.h +++ b/tests/test-sprintf-posix.h @@ -992,4 +992,14 @@ test_function (int (*my_sprintf) (char *, const char *, ...)) ASSERT (strcmp (result, "55 33") == 0); ASSERT (retval == strlen (result)); } + + /* Test the support of the grouping flag. */ + + { + char result[1000]; + int retval = + my_sprintf (result, "%'d %d", 1234567, 99); + ASSERT (result[strlen (result) - 1] == '9'); + ASSERT (retval == strlen (result)); + } } diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c index f08e1ad99..4162d3b53 100644 --- a/tests/test-vasnprintf-posix.c +++ b/tests/test-vasnprintf-posix.c @@ -1236,6 +1236,18 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...)) ASSERT (length == strlen (result)); free (result); } + + /* Test the support of the grouping flag. */ + + { + size_t length; + char *result = + my_asnprintf (NULL, &length, "%'d %d", 1234567, 99); + ASSERT (result != NULL); + ASSERT (result[strlen (result) - 1] == '9'); + ASSERT (length == strlen (result)); + free (result); + } } static char * diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c index 40798ea2b..e26b8a5d0 100644 --- a/tests/test-vasprintf-posix.c +++ b/tests/test-vasprintf-posix.c @@ -1217,6 +1217,18 @@ test_function (int (*my_asprintf) (char **, const char *, ...)) ASSERT (retval == strlen (result)); free (result); } + + /* Test the support of the grouping flag. */ + + { + char *result; + int retval = + my_asprintf (&result, "%'d %d", 1234567, 99); + ASSERT (result != NULL); + ASSERT (result[strlen (result) - 1] == '9'); + ASSERT (retval == strlen (result)); + free (result); + } } static int -- 2.11.0