summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-03-23 13:51:41 +0100
committerBruno Haible <bruno@clisp.org>2023-03-24 02:45:52 +0100
commit0645e170eadd356967b0690ba8208d85e8042edd (patch)
tree7144fdbd0ccfbb81c7558578204983b1d3c2b300
parentf9a4ee73c3e7b544f640d0d04b55983d3a7b894e (diff)
downloadgnulib-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.
-rw-r--r--ChangeLog34
-rw-r--r--lib/printf-parse.c4
-rw-r--r--lib/printf-parse.h8
-rw-r--r--lib/vasnprintf.c28
-rw-r--r--lib/wprintf-parse.h2
-rw-r--r--m4/printf.m4224
-rw-r--r--m4/vasnprintf-gnu.m424
-rw-r--r--m4/vasnprintf-posix.m429
-rw-r--r--m4/vasnprintf.m430
-rw-r--r--modules/c-vasnprintf2
-rw-r--r--modules/unistdio/u16-u16-vasnprintf2
-rw-r--r--modules/unistdio/u16-vasnprintf2
-rw-r--r--modules/unistdio/u32-u32-vasnprintf2
-rw-r--r--modules/unistdio/u32-vasnprintf2
-rw-r--r--modules/unistdio/u8-u8-vasnprintf2
-rw-r--r--modules/unistdio/u8-vasnprintf2
-rw-r--r--modules/unistdio/ulc-vasnprintf2
-rw-r--r--modules/vasnprintf-gnu29
18 files changed, 315 insertions, 113 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a70e323ae..ccab8c88cf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,39 @@
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).
* modules/printf-posix-tests (Files): Add tests/qemu.h.
diff --git a/lib/printf-parse.c b/lib/printf-parse.c
index 6273dd773f..7fbd1d4b53 100644
--- a/lib/printf-parse.c
+++ b/lib/printf-parse.c
@@ -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;
diff --git a/lib/printf-parse.h b/lib/printf-parse.h
index dc4bcfe2a3..45febac1f0 100644
--- a/lib/printf-parse.h
+++ b/lib/printf-parse.h
@@ -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 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 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 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 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;
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 248444ca23..bb7d0aec25 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -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);
diff --git a/lib/wprintf-parse.h b/lib/wprintf-parse.h
index 86bdec9a21..fe46298278 100644
--- a/lib/wprintf-parse.h
+++ b/lib/wprintf-parse.h
@@ -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 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;
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 # # # # # # # # . . ? # # . # # ? . # # # . . #
diff --git a/m4/vasnprintf-gnu.m4 b/m4/vasnprintf-gnu.m4
new file mode 100644
index 0000000000..8c7124f6cf
--- /dev/null
+++ b/m4/vasnprintf-gnu.m4
@@ -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
+])
diff --git a/m4/vasnprintf-posix.m4 b/m4/vasnprintf-posix.m4
index d061d3136e..b4d1e3d0aa 100644
--- a/m4/vasnprintf-posix.m4
+++ b/m4/vasnprintf-posix.m4
@@ -1,4 +1,4 @@
-# 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,
@@ -6,6 +6,17 @@ 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])
AC_REQUIRE([gl_PRINTF_INFINITE])
@@ -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
])
diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4
index a42b5f83ac..929f3d80af 100644
--- a/m4/vasnprintf.m4
+++ b/m4/vasnprintf.m4
@@ -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],
diff --git a/modules/c-vasnprintf b/modules/c-vasnprintf
index 44259c1f0e..35adfbbbdf 100644
--- a/modules/c-vasnprintf
+++ b/modules/c-vasnprintf
@@ -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
diff --git a/modules/unistdio/u16-u16-vasnprintf b/modules/unistdio/u16-u16-vasnprintf
index ac8df9f1b1..d3ad4ffe92 100644
--- a/modules/unistdio/u16-u16-vasnprintf
+++ b/modules/unistdio/u16-u16-vasnprintf
@@ -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:
diff --git a/modules/unistdio/u16-vasnprintf b/modules/unistdio/u16-vasnprintf
index e767f54bd3..908f043a4e 100644
--- a/modules/unistdio/u16-vasnprintf
+++ b/modules/unistdio/u16-vasnprintf
@@ -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:
diff --git a/modules/unistdio/u32-u32-vasnprintf b/modules/unistdio/u32-u32-vasnprintf
index 86e669723b..e64e97d4dd 100644
--- a/modules/unistdio/u32-u32-vasnprintf
+++ b/modules/unistdio/u32-u32-vasnprintf
@@ -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:
diff --git a/modules/unistdio/u32-vasnprintf b/modules/unistdio/u32-vasnprintf
index 58185bc34b..8fb0187382 100644
--- a/modules/unistdio/u32-vasnprintf
+++ b/modules/unistdio/u32-vasnprintf
@@ -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:
diff --git a/modules/unistdio/u8-u8-vasnprintf b/modules/unistdio/u8-u8-vasnprintf
index 63ab8d8768..f91638bf83 100644
--- a/modules/unistdio/u8-u8-vasnprintf
+++ b/modules/unistdio/u8-u8-vasnprintf
@@ -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:
diff --git a/modules/unistdio/u8-vasnprintf b/modules/unistdio/u8-vasnprintf
index f6be0a5de3..f8d7e79d68 100644
--- a/modules/unistdio/u8-vasnprintf
+++ b/modules/unistdio/u8-vasnprintf
@@ -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:
diff --git a/modules/unistdio/ulc-vasnprintf b/modules/unistdio/ulc-vasnprintf
index 7f7614d8ac..c950cbf62a 100644
--- a/modules/unistdio/ulc-vasnprintf
+++ b/modules/unistdio/ulc-vasnprintf
@@ -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
index 0000000000..b5551f3011
--- /dev/null
+++ b/modules/vasnprintf-gnu
@@ -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