]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf-gnu: New module.
authorBruno Haible <bruno@clisp.org>
Thu, 23 Mar 2023 12:51:41 +0000 (13:51 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 24 Mar 2023 01:45:52 +0000 (02:45 +0100)
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.

18 files changed:
ChangeLog
lib/printf-parse.c
lib/printf-parse.h
lib/vasnprintf.c
lib/wprintf-parse.h
m4/printf.m4
m4/vasnprintf-gnu.m4 [new file with mode: 0644]
m4/vasnprintf-posix.m4
m4/vasnprintf.m4
modules/c-vasnprintf
modules/unistdio/u16-u16-vasnprintf
modules/unistdio/u16-vasnprintf
modules/unistdio/u32-u32-vasnprintf
modules/unistdio/u32-vasnprintf
modules/unistdio/u8-u8-vasnprintf
modules/unistdio/u8-vasnprintf
modules/unistdio/ulc-vasnprintf
modules/vasnprintf-gnu [new file with mode: 0644]

index 4a70e323aefbbc3fdf50ed1880763f3e6b17f4a5..ccab8c88cf5c072dc5b4fe9a2eb7dac36a39c1d8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2023-03-23  Bruno Haible  <bruno@clisp.org>
+
+       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.
+
 2023-03-23  Bruno Haible  <bruno@clisp.org>
 
        printf-posix tests: Fix compilation error (regression 2021-08-28).
index 6273dd773fac757dd98f0836e6d9c9b58ee005f1..7fbd1d4b53ffaf126fa2987a42933c3f207a10a0 100644 (file)
@@ -454,6 +454,10 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
                     type = TYPE_INT;
                   break;
                 case 'b': case 'o': case 'u': case 'x': case 'X':
+                #if SUPPORT_GNU_PRINTF_DIRECTIVES \
+                    || (__GLIBC__ + (__GLIBC_MINOR__ >= 35) > 2)
+                case 'B':
+                #endif
                   /* If 'unsigned long long' is larger than 'unsigned long':  */
                   if (flags >= 16 || (flags & 4))
                     type = TYPE_ULONGLONGINT;
index dc4bcfe2a3fa245ba79a0ed15cbbb350a5aba921..45febac1f04cfabe65ad41b68ec6b458eb2b72fe 100644 (file)
@@ -61,7 +61,7 @@ typedef struct
   const char* precision_start;
   const char* precision_end;
   size_t precision_arg_index;
-  char conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
+  char conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
   size_t arg_index;
 }
 char_directive;
@@ -91,7 +91,7 @@ typedef struct
   const uint8_t* precision_start;
   const uint8_t* precision_end;
   size_t precision_arg_index;
-  uint8_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
+  uint8_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
   size_t arg_index;
 }
 u8_directive;
@@ -119,7 +119,7 @@ typedef struct
   const uint16_t* precision_start;
   const uint16_t* precision_end;
   size_t precision_arg_index;
-  uint16_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
+  uint16_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
   size_t arg_index;
 }
 u16_directive;
@@ -147,7 +147,7 @@ typedef struct
   const uint32_t* precision_start;
   const uint32_t* precision_end;
   size_t precision_arg_index;
-  uint32_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
+  uint32_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
   size_t arg_index;
 }
 u32_directive;
index 248444ca23eb95bc768ce0ab379210533b66e61e..bb7d0aec253f5870cd4745c0639965ca7bef8b17 100644 (file)
@@ -1660,6 +1660,10 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
       break;
 
     case 'b':
+    #if SUPPORT_GNU_PRINTF_DIRECTIVES \
+        || (__GLIBC__ + (__GLIBC_MINOR__ >= 35) > 2)
+    case 'B':
+    #endif
       if (type == TYPE_ULONGLONGINT)
         tmp_length =
           (unsigned int) (sizeof (unsigned long long) * CHAR_BIT)
@@ -3212,8 +3216,15 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 }
               }
 #endif
