summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog43
-rw-r--r--doc/glibc-functions/asprintf.texi4
-rw-r--r--doc/glibc-functions/obstack_printf.texi4
-rw-r--r--doc/glibc-functions/obstack_vprintf.texi4
-rw-r--r--doc/glibc-functions/vasprintf.texi4
-rw-r--r--doc/posix-functions/dprintf.texi4
-rw-r--r--doc/posix-functions/fprintf.texi4
-rw-r--r--doc/posix-functions/printf.texi4
-rw-r--r--doc/posix-functions/snprintf.texi4
-rw-r--r--doc/posix-functions/sprintf.texi4
-rw-r--r--doc/posix-functions/vdprintf.texi4
-rw-r--r--doc/posix-functions/vfprintf.texi4
-rw-r--r--doc/posix-functions/vprintf.texi4
-rw-r--r--doc/posix-functions/vsnprintf.texi4
-rw-r--r--doc/posix-functions/vsprintf.texi4
-rw-r--r--lib/vasnprintf.c7
-rw-r--r--m4/dprintf-posix.m426
-rw-r--r--m4/fprintf-posix.m426
-rw-r--r--m4/obstack-printf-posix.m426
-rw-r--r--m4/printf.m4180
-rw-r--r--m4/snprintf-posix.m436
-rw-r--r--m4/sprintf-posix.m426
-rw-r--r--m4/vasnprintf-posix.m430
-rw-r--r--m4/vasnprintf.m418
-rw-r--r--m4/vasprintf-posix.m430
-rw-r--r--m4/vdprintf-posix.m426
-rw-r--r--m4/vfprintf-posix.m426
-rw-r--r--m4/vsnprintf-posix.m436
-rw-r--r--m4/vsprintf-posix.m426
-rw-r--r--tests/test-snprintf-posix.h35
-rw-r--r--tests/test-sprintf-posix.h31
-rw-r--r--tests/test-vasnprintf-posix.c41
-rw-r--r--tests/test-vasprintf-posix.c39
33 files changed, 572 insertions, 192 deletions
diff --git a/ChangeLog b/ChangeLog
index 1aeb66cdfd..8aad539d3e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,46 @@
+2023-03-21 Bruno Haible <bruno@clisp.org>
+
+ *printf-posix: Work around bug with %lc of 0 on many platforms.
+ * lib/vasnprintf.c (local_wctomb): Define also for
+ NEED_PRINTF_DIRECTIVE_LC.
+ (VASNPRINTF): Implement %lc handling ourselves if
+ NEED_PRINTF_DIRECTIVE_LC.
+ * m4/printf.m4 (gl_PRINTF_DIRECTIVE_LC): New macro.
+ * m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_DIRECTIVE_LC): New macro.
+ (gl_PREREQ_VASNPRINTF_WITH_EXTRAS): Invoke it.
+ * m4/dprintf-posix.m4 (gl_FUNC_DPRINTF_POSIX): Require
+ gl_PRINTF_DIRECTIVE_LC and test its result. Invoke
+ gl_PREREQ_VASNPRINTF_DIRECTIVE_LC.
+ * m4/fprintf-posix.m4 (gl_FUNC_FPRINTF_POSIX): Likewise.
+ * m4/obstack-printf-posix.m4 (gl_FUNC_OBSTACK_PRINTF_POSIX): Likewise.
+ * m4/snprintf-posix.m4 (gl_FUNC_SNPRINTF_POSIX): Likewise.
+ * m4/sprintf-posix.m4 (gl_FUNC_SPRINTF_POSIX): Likewise.
+ * m4/vasnprintf-posix.m4 (gl_FUNC_VASNPRINTF_POSIX): Likewise.
+ * m4/vasprintf-posix.m4 (gl_FUNC_VASPRINTF_POSIX): Likewise.
+ * m4/vdprintf-posix.m4 (gl_FUNC_VDPRINTF_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): Add more tests for the
+ %c and %lc directives.
+ * 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/glibc-functions/asprintf.texi: Mention the %lc 0 bug.
+ * doc/glibc-functions/obstack_printf.texi: Likewise.
+ * doc/glibc-functions/obstack_vprintf.texi: Likewise.
+ * doc/glibc-functions/vasprintf.texi: Likewise.
+ * doc/posix-functions/dprintf.texi: Likewise.
+ * doc/posix-functions/fprintf.texi: Likewise.
+ * doc/posix-functions/printf.texi: Likewise.
+ * doc/posix-functions/snprintf.texi: Likewise.
+ * doc/posix-functions/sprintf.texi: Likewise.
+ * doc/posix-functions/vdprintf.texi: Likewise.
+ * doc/posix-functions/vfprintf.texi: Likewise.
+ * doc/posix-functions/vprintf.texi: Likewise.
+ * doc/posix-functions/vsnprintf.texi: Likewise.
+ * doc/posix-functions/vsprintf.texi: Likewise.
+
2023-03-21 Ar Rakin <rakinar2@onesoftnet.eu.org> (tiny change)
gnupload: correct SFTP connection URL
diff --git a/doc/glibc-functions/asprintf.texi b/doc/glibc-functions/asprintf.texi
index 47708c40fb..70de08dd1c 100644
--- a/doc/glibc-functions/asprintf.texi
+++ b/doc/glibc-functions/asprintf.texi
@@ -71,6 +71,10 @@ printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded
with zeroes) on some platforms:
Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, Solaris 11.0, Cygwin 1.5.x.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@end itemize
diff --git a/doc/glibc-functions/obstack_printf.texi b/doc/glibc-functions/obstack_printf.texi
index 7feae78b36..8b13e1296e 100644
--- a/doc/glibc-functions/obstack_printf.texi
+++ b/doc/glibc-functions/obstack_printf.texi
@@ -77,6 +77,10 @@ This function does not support precisions larger than 512 or 1024 in integer,
floating-point and pointer output on some platforms:
Solaris 10/x86, mingw, MSVC/clang.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@item
diff --git a/doc/glibc-functions/obstack_vprintf.texi b/doc/glibc-functions/obstack_vprintf.texi
index cdded10221..2ea59ef4fa 100644
--- a/doc/glibc-functions/obstack_vprintf.texi
+++ b/doc/glibc-functions/obstack_vprintf.texi
@@ -77,6 +77,10 @@ This function does not support precisions larger than 512 or 1024 in integer,
floating-point and pointer output on some platforms:
Solaris 10/x86, mingw, MSVC/clang.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@item
diff --git a/doc/glibc-functions/vasprintf.texi b/doc/glibc-functions/vasprintf.texi
index 2f69df8e78..ef1be6bb88 100644
--- a/doc/glibc-functions/vasprintf.texi
+++ b/doc/glibc-functions/vasprintf.texi
@@ -71,6 +71,10 @@ printf @code{"%010f"} of NaN and Infinity yields an incorrect result (padded
with zeroes) on some platforms:
Mac OS X 10.5, FreeBSD 6.0, NetBSD 5.0, Solaris 11.0, Cygwin 1.5.x.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@end itemize
diff --git a/doc/posix-functions/dprintf.texi b/doc/posix-functions/dprintf.texi
index 7d5aeb9051..09e308c33b 100644
--- a/doc/posix-functions/dprintf.texi
+++ b/doc/posix-functions/dprintf.texi
@@ -44,6 +44,10 @@ Solaris 11.4.
This function does not support precisions larger than 512 or 1024 in integer,
floating-point and pointer output on some platforms:
AIX 7.1.
+@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-functions/fprintf.texi b/doc/posix-functions/fprintf.texi
index eedd9babbf..513777c0a4 100644
--- a/doc/posix-functions/fprintf.texi
+++ b/doc/posix-functions/fprintf.texi
@@ -69,6 +69,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@end itemize
diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi
index c32881c2cc..8a3971aa30 100644
--- a/doc/posix-functions/printf.texi
+++ b/doc/posix-functions/printf.texi
@@ -69,6 +69,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@end itemize
diff --git a/doc/posix-functions/snprintf.texi b/doc/posix-functions/snprintf.texi
index 6d8453b9fe..9ea76cfa8b 100644
--- a/doc/posix-functions/snprintf.texi
+++ b/doc/posix-functions/snprintf.texi
@@ -80,6 +80,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@item
diff --git a/doc/posix-functions/sprintf.texi b/doc/posix-functions/sprintf.texi
index 8974498ebf..57c42c294d 100644
--- a/doc/posix-functions/sprintf.texi
+++ b/doc/posix-functions/sprintf.texi
@@ -69,6 +69,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@item
diff --git a/doc/posix-functions/vdprintf.texi b/doc/posix-functions/vdprintf.texi
index d4de64ee25..d533d32892 100644
--- a/doc/posix-functions/vdprintf.texi
+++ b/doc/posix-functions/vdprintf.texi
@@ -44,6 +44,10 @@ Solaris 11.4.
This function does not support precisions larger than 512 or 1024 in integer,
floating-point and pointer output on some platforms:
AIX 7.1.
+@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
@end itemize
Portability problems not fixed by Gnulib:
diff --git a/doc/posix-functions/vfprintf.texi b/doc/posix-functions/vfprintf.texi
index f3ec56b5a6..252ac10e2b 100644
--- a/doc/posix-functions/vfprintf.texi
+++ b/doc/posix-functions/vfprintf.texi
@@ -69,6 +69,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@end itemize
diff --git a/doc/posix-functions/vprintf.texi b/doc/posix-functions/vprintf.texi
index 6e05d41002..8272e50fd9 100644
--- a/doc/posix-functions/vprintf.texi
+++ b/doc/posix-functions/vprintf.texi
@@ -69,6 +69,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@end itemize
diff --git a/doc/posix-functions/vsnprintf.texi b/doc/posix-functions/vsnprintf.texi
index 660ccfb1c3..3531644660 100644
--- a/doc/posix-functions/vsnprintf.texi
+++ b/doc/posix-functions/vsnprintf.texi
@@ -73,6 +73,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@item
diff --git a/doc/posix-functions/vsprintf.texi b/doc/posix-functions/vsprintf.texi
index 8af4bdf279..27ec5b9141 100644
--- a/doc/posix-functions/vsprintf.texi
+++ b/doc/posix-functions/vsprintf.texi
@@ -69,6 +69,10 @@ This function mishandles large floating point precisions
on some platforms:
Solaris 10.
@item
+This function produces wrong output for the @samp{lc} directive with a NUL
+wide character argument on some platforms:
+glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2, macOS 12.5, AIX 7.2, Solaris 11.4, and others.
+@item
This function can crash in out-of-memory conditions on some platforms:
FreeBSD 13.0, NetBSD 5.0.
@item
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 2150bead4d..0b349f4b55 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -289,7 +289,7 @@ local_wcsnlen (const wchar_t *s, size_t maxlen)
# endif
#endif
-#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T) || (ENABLE_WCHAR_FALLBACK && HAVE_WINT_T)) && !WIDE_CHAR_VERSION
+#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || USE_MSVC__SNPRINTF || NEED_PRINTF_DIRECTIVE_LS || ENABLE_WCHAR_FALLBACK) && HAVE_WCHAR_T) || ((NEED_PRINTF_DIRECTIVE_LC || ENABLE_WCHAR_FALLBACK) && HAVE_WINT_T)) && !WIDE_CHAR_VERSION
# if ENABLE_WCHAR_FALLBACK
static size_t
wctomb_fallback (char *s, wchar_t wc)
@@ -3017,12 +3017,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
# endif
}
#endif
-#if ENABLE_WCHAR_FALLBACK && HAVE_WINT_T && !WIDE_CHAR_VERSION
+#if (NEED_PRINTF_DIRECTIVE_LC || ENABLE_WCHAR_FALLBACK) && HAVE_WINT_T && !WIDE_CHAR_VERSION
else if (dp->conversion == 'c'
&& a.arg[dp->arg_index].type == TYPE_WIDE_CHAR)
{
/* Implement the 'lc' directive ourselves, in order to provide
- the fallback that avoids EILSEQ. */
+ a correct behaviour for the null wint_t argument and/or the
+ fallback that avoids EILSEQ. */
int flags = dp->flags;
int has_width;
size_t width;
diff --git a/m4/dprintf-posix.m4 b/m4/dprintf-posix.m4
index 4186ab70fe..eb8bd634f8 100644
--- a/m4/dprintf-posix.m4
+++ b/m4/dprintf-posix.m4
@@ -1,4 +1,4 @@
-# dprintf-posix.m4 serial 4
+# dprintf-posix.m4 serial 5
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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -42,21 +43,25 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- # dprintf exists and is
- # already POSIX compliant.
- gl_cv_func_dprintf_posix=yes
+ case "$gl_cv_func_printf_enomem" in
+ *yes)
+ # dprintf exists and is
+ # already POSIX compliant.
+ gl_cv_func_dprintf_posix=yes
+ ;;
+ esac
;;
esac
;;
@@ -96,6 +101,7 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX],
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
diff --git a/m4/fprintf-posix.m4 b/m4/fprintf-posix.m4
index 5602000e4a..1eb669fd5d 100644
--- a/m4/fprintf-posix.m4
+++ b/m4/fprintf-posix.m4
@@ -1,4 +1,4 @@
-# fprintf-posix.m4 serial 15
+# fprintf-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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -40,21 +41,25 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- # fprintf exists and is
- # already POSIX compliant.
- gl_cv_func_fprintf_posix=yes
+ case "$gl_cv_func_printf_enomem" in
+ *yes)
+ # fprintf exists and is
+ # already POSIX compliant.
+ gl_cv_func_fprintf_posix=yes
+ ;;
+ esac
;;
esac
;;
@@ -93,6 +98,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX],
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
diff --git a/m4/obstack-printf-posix.m4 b/m4/obstack-printf-posix.m4
index 633b017442..8092119906 100644
--- a/m4/obstack-printf-posix.m4
+++ b/m4/obstack-printf-posix.m4
@@ -1,4 +1,4 @@
-# obstack-printf-posix.m4 serial 5
+# obstack-printf-posix.m4 serial 6
dnl Copyright (C) 2008-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,
@@ -18,6 +18,7 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -45,21 +46,25 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- # obstack_printf exists and is
- # already POSIX compliant.
- gl_cv_func_obstack_printf_posix=yes
+ case "$gl_cv_func_printf_enomem" in
+ *yes)
+ # obstack_printf exists and is
+ # already POSIX compliant.
+ gl_cv_func_obstack_printf_posix=yes
+ ;;
+ esac
;;
esac
;;
@@ -99,6 +104,7 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX],
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
diff --git a/m4/printf.m4 b/m4/printf.m4
index 719679c362..1096b87dc2 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 75
+# printf.m4 serial 76
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,
@@ -873,6 +873,53 @@ changequote([,])dnl
])
])
+dnl Test whether the *printf family of functions supports the %lc format
+dnl directive and in particular, when the argument is a null wide character,
+dnl whether the functions don't produce a NUL byte.
+dnl Result is gl_cv_func_printf_directive_lc.
+
+AC_DEFUN([gl_PRINTF_DIRECTIVE_LC],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+ AC_CACHE_CHECK([whether printf supports the 'lc' directive correctly],
+ [gl_cv_func_printf_directive_lc],
+ [
+ AC_RUN_IFELSE(
+ [AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <wchar.h>
+#include <string.h>
+int main ()
+{
+ int result = 0;
+ char buf[100];
+ /* This test fails on glibc 2.35, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+ macOS 12.5, AIX 7.2, Solaris 11.4.
+ glibc 2.35 bug: <https://sourceware.org/bugzilla/show_bug.cgi?id=30257> */
+ {
+ buf[0] = '\0';
+ if (sprintf (buf, "%lc%lc%lc", (wint_t) 'a', (wint_t) 0, (wint_t) 'z') < 0
+ || strcmp (buf, "az") != 0)
+ result |= 1;
+ }
+ return result;
+}]])],
+ [gl_cv_func_printf_directive_lc=yes],
+ [gl_cv_func_printf_directive_lc=no],
+ [
+changequote(,)dnl
+ case "$host_os" in
+ # Guess yes on musl libc.
+ *-musl* | midipix*) gl_cv_func_printf_directive_lc="guessing yes";;
+ # Guess no otherwise.
+ *) gl_cv_func_printf_directive_lc="guessing no";;
+ esac
+changequote([,])dnl
+ ])
+ ])
+])
+
dnl Test whether the *printf family of functions supports POSIX/XSI format
dnl strings with positions. (POSIX:2001)
dnl Result is gl_cv_func_printf_positions.
@@ -1696,18 +1743,19 @@ 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_POSITIONS
-dnl 11 = gl_PRINTF_FLAG_GROUPING
-dnl 12 = gl_PRINTF_FLAG_LEFTADJUST
-dnl 13 = gl_PRINTF_FLAG_ZERO
-dnl 14 = gl_PRINTF_PRECISION
-dnl 15 = gl_PRINTF_ENOMEM
-dnl 16 = gl_SNPRINTF_PRESENCE
-dnl 17 = gl_SNPRINTF_TRUNCATION_C99
-dnl 18 = gl_SNPRINTF_RETVAL_C99
-dnl 19 = gl_SNPRINTF_DIRECTIVE_N
-dnl 20 = gl_SNPRINTF_SIZE1
-dnl 21 = gl_VSNPRINTF_ZEROSIZE_C99
+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
dnl 1 = checking whether printf supports size specifiers as in C99...
dnl 2 = checking whether printf supports 'long double' arguments...
@@ -1718,57 +1766,61 @@ 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 POSIX/XSI format strings with positions...
-dnl 11 = checking whether printf supports the grouping flag...
-dnl 12 = checking whether printf supports the left-adjust flag correctly...
-dnl 13 = checking whether printf supports the zero flag correctly...
-dnl 14 = checking whether printf supports large precisions...
-dnl 15 = checking whether printf survives out-of-memory conditions...
-dnl 16 = checking for snprintf...
-dnl 17 = checking whether snprintf truncates the result as in C99...
-dnl 18 = checking whether snprintf returns a byte count as in C99...
-dnl 19 = checking whether snprintf fully supports the 'n' directive...
-dnl 20 = checking whether snprintf respects a size of 1...
-dnl 21 = checking whether vsnprintf respects a zero size as in C99...
+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
dnl . = yes, # = no.
+checking whether snprintf truncates the result as in C99... yes
dnl
-dnl 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
-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
+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/snprintf-posix.m4 b/m4/snprintf-posix.m4
index 033e1916e5..1a0147f3b6 100644
--- a/m4/snprintf-posix.m4
+++ b/m4/snprintf-posix.m4
@@ -1,4 +1,4 @@
-# snprintf-posix.m4 serial 15
+# snprintf-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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -47,31 +48,35 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- case "$gl_cv_func_snprintf_truncation_c99" in
+ case "$gl_cv_func_printf_enomem" 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_snprintf_size1" in
+ case "$gl_cv_func_snprintf_directive_n" in
*yes)
- case "$gl_cv_func_vsnprintf_zerosize_c99" in
+ case "$gl_cv_func_snprintf_size1" 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
;;
@@ -121,6 +126,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX],
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
diff --git a/m4/sprintf-posix.m4 b/m4/sprintf-posix.m4
index cfcbe37cce..96d0e0dacc 100644
--- a/m4/sprintf-posix.m4
+++ b/m4/sprintf-posix.m4
@@ -1,4 +1,4 @@
-# sprintf-posix.m4 serial 13
+# sprintf-posix.m4 serial 14
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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -40,21 +41,25 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- # sprintf exists and is
- # already POSIX compliant.
- gl_cv_func_sprintf_posix=yes
+ case "$gl_cv_func_printf_enomem" in
+ *yes)
+ # sprintf exists and is
+ # already POSIX compliant.
+ gl_cv_func_sprintf_posix=yes
+ ;;
+ esac
;;
esac
;;
@@ -93,6 +98,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX],
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
diff --git a/m4/vasnprintf-posix.m4 b/m4/vasnprintf-posix.m4
index 4983dfc50a..d061d3136e 100644
--- a/m4/vasnprintf-posix.m4
+++ b/m4/vasnprintf-posix.m4
@@ -1,4 +1,4 @@
-# vasnprintf-posix.m4 serial 14
+# vasnprintf-posix.m4 serial 15
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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -41,23 +42,27 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" 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_enomem" 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
;;
@@ -96,6 +101,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX],
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
diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4
index f807e4771f..26ed82a731 100644
--- a/m4/vasnprintf.m4
+++ b/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 43
+# vasnprintf.m4 serial 44
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,
@@ -228,6 +228,21 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LS],
esac
])
+# Extra prerequisites of lib/vasnprintf.c for supporting the 'lc' directive.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_LC],
+[
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
+ case "$gl_cv_func_printf_directive_lc" in
+ *yes)
+ ;;
+ *)
+ AC_DEFINE([NEED_PRINTF_DIRECTIVE_LC], [1],
+ [Define if the vasnprintf implementation needs special code for
+ the 'lc' directive.])
+ ;;
+ esac
+])
+
# Extra prerequisites of lib/vasnprintf.c for supporting the ' flag.
AC_DEFUN([gl_PREREQ_VASNPRINTF_FLAG_GROUPING],
[
@@ -327,6 +342,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS],
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
diff --git a/m4/vasprintf-posix.m4 b/m4/vasprintf-posix.m4
index 1537ad52d9..aa879de711 100644
--- a/m4/vasprintf-posix.m4
+++ b/m4/vasprintf-posix.m4
@@ -1,4 +1,4 @@
-# vasprintf-posix.m4 serial 14
+# vasprintf-posix.m4 serial 15
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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -41,23 +42,27 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" 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_enomem" 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
;;
@@ -96,6 +101,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX],
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
diff --git a/m4/vdprintf-posix.m4 b/m4/vdprintf-posix.m4
index eb9ab8c679..ff74fdaab4 100644
--- a/m4/vdprintf-posix.m4
+++ b/m4/vdprintf-posix.m4
@@ -1,4 +1,4 @@
-# vdprintf-posix.m4 serial 4
+# vdprintf-posix.m4 serial 5
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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -42,21 +43,25 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- # vdprintf exists and is
- # already POSIX compliant.
- gl_cv_func_vdprintf_posix=yes
+ case "$gl_cv_func_printf_enomem" in
+ *yes)
+ # vdprintf exists and is
+ # already POSIX compliant.
+ gl_cv_func_vdprintf_posix=yes
+ ;;
+ esac
;;
esac
;;
@@ -96,6 +101,7 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX],
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
diff --git a/m4/vfprintf-posix.m4 b/m4/vfprintf-posix.m4
index 17a8bad843..f248292cc4 100644
--- a/m4/vfprintf-posix.m4
+++ b/m4/vfprintf-posix.m4
@@ -1,4 +1,4 @@
-# vfprintf-posix.m4 serial 15
+# vfprintf-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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -40,21 +41,25 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- # vfprintf exists and is
- # already POSIX compliant.
- gl_cv_func_vfprintf_posix=yes
+ case "$gl_cv_func_printf_enomem" in
+ *yes)
+ # vfprintf exists and is
+ # already POSIX compliant.
+ gl_cv_func_vfprintf_posix=yes
+ ;;
+ esac
;;
esac
;;
@@ -93,6 +98,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX],
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
diff --git a/m4/vsnprintf-posix.m4 b/m4/vsnprintf-posix.m4
index 65805522d4..d1e1933aa3 100644
--- a/m4/vsnprintf-posix.m4
+++ b/m4/vsnprintf-posix.m4
@@ -1,4 +1,4 @@
-# vsnprintf-posix.m4 serial 16
+# vsnprintf-posix.m4 serial 17
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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -48,31 +49,35 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- case "$gl_cv_func_snprintf_truncation_c99" in
+ case "$gl_cv_func_printf_enomem" 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_snprintf_size1" in
+ case "$gl_cv_func_snprintf_directive_n" in
*yes)
- case "$gl_cv_func_vsnprintf_zerosize_c99" in
+ case "$gl_cv_func_snprintf_size1" 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
;;
@@ -122,6 +127,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX],
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
diff --git a/m4/vsprintf-posix.m4 b/m4/vsprintf-posix.m4
index 716f58f761..94ef61e9dd 100644
--- a/m4/vsprintf-posix.m4
+++ b/m4/vsprintf-posix.m4
@@ -1,4 +1,4 @@
-# vsprintf-posix.m4 serial 13
+# vsprintf-posix.m4 serial 14
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,
@@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX],
AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
+ AC_REQUIRE([gl_PRINTF_DIRECTIVE_LC])
AC_REQUIRE([gl_PRINTF_POSITIONS])
AC_REQUIRE([gl_PRINTF_FLAG_GROUPING])
AC_REQUIRE([gl_PRINTF_FLAG_LEFTADJUST])
@@ -40,21 +41,25 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX],
*yes)
case "$gl_cv_func_printf_directive_ls" in
*yes)
- case "$gl_cv_func_printf_positions" in
+ case "$gl_cv_func_printf_directive_lc" in
*yes)
- case "$gl_cv_func_printf_flag_grouping" in
+ case "$gl_cv_func_printf_positions" in
*yes)
- case "$gl_cv_func_printf_flag_leftadjust" in
+ case "$gl_cv_func_printf_flag_grouping" in
*yes)
- case "$gl_cv_func_printf_flag_zero" in
+ case "$gl_cv_func_printf_flag_leftadjust" in
*yes)
- case "$gl_cv_func_printf_precision" in
+ case "$gl_cv_func_printf_flag_zero" in
*yes)
- case "$gl_cv_func_printf_enomem" in
+ case "$gl_cv_func_printf_precision" in
*yes)
- # vsprintf exists and is
- # already POSIX compliant.
- gl_cv_func_vsprintf_posix=yes
+ case "$gl_cv_func_printf_enomem" in
+ *yes)
+ # vsprintf exists and is
+ # already POSIX compliant.
+ gl_cv_func_vsprintf_posix=yes
+ ;;
+ esac
;;
esac
;;
@@ -93,6 +98,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX],
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
diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h
index 579d34583d..05c7be8059 100644
--- a/tests/test-snprintf-posix.h
+++ b/tests/test-snprintf-posix.h
@@ -3024,6 +3024,22 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
ASSERT (retval == strlen (result));
}
+ { /* Precision is ignored. */
+ int retval =
+ my_snprintf (result, sizeof (result),
+ "%.0c %d", (unsigned char) 'x', 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (retval == strlen (result));
+ }
+
+ { /* NUL character. */
+ int retval =
+ my_snprintf (result, sizeof (result),
+ "a%cz %d", '\0', 33, 44, 55);
+ ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0);
+ ASSERT (retval == 6);
+ }
+
#if HAVE_WCHAR_T
static wint_t L_x = (wchar_t) 'x';
@@ -3054,6 +3070,25 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
ASSERT (strcmp (result, "x 33") == 0);
ASSERT (retval == strlen (result));
}
+
+ { /* Precision is ignored. */
+ int retval =
+ my_snprintf (result, sizeof (result),
+ "%.0lc %d", L_x, 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (retval == strlen (result));
+ }
+
+ { /* NUL character. */
+ int retval =
+ my_snprintf (result, sizeof (result),
+ "a%lcz %d", (wint_t) L'\0', 33, 44, 55);
+ /* No NUL byte between 'a' and 'z'. This is surprising, but is a
+ consequence of how POSIX:2018 and ISO C 23 specify the handling
+ of %lc. */
+ ASSERT (memcmp (result, "az 33\0", 5 + 1) == 0);
+ ASSERT (retval == 5);
+ }
#endif
/* Test the support of the 'b' conversion specifier for binary output of
diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h
index 863d084b99..d745a1109b 100644
--- a/tests/test-sprintf-posix.h
+++ b/tests/test-sprintf-posix.h
@@ -3006,6 +3006,20 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
ASSERT (retval == strlen (result));
}
+ { /* Precision is ignored. */
+ int retval =
+ my_sprintf (result, "%.0c %d", (unsigned char) 'x', 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (retval == strlen (result));
+ }
+
+ { /* NUL character. */
+ int retval =
+ my_sprintf (result, "a%cz %d", '\0', 33, 44, 55);
+ ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0);
+ ASSERT (retval == 6);
+ }
+
#if HAVE_WCHAR_T
static wint_t L_x = (wchar_t) 'x';
@@ -3036,6 +3050,23 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
ASSERT (strcmp (result, "x 33") == 0);
ASSERT (retval == strlen (result));
}
+
+ { /* Precision is ignored. */
+ int retval =
+ my_sprintf (result, "%.0lc %d", L_x, 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (retval == strlen (result));
+ }
+
+ { /* NUL character. */
+ int retval =
+ my_sprintf (result, "a%lcz %d", (wint_t) L'\0', 33, 44, 55);
+ /* No NUL byte between 'a' and 'z'. This is surprising, but is a
+ consequence of how POSIX:2018 and ISO C 23 specify the handling
+ of %lc. */
+ ASSERT (memcmp (result, "az 33\0", 5 + 1) == 0);
+ ASSERT (retval == 5);
+ }
#endif
/* Test the support of the 'b' conversion specifier for binary output of
diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c
index c6e1e2f650..ecbb8bcda0 100644
--- a/tests/test-vasnprintf-posix.c
+++ b/tests/test-vasnprintf-posix.c
@@ -3932,6 +3932,26 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
free (result);
}
+ { /* Precision is ignored. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length,
+ "%.0c %d", (unsigned char) 'x', 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+
+ { /* NUL character. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length,
+ "a%cz %d", '\0', 33, 44, 55);
+ ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0);
+ ASSERT (length == 6);
+ free (result);
+ }
+
#if HAVE_WCHAR_T
static wint_t L_x = (wchar_t) 'x';
@@ -3974,6 +3994,27 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
ASSERT (length == strlen (result));
free (result);
}
+
+ { /* Precision is ignored. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%.0lc %d", L_x, 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+
+ { /* NUL character. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "a%lcz %d", (wint_t) L'\0', 33, 44, 55);
+ /* No NUL byte between 'a' and 'z'. This is surprising, but is a
+ consequence of how POSIX:2018 and ISO C 23 specify the handling
+ of %lc. */
+ ASSERT (memcmp (result, "az 33\0", 5 + 1) == 0);
+ ASSERT (length == 5);
+ free (result);
+ }
#endif
/* Test the support of the 'b' conversion specifier for binary output of
diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c
index 13b3a1bca9..46086ef251 100644
--- a/tests/test-vasprintf-posix.c
+++ b/tests/test-vasprintf-posix.c
@@ -3873,6 +3873,24 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
free (result);
}
+ { /* Precision is ignored. */
+ char *result;
+ int retval =
+ my_asprintf (&result, "%.0c %d", (unsigned char) 'x', 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (retval == strlen (result));
+ free (result);
+ }
+
+ { /* NUL character. */
+ char *result;
+ int retval =
+ my_asprintf (&result, "a%cz %d", '\0', 33, 44, 55);
+ ASSERT (memcmp (result, "a\0z 33\0", 6 + 1) == 0);
+ ASSERT (retval == 6);
+ free (result);
+ }
+
#if HAVE_WCHAR_T
static wint_t L_x = (wchar_t) 'x';
@@ -3915,6 +3933,27 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
ASSERT (retval == strlen (result));
free (result);
}
+
+ { /* Precision is ignored. */
+ char *result;
+ int retval =
+ my_asprintf (&result, "%.0lc %d", L_x, 33, 44, 55);
+ ASSERT (strcmp (result, "x 33") == 0);
+ ASSERT (retval == strlen (result));
+ free (result);
+ }
+
+ { /* NUL character. */
+ char *result;
+ int retval =
+ my_asprintf (&result, "a%lcz %d", (wint_t) L'\0', 33, 44, 55);
+ /* No NUL byte between 'a' and 'z'. This is surprising, but is a
+ consequence of how POSIX:2018 and ISO C 23 specify the handling
+ of %lc. */
+ ASSERT (memcmp (result, "az 33\0", 5 + 1) == 0);
+ ASSERT (retval == 5);
+ free (result);
+ }
#endif
/* Test the support of the 'b' conversion specifier for binary output of