diff options
author | Bruno Haible <bruno@clisp.org> | 2023-03-23 13:51:41 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2023-03-24 02:45:52 +0100 |
commit | 0645e170eadd356967b0690ba8208d85e8042edd (patch) | |
tree | 7144fdbd0ccfbb81c7558578204983b1d3c2b300 /m4/printf.m4 | |
parent | f9a4ee73c3e7b544f640d0d04b55983d3a7b894e (diff) | |
download | gnulib-0645e170eadd356967b0690ba8208d85e8042edd.tar.gz |
vasnprintf-gnu: New module.
Suggested by Eric Blake in
<https://lists.gnu.org/archive/html/bug-gnulib/2023-03/msg00060.html>.
* lib/printf-parse.c (PRINTF_PARSE): Recognize the 'B' conversion.
* lib/printf-parse.h: Update comments.
* lib/wprintf-parse.h: Likewise.
* lib/vasnprintf.c (MAX_ROOM_NEEDED): Treat the 'B' conversion like 'b'.
(VASNPRINTF): Implement 'B' conversion if
NEED_PRINTF_DIRECTIVE_UPPERCASE_B is set. Support the 'B' conversion if
requested.
* m4/printf.m4 (gl_PRINTF_DIRECTIVE_B): When cross-compiling, guess yes
on glibc >= 2.35.
(gl_PRINTF_DIRECTIVE_UPPERCASE_B): New macro.
* m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS): Renamed
from gl_PREREQ_VASNPRINTF_WITH_EXTRAS.
(gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B,
gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS): New macros.
* m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_IS_POSIX): New macro,
extracted from gl_FUNC_VASNPRINTF_POSIX.
(gl_FUNC_VASNPRINTF_POSIX): Require it. Invoke
gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS.
* m4/vasnprintf-gnu.m4: New file.
* modules/vasnprintf-gnu: New file.
* modules/c-vasnprintf (configure.ac): Update.
* modules/unistdio/u8-vasnprintf (configure.ac): Likewise.
* modules/unistdio/u8-u8-vasnprintf (configure.ac): Likewise.
* modules/unistdio/u16-vasnprintf (configure.ac): Likewise.
* modules/unistdio/u16-u16-vasnprintf (configure.ac): Likewise.
* modules/unistdio/u32-vasnprintf (configure.ac): Likewise.
* modules/unistdio/u32-u32-vasnprintf (configure.ac): Likewise.
* modules/unistdio/ulc-vasnprintf (configure.ac): Likewise.
Diffstat (limited to 'm4/printf.m4')
-rw-r--r-- | m4/printf.m4 | 224 |
1 files changed, 146 insertions, 78 deletions
diff --git a/m4/printf.m4 b/m4/printf.m4 index 3cf8c87b1a..2f15df1e76 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 77 +# printf.m4 serial 78 dnl Copyright (C) 2003, 2007-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -632,8 +632,19 @@ int main () [gl_cv_func_printf_directive_b=no], [ case "$host_os" in - # Guess no on glibc systems. - *-gnu* | gnu*) gl_cv_func_printf_directive_b="guessing no";; + # Guess yes on glibc >= 2.35 systems. + *-gnu* | gnu*) + AC_EGREP_CPP([Lucky], [ + #include <features.h> + #ifdef __GNU_LIBRARY__ + #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2) + Lucky user + #endif + #endif + ], + [gl_cv_func_printf_directive_uppercase_b="guessing yes"], + [gl_cv_func_printf_directive_uppercase_b="guessing no"]) + ;; # Guess no on musl systems. *-musl* | midipix*) gl_cv_func_printf_directive_b="guessing no";; # Guess no on Android. @@ -647,6 +658,61 @@ int main () ]) ]) +dnl Test whether the *printf family of functions supports the 'B' conversion +dnl specifier for binary output of integers. +dnl (GNU, encouraged by ISO C23 ยง 7.23.6.1) +dnl Result is gl_cv_func_printf_directive_uppercase_b. + +AC_DEFUN([gl_PRINTF_DIRECTIVE_UPPERCASE_B], +[ + AC_REQUIRE([AC_PROG_CC]) + AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles + AC_CACHE_CHECK([whether printf supports the 'B' directive], + [gl_cv_func_printf_directive_uppercase_b], + [ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include <stdio.h> +#include <string.h> +static char buf[100]; +int main () +{ + int result = 0; + if (sprintf (buf, "%#B %d", 12345, 33, 44, 55) < 0 + || strcmp (buf, "0B11000000111001 33") != 0) + result |= 1; + return result; +}]])], + [gl_cv_func_printf_directive_uppercase_b=yes], + [gl_cv_func_printf_directive_uppercase_b=no], + [ + case "$host_os" in + # Guess yes on glibc >= 2.35 systems. + *-gnu* | gnu*) + AC_EGREP_CPP([Lucky], [ + #include <features.h> + #ifdef __GNU_LIBRARY__ + #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 35) || (__GLIBC__ > 2) + Lucky user + #endif + #endif + ], + [gl_cv_func_printf_directive_uppercase_b="guessing yes"], + [gl_cv_func_printf_directive_uppercase_b="guessing no"]) + ;; + # Guess no on musl systems. + *-musl* | midipix*) gl_cv_func_printf_directive_uppercase_b="guessing no";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_directive_uppercase_b="guessing no";; + # Guess no on native Windows. + mingw*) gl_cv_func_printf_directive_uppercase_b="guessing no";; + # If we don't know, obey --enable-cross-guesses. + *) gl_cv_func_printf_directive_uppercase_b="$gl_cross_guess_normal";; + esac + ]) + ]) +]) + dnl Test whether the *printf family of functions supports the %F format dnl directive. (ISO C99, POSIX:2001) dnl Result is gl_cv_func_printf_directive_f. @@ -1806,23 +1872,24 @@ dnl 3 = gl_PRINTF_INFINITE dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE dnl 5 = gl_PRINTF_DIRECTIVE_A dnl 6 = gl_PRINTF_DIRECTIVE_B -dnl 7 = gl_PRINTF_DIRECTIVE_F -dnl 8 = gl_PRINTF_DIRECTIVE_N -dnl 9 = gl_PRINTF_DIRECTIVE_LS -dnl 10 = gl_PRINTF_DIRECTIVE_LC -dnl 11 = gl_PRINTF_POSITIONS -dnl 12 = gl_PRINTF_FLAG_GROUPING -dnl 13 = gl_PRINTF_FLAG_LEFTADJUST -dnl 14 = gl_PRINTF_FLAG_ZERO -dnl 15 = gl_PRINTF_PRECISION -dnl 16 = gl_PRINTF_ENOMEM -dnl 17 = gl_SNPRINTF_PRESENCE -dnl 18 = gl_SNPRINTF_TRUNCATION_C99 -dnl 19 = gl_SNPRINTF_RETVAL_C99 -dnl 10 = gl_SNPRINTF_DIRECTIVE_N -dnl 21 = gl_SNPRINTF_SIZE1 -dnl 22 = gl_VSNPRINTF_ZEROSIZE_C99 -dnl 23 = gl_SWPRINTF_WORKS +dnl 7 = gl_PRINTF_DIRECTIVE_UPPERCASE_B +dnl 8 = gl_PRINTF_DIRECTIVE_F +dnl 9 = gl_PRINTF_DIRECTIVE_N +dnl 10 = gl_PRINTF_DIRECTIVE_LS +dnl 11 = gl_PRINTF_DIRECTIVE_LC +dnl 12 = gl_PRINTF_POSITIONS +dnl 13 = gl_PRINTF_FLAG_GROUPING +dnl 14 = gl_PRINTF_FLAG_LEFTADJUST +dnl 15 = gl_PRINTF_FLAG_ZERO +dnl 16 = gl_PRINTF_PRECISION +dnl 17 = gl_PRINTF_ENOMEM +dnl 18 = gl_SNPRINTF_PRESENCE +dnl 19 = gl_SNPRINTF_TRUNCATION_C99 +dnl 20 = gl_SNPRINTF_RETVAL_C99 +dnl 21 = gl_SNPRINTF_DIRECTIVE_N +dnl 22 = gl_SNPRINTF_SIZE1 +dnl 23 = gl_VSNPRINTF_ZEROSIZE_C99 +dnl 24 = gl_SWPRINTF_WORKS dnl dnl 1 = checking whether printf supports size specifiers as in C99... dnl 2 = checking whether printf supports 'long double' arguments... @@ -1830,64 +1897,65 @@ dnl 3 = checking whether printf supports infinite 'double' arguments... dnl 4 = checking whether printf supports infinite 'long double' arguments... dnl 5 = checking whether printf supports the 'a' and 'A' directives... dnl 6 = checking whether printf supports the 'b' directive... -dnl 7 = checking whether printf supports the 'F' directive... -dnl 8 = checking whether printf supports the 'n' directive... -dnl 9 = checking whether printf supports the 'ls' directive... -dnl 10 = checking whether printf supports the 'lc' directive correctly... -dnl 11 = checking whether printf supports POSIX/XSI format strings with positions... -dnl 12 = checking whether printf supports the grouping flag... -dnl 13 = checking whether printf supports the left-adjust flag correctly... -dnl 14 = checking whether printf supports the zero flag correctly... -dnl 15 = checking whether printf supports large precisions... -dnl 16 = checking whether printf survives out-of-memory conditions... -dnl 17 = checking for snprintf... -dnl 18 = checking whether snprintf truncates the result as in C99... -dnl 19 = checking whether snprintf returns a byte count as in C99... -dnl 20 = checking whether snprintf fully supports the 'n' directive... -dnl 21 = checking whether snprintf respects a size of 1... -dnl 22 = checking whether vsnprintf respects a zero size as in C99... -dnl 23 = checking whether swprintf works... +dnl 7 = checking whether printf supports the 'B' directive... +dnl 8 = checking whether printf supports the 'F' directive... +dnl 9 = checking whether printf supports the 'n' directive... +dnl 10 = checking whether printf supports the 'ls' directive... +dnl 11 = checking whether printf supports the 'lc' directive correctly... +dnl 12 = checking whether printf supports POSIX/XSI format strings with positions... +dnl 13 = checking whether printf supports the grouping flag... +dnl 14 = checking whether printf supports the left-adjust flag correctly... +dnl 15 = checking whether printf supports the zero flag correctly... +dnl 16 = checking whether printf supports large precisions... +dnl 17 = checking whether printf survives out-of-memory conditions... +dnl 18 = checking for snprintf... +dnl 19 = checking whether snprintf truncates the result as in C99... +dnl 20 = checking whether snprintf returns a byte count as in C99... +dnl 21 = checking whether snprintf fully supports the 'n' directive... +dnl 22 = checking whether snprintf respects a size of 1... +dnl 23 = checking whether vsnprintf respects a zero size as in C99... +dnl 24 = checking whether swprintf works... dnl dnl . = yes, # = no. dnl -dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 -dnl musl libc 1.2.3 . . . . . # . . . . . . . . . . . . . . . . # -dnl glibc 2.35 . . . . . . . . . # . . . . . . . . . . . . . -dnl glibc 2.5 . . . . . # . . . # . . . . . . . . . . . . ? -dnl glibc 2.3.6 . . . . # # . . . # . . . . . . . . . . . . ? -dnl FreeBSD 13.0 . . . . # # . . . # . . . . . # . . . . . . # -dnl FreeBSD 5.4, 6.1 . . . . # # . . . # . . . # . # . . . . . . # -dnl Mac OS X 10.13.5 . . . # # # . # . # . . . . . . . . . # . . # -dnl Mac OS X 10.5.8 . . . # # # . . . # . . . # . . . . . . . . # -dnl Mac OS X 10.3.9 . . . . # # . . . # . . . # . # . . . . . . # -dnl OpenBSD 6.0, 6.7 . . . . # # . . . # . . . . . # . . . . . . # -dnl OpenBSD 3.9, 4.0 . . # # # # # . # # . # . # . # . . . . . . # -dnl Cygwin 1.7.0 (2009) . . . # . # . . ? ? . . . . . ? . . . . . . ? -dnl Cygwin 1.5.25 (2008) . . . # # # . . # ? . . . . . # . . . . . . ? -dnl Cygwin 1.5.19 (2006) # . . # # # # . # ? . # . # # # . . . . . . ? -dnl Solaris 11.4 . . # # # # . . # # . . . # . . . . . . . . . -dnl Solaris 11.3 . . . . # # . . # # . . . . . . . . . . . . . -dnl Solaris 11.0 . . # # # # . . # # . . . # . . . . . . . . ? -dnl Solaris 10 . . # # # # . . # # . . . # # . . . . . . . ? -dnl Solaris 2.6 ... 9 # . # # # # # . # # . . . # # . . . # . . . ? -dnl Solaris 2.5.1 # . # # # # # . # # . . . # . . # # # # # # ? -dnl AIX 7.1 . . # # # # . . . # . . . # # . . . . . . . # -dnl AIX 5.2 . . # # # # . . . # . . . # . . . . . . . . # -dnl AIX 4.3.2, 5.1 # . # # # # # . . # . . . # . . . . # . . . # -dnl HP-UX 11.31 . . . . # # . . . ? . . . # . . . . # # . . ? -dnl HP-UX 11.{00,11,23} # . . . # # # . . ? . . . # . . . . # # . # ? -dnl HP-UX 10.20 # . # . # # # . ? ? . . # # . . . . # # ? # ? -dnl IRIX 6.5 # . # # # # # . # # . . . # . . . . # . . . # -dnl OSF/1 5.1 # . # # # # # . . ? . . . # . . . . # . . # ? -dnl OSF/1 4.0d # . # # # # # . . ? . . . # . . # # # # # # ? -dnl NetBSD 9.0 . . . . # # . . . # . . . . . . . . . . . . # -dnl NetBSD 5.0 . . . # # # . . . # . . . # . # . . . . . . # -dnl NetBSD 4.0 . ? ? ? ? # ? . ? # . ? ? ? ? ? . . . ? ? ? # -dnl NetBSD 3.0 . . . . # # # . ? # # # ? # . # . . . . . . # -dnl Haiku . . . # # # # . # ? . . . . . ? . . ? . . . ? -dnl BeOS # # . # # # # . ? ? # . ? . # ? . . ? . . . ? -dnl Android 4.3 . . # # # # # # # ? . # . # . # . . . # . . ? -dnl old mingw / msvcrt # # # # # # # . . ? # # . # # ? . # # # . . # -dnl MSVC 9 # # # # # # # # . ? # # . # # ? # # # # . . # -dnl mingw 2009-2011 . # . # . # . . . ? # # . . . ? . . . . . . # -dnl mingw-w64 2011 # # # # # # # . . ? # # . # # ? . # # # . . # +dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 +dnl musl libc 1.2.3 . . . . . # # . . . . . . . . . . . . . . . . # +dnl glibc 2.35 . . . . . . . . . . # . . . . . . . . . . . . . +dnl glibc 2.5 . . . . . # # . . . # . . . . . . . . . . . . ? +dnl glibc 2.3.6 . . . . # # # . . . # . . . . . . . . . . . . ? +dnl FreeBSD 13.0 . . . . # # # . . . # . . . . . # . . . . . . # +dnl FreeBSD 5.4, 6.1 . . . . # # # . . . # . . . # . # . . . . . . # +dnl Mac OS X 10.13.5 . . . # # # # . # . # . . . . . . . . . # . . # +dnl Mac OS X 10.5.8 . . . # # # # . . . # . . . # . . . . . . . . # +dnl Mac OS X 10.3.9 . . . . # # # . . . # . . . # . # . . . . . . # +dnl OpenBSD 6.0, 6.7 . . . . # # # . . . # . . . . . # . . . . . . # +dnl OpenBSD 3.9, 4.0 . . # # # # # # . # # . # . # . # . . . . . . # +dnl Cygwin 1.7.0 (2009) . . . # . # # . . ? ? . . . . . ? . . . . . . ? +dnl Cygwin 1.5.25 (2008) . . . # # # # . . # ? . . . . . # . . . . . . ? +dnl Cygwin 1.5.19 (2006) # . . # # # # # . # ? . # . # # # . . . . . . ? +dnl Solaris 11.4 . . # # # # # . . # # . . . # . . . . . . . . . +dnl Solaris 11.3 . . . . # # # . . # # . . . . . . . . . . . . . +dnl Solaris 11.0 . . # # # # # . . # # . . . # . . . . . . . . ? +dnl Solaris 10 . . # # # # # . . # # . . . # # . . . . . . . ? +dnl Solaris 2.6 ... 9 # . # # # # # # . # # . . . # # . . . # . . . ? +dnl Solaris 2.5.1 # . # # # # # # . # # . . . # . . # # # # # # ? +dnl AIX 7.1 . . # # # # # . . . # . . . # # . . . . . . . # +dnl AIX 5.2 . . # # # # # . . . # . . . # . . . . . . . . # +dnl AIX 4.3.2, 5.1 # . # # # # # # . . # . . . # . . . . # . . . # +dnl HP-UX 11.31 . . . . # # # . . . ? . . . # . . . . # # . . ? +dnl HP-UX 11.{00,11,23} # . . . # # # # . . ? . . . # . . . . # # . # ? +dnl HP-UX 10.20 # . # . # # # # . ? ? . . # # . . . . # # ? # ? +dnl IRIX 6.5 # . # # # # # # . # # . . . # . . . . # . . . # +dnl OSF/1 5.1 # . # # # # # # . . ? . . . # . . . . # . . # ? +dnl OSF/1 4.0d # . # # # # # # . . ? . . . # . . # # # # # # ? +dnl NetBSD 9.0 . . . . # # # . . . # . . . . . . . . . . . . # +dnl NetBSD 5.0 . . . # # # # . . . # . . . # . # . . . . . . # +dnl NetBSD 4.0 . ? ? ? ? # # ? . ? # . ? ? ? ? ? . . . ? ? ? # +dnl NetBSD 3.0 . . . . # # # # . ? # # # ? # . # . . . . . . # +dnl Haiku . . . # # # # # . # ? . . . . . ? . . ? . . . ? +dnl BeOS # # . # # # # # . ? ? # . ? . # ? . . ? . . . ? +dnl Android 4.3 . . # # # # # # # # ? . # . # . # . . . # . . ? +dnl old mingw / msvcrt # # # # # # # # . . ? # # . # # ? . # # # . . # +dnl MSVC 9 # # # # # # # # # . ? # # . # # ? # # # # . . # +dnl mingw 2009-2011 . # . # . # # . . . ? # # . . . ? . . . . . . # +dnl mingw-w64 2011 # # # # # # # # . . ? # # . # # ? . # # # . . # |