-#if NEED_PRINTF_DIRECTIVE_B
-            else if (dp->conversion == 'b')
+#if NEED_PRINTF_DIRECTIVE_B || NEED_PRINTF_DIRECTIVE_UPPERCASE_B
+            else if (0
+# if NEED_PRINTF_DIRECTIVE_B
+                     || (dp->conversion == 'b')
+# endif
+# if NEED_PRINTF_DIRECTIVE_UPPERCASE_B
+                     || (dp->conversion == 'B')
+# endif
+                    )
               {
                 arg_type type = a.arg[dp->arg_index].type;
                 int flags = dp->flags;
@@ -3359,7 +3370,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
 
                 if (need_prefix)
                   {
-                    *--p = 'b'; *--p = '0';
+# if NEED_PRINTF_DIRECTIVE_B && !NEED_PRINTF_DIRECTIVE_UPPERCASE_B
+                    *--p = 'b';
+# elif NEED_PRINTF_DIRECTIVE_UPPERCASE_B && !NEED_PRINTF_DIRECTIVE_B
+                    *--p = 'B';
+# else
+                    *--p = dp->conversion;
+# endif
+                    *--p = '0';
                   }
                 tmp_start = p;
 
@@ -5209,6 +5227,10 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                   {
                   case 'd': case 'i': case 'u':
                   case 'b':
+                  #if SUPPORT_GNU_PRINTF_DIRECTIVES \
+                      || (__GLIBC__ + (__GLIBC_MINOR__ >= 35) > 2)
+                  case 'B':
+                  #endif
                   case 'o':
                   case 'x': case 'X': case 'p':
                     prec_ourselves = has_precision && (precision > 0);
index 86bdec9a21a55e9069626cc19940c0320f4a53f4..fe4629827828d2d6b3641801f98be9077f891696 100644 (file)
@@ -55,7 +55,7 @@ typedef struct
   const wchar_t* precision_start;
   const wchar_t* precision_end;
   size_t precision_arg_index;
-  wchar_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
+  wchar_t conversion; /* d i b o u x X f F e E g G a A c s p n U % but not C S */
   size_t arg_index;
 }
 wchar_t_directive;
index 3cf8c87b1ad8ce25a62a811be94d9b6b502d7050..2f15df1e767dba2fa4bb267561bdd11ace8f536b 100644 (file)
@@ -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                 #  #  #  #  #  #  #  #  .  .  ?  #  #  .  #  #  ?  .  #  #  #  .  .  #
diff --git a/m4/vasnprintf-gnu.m4 b/m4/vasnprintf-gnu.m4
new file mode 100644 (file)
index 0000000..8c7124f
--- /dev/null
@@ -0,0 +1,24 @@
+# vasnprintf-gnu.m4 serial 1
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_VASNPRINTF_GNU],
+[
+  AC_REQUIRE([gl_FUNC_VASNPRINTF_IS_POSIX])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_UPPERCASE_B])
+  gl_cv_func_vasnprintf_gnu=no
+  if test $gl_cv_func_vasnprintf_posix = yes; then
+    case "$gl_cv_func_printf_directive_uppercase_b" in
+      *yes)
+        # vasnprintf exists and is already POSIX compliant and GNU compatible.
+        gl_cv_func_vasnprintf_gnu=yes
+        ;;
+    esac
+  fi
+  if test $gl_cv_func_vasnprintf_gnu = no; then
+    gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS
+    gl_REPLACE_VASNPRINTF
+  fi
+])
index d061d3136e7c0f01ab07eaa5d4c2192d60e5dc5d..b4d1e3d0aaee54ff63ac173057a6dbd1dd181e07 100644 (file)
@@ -1,10 +1,21 @@
-# vasnprintf-posix.m4 serial 15
+# vasnprintf-posix.m4 serial 16
 dnl Copyright (C) 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,
 dnl with or without modifications, as long as this notice is preserved.
 
 AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
+[
+  AC_REQUIRE([gl_FUNC_VASNPRINTF_IS_POSIX])
+  if test $gl_cv_func_vasnprintf_posix = no; then
+    gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
+    gl_REPLACE_VASNPRINTF
+  fi
+])
+
+dnl Test whether vasnprintf exists and is POSIX compliant.
+dnl Result is gl_cv_func_vasnprintf_posix.
+AC_DEFUN_ONCE([gl_FUNC_VASNPRINTF_IS_POSIX],
 [
   AC_REQUIRE([gl_PRINTF_SIZES_C99])
   AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
@@ -93,20 +104,4 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
       esac
       ;;
   esac
-  if test $gl_cv_func_vasnprintf_posix = no; then
-    gl_PREREQ_VASNPRINTF_LONG_DOUBLE
-    gl_PREREQ_VASNPRINTF_INFINITE_DOUBLE
-    gl_PREREQ_VASNPRINTF_INFINITE_LONG_DOUBLE
-    gl_PREREQ_VASNPRINTF_DIRECTIVE_A
-    gl_PREREQ_VASNPRINTF_DIRECTIVE_B
-    gl_PREREQ_VASNPRINTF_DIRECTIVE_F
-    gl_PREREQ_VASNPRINTF_DIRECTIVE_LS
-    gl_PREREQ_VASNPRINTF_DIRECTIVE_LC
-    gl_PREREQ_VASNPRINTF_FLAG_GROUPING
-    gl_PREREQ_VASNPRINTF_FLAG_LEFTADJUST
-    gl_PREREQ_VASNPRINTF_FLAG_ZERO
-    gl_PREREQ_VASNPRINTF_PRECISION
-    gl_PREREQ_VASNPRINTF_ENOMEM
-    gl_REPLACE_VASNPRINTF
-  fi
 ])
index a42b5f83ac8e3a239c8adb52e93680d6637bd636..929f3d80af790f348ad12002125870b6cb4e753d 100644 (file)
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 46
+# vasnprintf.m4 serial 47
 dnl Copyright (C) 2002-2004, 2006-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,
@@ -341,7 +341,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_ENOMEM],
 ])
 
 # Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance.
-AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
+AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS],
 [
   AC_REQUIRE([gl_PREREQ_VASNPRINTF])
   gl_PREREQ_VASNPRINTF_LONG_DOUBLE
@@ -359,6 +359,32 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
   gl_PREREQ_VASNPRINTF_ENOMEM
 ])
 
+# Extra prerequisites of lib/vasnprintf.c for supporting the 'B' directive.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B],
+[
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_UPPERCASE_B])
+  case "$gl_cv_func_printf_directive_uppercase_b" in
+    *yes)
+      ;;
+    *)
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_UPPERCASE_B], [1],
+        [Define if the vasnprintf implementation needs special code for
+         the 'B' directive.])
+      ;;
+  esac
+])
+
+# Prerequisites of lib/vasnprintf.c including all extras for POSIX compliance
+# and GNU compatibility.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS],
+[
+  gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
+  AC_DEFINE([SUPPORT_GNU_PRINTF_DIRECTIVES], [1],
+    [Define if the vasnprintf implementation should support GNU compatible
+     printf directives.])
+  gl_PREREQ_VASNPRINTF_DIRECTIVE_UPPERCASE_B
+])
+
 # Prerequisites of lib/asnprintf.c.
 # Prerequisites of lib/asnwprintf.c.
 AC_DEFUN([gl_PREREQ_ASNPRINTF],
index 44259c1f0e602021800e54d1790a27c6774a444c..35adfbbbdfad4a437b58fb02e3afbd9b743279f6 100644 (file)
@@ -43,7 +43,7 @@ multiarch
 
 configure.ac:
 AC_REQUIRE([AC_C_RESTRICT])
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 
 Makefile.am:
 lib_SOURCES += c-vasnprintf.c
index ac8df9f1b117061d4bed8f6fc2241a9574ba51a1..d3ad4ffe92317bf5050cebc4e841c879c407dad7 100644 (file)
@@ -50,7 +50,7 @@ multiarch
 assert-h
 
 configure.ac:
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-u16-vasnprintf])
 
 Makefile.am:
index e767f54bd3d03d2bc202f2ac9ca05b0935797548..908f043a4e3166b353e924ae3f19f90adc0e0ed5 100644 (file)
@@ -50,7 +50,7 @@ multiarch
 assert-h
 
 configure.ac:
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 gl_LIBUNISTRING_MODULE([0.9], [unistdio/u16-vasnprintf])
 
 Makefile.am:
index 86e669723b8c5aebed09425225882b73164ae977..e64e97d4dda55fa1667ae73b094d442166e71bdf 100644 (file)
@@ -50,7 +50,7 @@ multiarch
 assert-h
 
 configure.ac:
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 gl_LIBUNISTRING_MODULE([0.9], [unistdio/u32-u32-vasnprintf])
 
 Makefile.am:
index 58185bc34bdb8c0eacb6f168c58ddaa44b773e12..8fb0187382a242104e166164e375d5673671548a 100644 (file)
@@ -50,7 +50,7 @@ multiarch
 assert-h
 
 configure.ac:
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 gl_LIBUNISTRING_MODULE([0.9], [unistdio/u32-vasnprintf])
 
 Makefile.am:
index 63ab8d876815c4d7a8a9d6366d0b08bcf35b2d20..f91638bf8398f831c5e67b00bd506a3a852999ac 100644 (file)
@@ -50,7 +50,7 @@ multiarch
 assert-h
 
 configure.ac:
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 gl_LIBUNISTRING_MODULE([0.9], [unistdio/u8-u8-vasnprintf])
 
 Makefile.am:
index f6be0a5de3bc51f03fd52b300c4e7174166103ec..f8d7e79d6850b955c5f39badf756548b9eb4151c 100644 (file)
@@ -50,7 +50,7 @@ multiarch
 assert-h
 
 configure.ac:
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 gl_LIBUNISTRING_MODULE([0.9], [unistdio/u8-vasnprintf])
 
 Makefile.am:
index 7f7614d8ac2430bd539b5eea2d8b8cefa46100d3..c950cbf62a919cfe33c5a7fd825c90f6da80017e 100644 (file)
@@ -48,7 +48,7 @@ multiarch
 assert-h
 
 configure.ac:
-gl_PREREQ_VASNPRINTF_WITH_EXTRAS
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
 gl_LIBUNISTRING_MODULE([0.9.11], [unistdio/ulc-vasnprintf])
 
 Makefile.am:
diff --git a/modules/vasnprintf-gnu b/modules/vasnprintf-gnu
new file mode 100644 (file)
index 0000000..b5551f3
--- /dev/null
@@ -0,0 +1,29 @@
+Description:
+POSIX and GNU compatible vsprintf with automatic memory allocation and bounded
+output size.
+
+Comment:
+This module should not be used as a dependency from a test module,
+otherwise when this module occurs as a tests-related module, it will
+have side effects on the compilation of the 'vasnprintf' module, if
+that module occurs among the main modules in lib/.
+
+Files:
+m4/vasnprintf-gnu.m4
+
+Depends-on:
+vasnprintf-posix
+
+configure.ac:
+gl_FUNC_VASNPRINTF_GNU
+
+Makefile.am:
+
+Include:
+"vasnprintf.h"
+
+License:
+LGPLv2+
+
+Maintainer:
+all