This set of patches adds support for the %b format string directive, required
by ISO C 23, to the *printf family of functions.

So far, only glibc implements it (since version 2.35). For portability to the
other platforms, use the *printf-posix modules.


2023-03-17  Bruno Haible  <br...@clisp.org>

        *printf-posix: ISO C 23: Add %b directive for binary output of integers.
        * lib/printf-parse.c (PRINTF_PARSE): Recognize the 'b' directive.
        * lib/printf-parse.h: Update comment.
        * lib/wprintf-parse.h: Likewise.
        * lib/vasnprintf.c (MAX_ROOM_NEEDED, VASNPRINTF): Add support for the
        'b' directive.
        * m4/printf.m4 (gl_PRINTF_DIRECTIVE_B): New macro.
        * m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_DIRECTIVE_B): New macro.
        (gl_PREREQ_VASNPRINTF_WITH_EXTRAS): Invoke it.
        * m4/vasnwprintf-posix.m4 (gl_FUNC_VASNWPRINTF_POSIX): Invoke
        gl_PREREQ_VASNPRINTF_DIRECTIVE_B.
        * m4/dprintf-posix.m4 (gl_FUNC_DPRINTF_POSIX): Require
        gl_PRINTF_DIRECTIVE_B and test its result. Invoke
        gl_PREREQ_VASNPRINTF_DIRECTIVE_B.
        * 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 some tests of the %b
        directive.
        * tests/test-sprintf-posix.h (test_function): Likewise.
        * tests/test-vasnprintf-posix.c (test_function): Likewise.
        * tests/test-vasnwprintf-posix.c (test_function): Likewise.
        * tests/test-vasprintf-posix.c (test_function): Likewise.
        * doc/glibc-functions/asprintf.texi: Mention the 'b' directive.
        * 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/fwprintf.texi: Likewise.
        * doc/posix-functions/printf.texi: Likewise.
        * doc/posix-functions/snprintf.texi: Likewise.
        * doc/posix-functions/sprintf.texi: Likewise.
        * doc/posix-functions/swprintf.texi: Likewise.
        * doc/posix-functions/vdprintf.texi: Likewise.
        * doc/posix-functions/vfprintf.texi: Likewise.
        * doc/posix-functions/vfwprintf.texi: Likewise.
        * doc/posix-functions/vprintf.texi: Likewise.
        * doc/posix-functions/vsnprintf.texi: Likewise.
        * doc/posix-functions/vsprintf.texi: Likewise.
        * doc/posix-functions/vswprintf.texi: Likewise.
        * doc/posix-functions/vwprintf.texi: Likewise.
        * doc/posix-functions/wprintf.texi: Likewise.

2023-03-17  Bruno Haible  <br...@clisp.org>

        vasnprintf, vasnwprintf: Simplify code.
        * lib/vasnprintf.c (MAX_ROOM_NEEDED): Remove dead code: The directives
        'o', 'x', 'X' always take an unsigned integer argument.

>From 21ed6e8365e371b9088df727d0449133df58e9bc Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 17 Mar 2023 22:33:24 +0100
Subject: [PATCH 1/2] vasnprintf, vasnwprintf: Simplify code.

* lib/vasnprintf.c (MAX_ROOM_NEEDED): Remove dead code: The directives
'o', 'x', 'X' always take an unsigned integer argument.
---
 ChangeLog        |  6 ++++++
 lib/vasnprintf.c | 10 +++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8318d7f6fc..62dd39e17f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2023-03-17  Bruno Haible  <br...@clisp.org>
+
+	vasnprintf, vasnwprintf: Simplify code.
+	* lib/vasnprintf.c (MAX_ROOM_NEEDED): Remove dead code: The directives
+	'o', 'x', 'X' always take an unsigned integer argument.
+
 2023-03-17  Bruno Haible  <br...@clisp.org>
 
 	vasnwprintf: Fix test failure on OpenBSD.
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 74a6712926..a49eb1dcd7 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1654,13 +1654,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
       break;
 
     case 'o':
-      if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+      if (type == TYPE_ULONGLONGINT)
         tmp_length =
           (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
                           * 0.333334 /* binary -> octal */
                          )
           + 1; /* turn floor into ceil */
-      else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+      else if (type == TYPE_ULONGINT)
         tmp_length =
           (unsigned int) (sizeof (unsigned long) * CHAR_BIT
                           * 0.333334 /* binary -> octal */
@@ -1679,13 +1679,13 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
       break;
 
     case 'x': case 'X':
-      if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT)
+      if (type == TYPE_ULONGLONGINT)
         tmp_length =
           (unsigned int) (sizeof (unsigned long long) * CHAR_BIT
                           * 0.25 /* binary -> hexadecimal */
                          )
           + 1; /* turn floor into ceil */
-      else if (type == TYPE_LONGINT || type == TYPE_ULONGINT)
+      else if (type == TYPE_ULONGINT)
         tmp_length =
           (unsigned int) (sizeof (unsigned long) * CHAR_BIT
                           * 0.25 /* binary -> hexadecimal */
@@ -1699,7 +1699,7 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
           + 1; /* turn floor into ceil */
       if (tmp_length < precision)
         tmp_length = precision;
-      /* Add 2, to account for a leading sign or alternate form.  */
+      /* Add 2, to account for a prefix from the alternate form.  */
       tmp_length = xsum (tmp_length, 2);
       break;
 
-- 
2.34.1

>From bb7cf2b64d2caf381249dda65ee0fe6766d9b3c6 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 17 Mar 2023 22:45:56 +0100
Subject: [PATCH 2/2] *printf-posix: ISO C 23: Add %b directive for binary
 output of integers.

* lib/printf-parse.c (PRINTF_PARSE): Recognize the 'b' directive.
* lib/printf-parse.h: Update comment.
* lib/wprintf-parse.h: Likewise.
* lib/vasnprintf.c (MAX_ROOM_NEEDED, VASNPRINTF): Add support for the
'b' directive.
* m4/printf.m4 (gl_PRINTF_DIRECTIVE_B): New macro.
* m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_DIRECTIVE_B): New macro.
(gl_PREREQ_VASNPRINTF_WITH_EXTRAS): Invoke it.
* m4/vasnwprintf-posix.m4 (gl_FUNC_VASNWPRINTF_POSIX): Invoke
gl_PREREQ_VASNPRINTF_DIRECTIVE_B.
* m4/dprintf-posix.m4 (gl_FUNC_DPRINTF_POSIX): Require
gl_PRINTF_DIRECTIVE_B and test its result. Invoke
gl_PREREQ_VASNPRINTF_DIRECTIVE_B.
* 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 some tests of the %b
directive.
* tests/test-sprintf-posix.h (test_function): Likewise.
* tests/test-vasnprintf-posix.c (test_function): Likewise.
* tests/test-vasnwprintf-posix.c (test_function): Likewise.
* tests/test-vasprintf-posix.c (test_function): Likewise.
* doc/glibc-functions/asprintf.texi: Mention the 'b' directive.
* 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/fwprintf.texi: Likewise.
* doc/posix-functions/printf.texi: Likewise.
* doc/posix-functions/snprintf.texi: Likewise.
* doc/posix-functions/sprintf.texi: Likewise.
* doc/posix-functions/swprintf.texi: Likewise.
* doc/posix-functions/vdprintf.texi: Likewise.
* doc/posix-functions/vfprintf.texi: Likewise.
* doc/posix-functions/vfwprintf.texi: Likewise.
* doc/posix-functions/vprintf.texi: Likewise.
* doc/posix-functions/vsnprintf.texi: Likewise.
* doc/posix-functions/vsprintf.texi: Likewise.
* doc/posix-functions/vswprintf.texi: Likewise.
* doc/posix-functions/vwprintf.texi: Likewise.
* doc/posix-functions/wprintf.texi: Likewise.
---
 ChangeLog                                |  53 ++++++
 doc/glibc-functions/asprintf.texi        |   5 +
 doc/glibc-functions/obstack_printf.texi  |   5 +
 doc/glibc-functions/obstack_vprintf.texi |   5 +
 doc/glibc-functions/vasprintf.texi       |   5 +
 doc/posix-functions/dprintf.texi         |   5 +
 doc/posix-functions/fprintf.texi         |   5 +
 doc/posix-functions/fwprintf.texi        |  13 +-
 doc/posix-functions/printf.texi          |   5 +
 doc/posix-functions/snprintf.texi        |   5 +
 doc/posix-functions/sprintf.texi         |   5 +
 doc/posix-functions/swprintf.texi        |  13 +-
 doc/posix-functions/vdprintf.texi        |   5 +
 doc/posix-functions/vfprintf.texi        |   5 +
 doc/posix-functions/vfwprintf.texi       |  13 +-
 doc/posix-functions/vprintf.texi         |   5 +
 doc/posix-functions/vsnprintf.texi       |   5 +
 doc/posix-functions/vsprintf.texi        |   5 +
 doc/posix-functions/vswprintf.texi       |  13 +-
 doc/posix-functions/vwprintf.texi        |  13 +-
 doc/posix-functions/wprintf.texi         |  13 +-
 lib/printf-parse.c                       |   2 +-
 lib/printf-parse.h                       |   2 +-
 lib/vasnprintf.c                         | 213 +++++++++++++++++++++++
 lib/wprintf-parse.h                      |   2 +-
 m4/dprintf-posix.m4                      |  32 ++--
 m4/fprintf-posix.m4                      |  32 ++--
 m4/obstack-printf-posix.m4               |  32 ++--
 m4/printf.m4                             | 186 ++++++++++++--------
 m4/snprintf-posix.m4                     |  42 +++--
 m4/sprintf-posix.m4                      |  32 ++--
 m4/vasnprintf-posix.m4                   |  36 ++--
 m4/vasnprintf.m4                         |  18 +-
 m4/vasnwprintf-posix.m4                  |   3 +-
 m4/vasprintf-posix.m4                    |  36 ++--
 m4/vdprintf-posix.m4                     |  32 ++--
 m4/vfprintf-posix.m4                     |  32 ++--
 m4/vsnprintf-posix.m4                    |  42 +++--
 m4/vsprintf-posix.m4                     |  32 ++--
 tests/test-snprintf-posix.h              |  68 ++++++++
 tests/test-sprintf-posix.h               |  68 ++++++++
 tests/test-vasnprintf-posix.c            |  93 ++++++++++
 tests/test-vasnwprintf-posix.c           |  93 ++++++++++
 tests/test-vasprintf-posix.c             |  93 ++++++++++
 44 files changed, 1166 insertions(+), 256 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 62dd39e17f..173cd45bff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,56 @@
+2023-03-17  Bruno Haible  <br...@clisp.org>
+
+	*printf-posix: ISO C 23: Add %b directive for binary output of integers.
+	* lib/printf-parse.c (PRINTF_PARSE): Recognize the 'b' directive.
+	* lib/printf-parse.h: Update comment.
+	* lib/wprintf-parse.h: Likewise.
+	* lib/vasnprintf.c (MAX_ROOM_NEEDED, VASNPRINTF): Add support for the
+	'b' directive.
+	* m4/printf.m4 (gl_PRINTF_DIRECTIVE_B): New macro.
+	* m4/vasnprintf.m4 (gl_PREREQ_VASNPRINTF_DIRECTIVE_B): New macro.
+	(gl_PREREQ_VASNPRINTF_WITH_EXTRAS): Invoke it.
+	* m4/vasnwprintf-posix.m4 (gl_FUNC_VASNWPRINTF_POSIX): Invoke
+	gl_PREREQ_VASNPRINTF_DIRECTIVE_B.
+	* m4/dprintf-posix.m4 (gl_FUNC_DPRINTF_POSIX): Require
+	gl_PRINTF_DIRECTIVE_B and test its result. Invoke
+	gl_PREREQ_VASNPRINTF_DIRECTIVE_B.
+	* 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 some tests of the %b
+	directive.
+	* tests/test-sprintf-posix.h (test_function): Likewise.
+	* tests/test-vasnprintf-posix.c (test_function): Likewise.
+	* tests/test-vasnwprintf-posix.c (test_function): Likewise.
+	* tests/test-vasprintf-posix.c (test_function): Likewise.
+	* doc/glibc-functions/asprintf.texi: Mention the 'b' directive.
+	* 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/fwprintf.texi: Likewise.
+	* doc/posix-functions/printf.texi: Likewise.
+	* doc/posix-functions/snprintf.texi: Likewise.
+	* doc/posix-functions/sprintf.texi: Likewise.
+	* doc/posix-functions/swprintf.texi: Likewise.
+	* doc/posix-functions/vdprintf.texi: Likewise.
+	* doc/posix-functions/vfprintf.texi: Likewise.
+	* doc/posix-functions/vfwprintf.texi: Likewise.
+	* doc/posix-functions/vprintf.texi: Likewise.
+	* doc/posix-functions/vsnprintf.texi: Likewise.
+	* doc/posix-functions/vsprintf.texi: Likewise.
+	* doc/posix-functions/vswprintf.texi: Likewise.
+	* doc/posix-functions/vwprintf.texi: Likewise.
+	* doc/posix-functions/wprintf.texi: Likewise.
+
 2023-03-17  Bruno Haible  <br...@clisp.org>
 
 	vasnprintf, vasnwprintf: Simplify code.
diff --git a/doc/glibc-functions/asprintf.texi b/doc/glibc-functions/asprintf.texi
index 93d092d795..47708c40fb 100644
--- a/doc/glibc-functions/asprintf.texi
+++ b/doc/glibc-functions/asprintf.texi
@@ -41,6 +41,11 @@
 platforms:
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, Solaris 11.4, Cygwin 1.5.x.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, Solaris 11.4, Cygwin 2.9.0.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, Cygwin 1.5.x.
 @item
diff --git a/doc/glibc-functions/obstack_printf.texi b/doc/glibc-functions/obstack_printf.texi
index b417486e7f..7feae78b36 100644
--- a/doc/glibc-functions/obstack_printf.texi
+++ b/doc/glibc-functions/obstack_printf.texi
@@ -39,6 +39,11 @@
 glibc-2.3.6, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/glibc-functions/obstack_vprintf.texi b/doc/glibc-functions/obstack_vprintf.texi
index a4d6242704..cdded10221 100644
--- a/doc/glibc-functions/obstack_vprintf.texi
+++ b/doc/glibc-functions/obstack_vprintf.texi
@@ -39,6 +39,11 @@
 glibc-2.3.6, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/glibc-functions/vasprintf.texi b/doc/glibc-functions/vasprintf.texi
index 2ba5405558..2f69df8e78 100644
--- a/doc/glibc-functions/vasprintf.texi
+++ b/doc/glibc-functions/vasprintf.texi
@@ -41,6 +41,11 @@
 platforms:
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, Solaris 11.4, Cygwin 1.5.x.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, Solaris 11.4, Cygwin 2.9.0.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, Cygwin 1.5.x.
 @item
diff --git a/doc/posix-functions/dprintf.texi b/doc/posix-functions/dprintf.texi
index 51428d036f..7d5aeb9051 100644
--- a/doc/posix-functions/dprintf.texi
+++ b/doc/posix-functions/dprintf.texi
@@ -24,6 +24,11 @@
 platforms:
 glibc-2.3.6, Solaris 11.4.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, Solaris 11.4, Cygwin 2.9.0.
+@item
 This function does not support the @samp{n} directive on some platforms:
 glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 macOS 11.1.
diff --git a/doc/posix-functions/fprintf.texi b/doc/posix-functions/fprintf.texi
index 18c4e0549d..eedd9babbf 100644
--- a/doc/posix-functions/fprintf.texi
+++ b/doc/posix-functions/fprintf.texi
@@ -25,6 +25,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/fwprintf.texi b/doc/posix-functions/fwprintf.texi
index 1bd4f3d4b8..b9ce2eb024 100644
--- a/doc/posix-functions/fwprintf.texi
+++ b/doc/posix-functions/fwprintf.texi
@@ -13,16 +13,21 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-The @code{%m} directive is not portable, use @code{%s} mapped to an
-argument of @code{strerror(errno)} (or a version of @code{strerror_r})
-instead.
-@item
 This function is missing on some platforms:
 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11.00, IRIX 6.5, Cygwin 1.5.x.
 @item
 On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
+The @code{%m} directive is not portable, use @code{%s} mapped to an
+argument of @code{strerror(errno)} (or a version of @code{strerror_r})
+instead.
+@item
 When formatting an integer with grouping flag, this function inserts thousands
 separators even in the "C" locale on some platforms:
 NetBSD 5.1.
diff --git a/doc/posix-functions/printf.texi b/doc/posix-functions/printf.texi
index 6fab46033e..c32881c2cc 100644
--- a/doc/posix-functions/printf.texi
+++ b/doc/posix-functions/printf.texi
@@ -25,6 +25,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/snprintf.texi b/doc/posix-functions/snprintf.texi
index 13d63acac7..6d8453b9fe 100644
--- a/doc/posix-functions/snprintf.texi
+++ b/doc/posix-functions/snprintf.texi
@@ -40,6 +40,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/sprintf.texi b/doc/posix-functions/sprintf.texi
index 0ced69dc57..8974498ebf 100644
--- a/doc/posix-functions/sprintf.texi
+++ b/doc/posix-functions/sprintf.texi
@@ -25,6 +25,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/swprintf.texi b/doc/posix-functions/swprintf.texi
index a076eb32cf..906ee521aa 100644
--- a/doc/posix-functions/swprintf.texi
+++ b/doc/posix-functions/swprintf.texi
@@ -13,10 +13,6 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-The @code{%m} directive is not portable, use @code{%s} mapped to an
-argument of @code{strerror(errno)} (or a version of @code{strerror_r})
-instead.
-@item
 This function is missing on some platforms:
 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11.00, IRIX 6.5, Cygwin 1.5.x.
 @item
@@ -35,6 +31,15 @@
 @item
 On Windows, this function does not take a buffer size as second argument.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
+The @code{%m} directive is not portable, use @code{%s} mapped to an
+argument of @code{strerror(errno)} (or a version of @code{strerror_r})
+instead.
+@item
 When formatting an integer with grouping flag, this function inserts thousands
 separators even in the "C" locale on some platforms:
 NetBSD 5.1.
diff --git a/doc/posix-functions/vdprintf.texi b/doc/posix-functions/vdprintf.texi
index ca84b011bb..d4de64ee25 100644
--- a/doc/posix-functions/vdprintf.texi
+++ b/doc/posix-functions/vdprintf.texi
@@ -24,6 +24,11 @@
 platforms:
 glibc-2.3.6, Solaris 11.4.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, Solaris 11.4, Cygwin 2.9.0.
+@item
 This function does not support the @samp{n} directive on some platforms:
 glibc when used with @code{_FORTIFY_SOURCE >= 2} (set by default on Ubuntu),
 macOS 11.1.
diff --git a/doc/posix-functions/vfprintf.texi b/doc/posix-functions/vfprintf.texi
index 8441649d03..f3ec56b5a6 100644
--- a/doc/posix-functions/vfprintf.texi
+++ b/doc/posix-functions/vfprintf.texi
@@ -25,6 +25,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/vfwprintf.texi b/doc/posix-functions/vfwprintf.texi
index 56cd3851f8..f6e136b0b1 100644
--- a/doc/posix-functions/vfwprintf.texi
+++ b/doc/posix-functions/vfwprintf.texi
@@ -13,16 +13,21 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-The @code{%m} directive is not portable, use @code{%s} mapped to an
-argument of @code{strerror(errno)} (or a version of @code{strerror_r})
-instead.
-@item
 This function is missing on some platforms:
 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11.00, IRIX 6.5, Cygwin 1.5.x.
 @item
 On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
+The @code{%m} directive is not portable, use @code{%s} mapped to an
+argument of @code{strerror(errno)} (or a version of @code{strerror_r})
+instead.
+@item
 When formatting an integer with grouping flag, this function inserts thousands
 separators even in the "C" locale on some platforms:
 NetBSD 5.1.
diff --git a/doc/posix-functions/vprintf.texi b/doc/posix-functions/vprintf.texi
index a43942fbd2..6e05d41002 100644
--- a/doc/posix-functions/vprintf.texi
+++ b/doc/posix-functions/vprintf.texi
@@ -25,6 +25,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/vsnprintf.texi b/doc/posix-functions/vsnprintf.texi
index 2f3406ec4c..660ccfb1c3 100644
--- a/doc/posix-functions/vsnprintf.texi
+++ b/doc/posix-functions/vsnprintf.texi
@@ -37,6 +37,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/vsprintf.texi b/doc/posix-functions/vsprintf.texi
index 0ddcdfca12..8af4bdf279 100644
--- a/doc/posix-functions/vsprintf.texi
+++ b/doc/posix-functions/vsprintf.texi
@@ -25,6 +25,11 @@
 glibc-2.3.6, Mac OS X 10.5, NetBSD 9.0, OpenBSD 4.0, AIX 5.2, HP-UX 11,
 IRIX 6.5, Solaris 11.4, Cygwin 1.5.x, mingw, MSVC 14.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, IRIX 6.5, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
 This function does not support the @samp{F} directive on some platforms:
 NetBSD 3.0, AIX 5.1, HP-UX 11.23, IRIX 6.5, Solaris 9,
 Cygwin 1.5.x, mingw, MSVC 14.
diff --git a/doc/posix-functions/vswprintf.texi b/doc/posix-functions/vswprintf.texi
index 2f771216ab..62a644fb6d 100644
--- a/doc/posix-functions/vswprintf.texi
+++ b/doc/posix-functions/vswprintf.texi
@@ -13,10 +13,6 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-The @code{%m} directive is not portable, use @code{%s} mapped to an
-argument of @code{strerror(errno)} (or a version of @code{strerror_r})
-instead.
-@item
 This function is missing on some platforms:
 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11.00, IRIX 6.5, Cygwin 1.5.x.
 @item
@@ -25,6 +21,15 @@
 @item
 On Windows, this function does not take a buffer size as second argument.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
+The @code{%m} directive is not portable, use @code{%s} mapped to an
+argument of @code{strerror(errno)} (or a version of @code{strerror_r})
+instead.
+@item
 When formatting an integer with grouping flag, this function inserts thousands
 separators even in the "C" locale on some platforms:
 NetBSD 5.1.
diff --git a/doc/posix-functions/vwprintf.texi b/doc/posix-functions/vwprintf.texi
index f2d839bdbc..80c8646663 100644
--- a/doc/posix-functions/vwprintf.texi
+++ b/doc/posix-functions/vwprintf.texi
@@ -13,10 +13,6 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-The @code{%m} directive is not portable, use @code{%s} mapped to an
-argument of @code{strerror(errno)} (or a version of @code{strerror_r})
-instead.
-@item
 This function is missing on some platforms:
 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11.00, IRIX 6.5, Cygwin 1.7.
 @item
@@ -26,6 +22,15 @@
 On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
+The @code{%m} directive is not portable, use @code{%s} mapped to an
+argument of @code{strerror(errno)} (or a version of @code{strerror_r})
+instead.
+@item
 When formatting an integer with grouping flag, this function inserts thousands
 separators even in the "C" locale on some platforms:
 NetBSD 5.1.
diff --git a/doc/posix-functions/wprintf.texi b/doc/posix-functions/wprintf.texi
index 48ac729e01..1c3b99b281 100644
--- a/doc/posix-functions/wprintf.texi
+++ b/doc/posix-functions/wprintf.texi
@@ -13,10 +13,6 @@
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-The @code{%m} directive is not portable, use @code{%s} mapped to an
-argument of @code{strerror(errno)} (or a version of @code{strerror_r})
-instead.
-@item
 This function is missing on some platforms:
 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, HP-UX 11.00, IRIX 6.5.
 @item
@@ -26,6 +22,15 @@
 On Windows and 32-bit AIX platforms, @code{wchar_t} is a 16-bit type and therefore cannot
 accommodate all Unicode characters.
 @item
+This function does not support the @samp{b} directive, required by ISO C23,
+on some platforms:
+glibc 2.34, musl libc, macOS 12.5, FreeBSD 13.1, NetBSD 9.0, OpenBSD 7.2,
+AIX 7.2, HP-UX 11, Solaris 11.4, Cygwin 2.9.0, mingw, MSVC 14.
+@item
+The @code{%m} directive is not portable, use @code{%s} mapped to an
+argument of @code{strerror(errno)} (or a version of @code{strerror_r})
+instead.
+@item
 When formatting an integer with grouping flag, this function inserts thousands
 separators even in the "C" locale on some platforms:
 NetBSD 5.1.
diff --git a/lib/printf-parse.c b/lib/printf-parse.c
index 3040749abd..6273dd773f 100644
--- a/lib/printf-parse.c
+++ b/lib/printf-parse.c
@@ -453,7 +453,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
                   else
                     type = TYPE_INT;
                   break;
-                case 'o': case 'u': case 'x': case 'X':
+                case 'b': case 'o': case 'u': case 'x': case 'X':
                   /* 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 1f86e32c99..fcb3cc462e 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 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;
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index a49eb1dcd7..c2f10cb0c4 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -1653,6 +1653,25 @@ MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion,
       tmp_length = xsum (tmp_length, 1);
       break;
 
+    case 'b':
+      if (type == TYPE_ULONGLONGINT)
+        tmp_length =
+          (unsigned int) (sizeof (unsigned long long) * CHAR_BIT)
+          + 1; /* turn floor into ceil */
+      else if (type == TYPE_ULONGINT)
+        tmp_length =
+          (unsigned int) (sizeof (unsigned long) * CHAR_BIT)
+          + 1; /* turn floor into ceil */
+      else
+        tmp_length =
+          (unsigned int) (sizeof (unsigned int) * CHAR_BIT)
+          + 1; /* turn floor into ceil */
+      if (tmp_length < precision)
+        tmp_length = precision;
+      /* Add 2, to account for a prefix from the alternate form.  */
+      tmp_length = xsum (tmp_length, 2);
+      break;
+
     case 'o':
       if (type == TYPE_ULONGLONGINT)
         tmp_length =
@@ -3043,6 +3062,199 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 }
               }
 #endif
+#if NEED_PRINTF_DIRECTIVE_B
+            else if (dp->conversion == 'b')
+              {
+                arg_type type = a.arg[dp->arg_index].type;
+                int flags = dp->flags;
+                size_t width;
+                int has_precision;
+                size_t precision;
+                size_t tmp_length;
+                size_t count;
+                DCHAR_T tmpbuf[700];
+                DCHAR_T *tmp;
+                DCHAR_T *tmp_end;
+                DCHAR_T *tmp_start;
+                DCHAR_T *pad_ptr;
+                DCHAR_T *p;
+
+                width = 0;
+                if (dp->width_start != dp->width_end)
+                  {
+                    if (dp->width_arg_index != ARG_NONE)
+                      {
+                        int arg;
+
+                        if (!(a.arg[dp->width_arg_index].type == TYPE_INT))
+                          abort ();
+                        arg = a.arg[dp->width_arg_index].a.a_int;
+                        width = arg;
+                        if (arg < 0)
+                          {
+                            /* "A negative field width is taken as a '-' flag
+                                followed by a positive field width."  */
+                            flags |= FLAG_LEFT;
+                            width = -width;
+                          }
+                      }
+                    else
+                      {
+                        const FCHAR_T *digitp = dp->width_start;
+
+                        do
+                          width = xsum (xtimes (width, 10), *digitp++ - '0');
+                        while (digitp != dp->width_end);
+                      }
+                  }
+
+                has_precision = 0;
+                precision = 0;
+                if (dp->precision_start != dp->precision_end)
+                  {
+                    if (dp->precision_arg_index != ARG_NONE)
+                      {
+                        int arg;
+
+                        if (!(a.arg[dp->precision_arg_index].type == TYPE_INT))
+                          abort ();
+                        arg = a.arg[dp->precision_arg_index].a.a_int;
+                        /* "A negative precision is taken as if the precision
+                            were omitted."  */
+                        if (arg >= 0)
+                          {
+                            precision = arg;
+                            has_precision = 1;
+                          }
+                      }
+                    else
+                      {
+                        const FCHAR_T *digitp = dp->precision_start + 1;
+
+                        precision = 0;
+                        while (digitp != dp->precision_end)
+                          precision = xsum (xtimes (precision, 10), *digitp++ - '0');
+                        has_precision = 1;
+                      }
+                  }
+
+                /* Allocate a temporary buffer of sufficient size.  */
+                if (type == TYPE_ULONGLONGINT)
+                  tmp_length =
+                    (unsigned int) (sizeof (unsigned long long) * CHAR_BIT)
+                    + 1; /* turn floor into ceil */
+                else if (type == TYPE_ULONGINT)
+                  tmp_length =
+                    (unsigned int) (sizeof (unsigned long) * CHAR_BIT)
+                    + 1; /* turn floor into ceil */
+                else
+                  tmp_length =
+                    (unsigned int) (sizeof (unsigned int) * CHAR_BIT)
+                    + 1; /* turn floor into ceil */
+                if (tmp_length < precision)
+                  tmp_length = precision;
+                /* Add 2, to account for a prefix from the alternate form.  */
+                tmp_length = xsum (tmp_length, 2);
+
+                if (tmp_length < width)
+                  tmp_length = width;
+
+                if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T))
+                  tmp = tmpbuf;
+                else
+                  {
+                    size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T));
+
+                    if (size_overflow_p (tmp_memsize))
+                      /* Overflow, would lead to out of memory.  */
+                      goto out_of_memory;
+                    tmp = (DCHAR_T *) malloc (tmp_memsize);
+                    if (tmp == NULL)
+                      /* Out of memory.  */
+                      goto out_of_memory;
+                  }
+
+                tmp_end = tmp + tmp_length;
+
+                unsigned long long arg =
+                  (type == TYPE_ULONGLONGINT ? a.arg[dp->arg_index].a.a_ulonglongint :
+                   type == TYPE_ULONGINT ? a.arg[dp->arg_index].a.a_ulongint :
+                   a.arg[dp->arg_index].a.a_uint);
+                int need_prefix = ((flags & FLAG_ALT) && arg != 0);
+
+                p = tmp_end;
+                do
+                  {
+                    *--p = '0' + (arg & 1);
+                    arg = arg >> 1;
+                  }
+                while (arg != 0);
+
+                pad_ptr = p;
+
+                if (need_prefix)
+                  {
+                    *--p = 'b'; *--p = '0';
+                  }
+                tmp_start = p;
+
+                /* The generated string now extends from tmp_start to tmp_end,
+                   with the zero padding insertion point being at pad_ptr,
+                   tmp_start <= pad_ptr <= tmp_end.  */
+                count = tmp_end - tmp_start;
+
+                if (count < width)
+                  {
+                    size_t pad = width - count;
+
+                    if (flags & FLAG_LEFT)
+                      {
+                        /* Pad with spaces on the right.  */
+                        for (p = tmp_start; p < tmp_end; p++)
+                          *(p - pad) = *p;
+                        for (p = tmp_end - pad; p < tmp_end; p++)
+                          *p = ' ';
+                      }
+                    else if (flags & FLAG_ZERO)
+                      {
+                        /* Pad with zeroes.  */
+                        for (p = tmp_start; p < pad_ptr; p++)
+                          *(p - pad) = *p;
+                        for (p = pad_ptr - pad; p < pad_ptr; p++)
+                          *p = '0';
+                      }
+                    else
+                      {
+                        /* Pad with spaces on the left.  */
+                        for (p = tmp_start - pad; p < tmp_start; p++)
+                          *p = ' ';
+                      }
+
+                    tmp_start = tmp_start - pad;
+                  }
+
+                count = tmp_end - tmp_start;
+
+                if (count > tmp_length)
+                  /* tmp_length was incorrectly calculated - fix the
+                     code above!  */
+                  abort ();
+
+                /* Make room for the result.  */
+                if (count >= allocated - length)
+                  {
+                    size_t n = xsum (length, count);
+
+                    ENSURE_ALLOCATION (n);
+                  }
+
+                /* Append the result.  */
+                memcpy (result + length, tmp_start, count * sizeof (DCHAR_T));
+                if (tmp != tmpbuf)
+                  free (tmp);
+                length += count;
+              }
+#endif
 #if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE
             else if ((dp->conversion == 'a' || dp->conversion == 'A')
 # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE))
@@ -4826,6 +5038,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
                 switch (dp->conversion)
                   {
                   case 'd': case 'i': case 'u':
+                  case 'b':
                   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 05799b8f15..86bdec9a21 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 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;
diff --git a/m4/dprintf-posix.m4 b/m4/dprintf-posix.m4
index a25ef4164e..4186ab70fe 100644
--- a/m4/dprintf-posix.m4
+++ b/m4/dprintf-posix.m4
@@ -1,4 +1,4 @@
-# dprintf-posix.m4 serial 3
+# dprintf-posix.m4 serial 4
 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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -33,27 +34,31 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX]
                   *yes)
                     case "$gl_cv_func_printf_directive_a" in
                       *yes)
-                        case "$gl_cv_func_printf_directive_f" in
+                        case "$gl_cv_func_printf_directive_b" in
                           *yes)
-                            case "$gl_cv_func_printf_directive_n" in
+                            case "$gl_cv_func_printf_directive_f" in
                               *yes)
-                                case "$gl_cv_func_printf_directive_ls" in
+                                case "$gl_cv_func_printf_directive_n" in
                                   *yes)
-                                    case "$gl_cv_func_printf_positions" in
+                                    case "$gl_cv_func_printf_directive_ls" 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
                                                         ;;
@@ -88,6 +93,7 @@ AC_DEFUN([gl_FUNC_DPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/fprintf-posix.m4 b/m4/fprintf-posix.m4
index 3a51bcf4e1..5602000e4a 100644
--- a/m4/fprintf-posix.m4
+++ b/m4/fprintf-posix.m4
@@ -1,4 +1,4 @@
-# fprintf-posix.m4 serial 14
+# fprintf-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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -31,27 +32,31 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX]
                 *yes)
                   case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_f" in
+                      case "$gl_cv_func_printf_directive_b" in
                         *yes)
-                          case "$gl_cv_func_printf_directive_n" in
+                          case "$gl_cv_func_printf_directive_f" in
                             *yes)
-                              case "$gl_cv_func_printf_directive_ls" in
+                              case "$gl_cv_func_printf_directive_n" in
                                 *yes)
-                                  case "$gl_cv_func_printf_positions" in
+                                  case "$gl_cv_func_printf_directive_ls" 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
                                                       ;;
@@ -85,6 +90,7 @@ AC_DEFUN([gl_FUNC_FPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/obstack-printf-posix.m4 b/m4/obstack-printf-posix.m4
index 10f744c575..633b017442 100644
--- a/m4/obstack-printf-posix.m4
+++ b/m4/obstack-printf-posix.m4
@@ -1,4 +1,4 @@
-# obstack-printf-posix.m4 serial 4
+# obstack-printf-posix.m4 serial 5
 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,
@@ -14,6 +14,7 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -36,27 +37,31 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX]
                   *yes)
                     case "$gl_cv_func_printf_directive_a" in
                       *yes)
-                        case "$gl_cv_func_printf_directive_f" in
+                        case "$gl_cv_func_printf_directive_b" in
                           *yes)
-                            case "$gl_cv_func_printf_directive_n" in
+                            case "$gl_cv_func_printf_directive_f" in
                               *yes)
-                                case "$gl_cv_func_printf_directive_ls" in
+                                case "$gl_cv_func_printf_directive_n" in
                                   *yes)
-                                    case "$gl_cv_func_printf_positions" in
+                                    case "$gl_cv_func_printf_directive_ls" 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
                                                         ;;
@@ -91,6 +96,7 @@ AC_DEFUN([gl_FUNC_OBSTACK_PRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/printf.m4 b/m4/printf.m4
index de98a870e9..719679c362 100644
--- a/m4/printf.m4
+++ b/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 74
+# printf.m4 serial 75
 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,
@@ -603,6 +603,50 @@ AC_DEFUN([gl_PRINTF_DIRECTIVE_A]
     ])
 ])
 
+dnl Test whether the *printf family of functions supports the 'b' conversion
+dnl specifier for binary output of integers.
+dnl (ISO C23)
+dnl Result is gl_cv_func_printf_directive_b.
+
+AC_DEFUN([gl_PRINTF_DIRECTIVE_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_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, "11000000111001 33") != 0)
+    result |= 1;
+  return result;
+}]])],
+        [gl_cv_func_printf_directive_b=yes],
+        [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 no on musl systems.
+           *-musl* | midipix*) gl_cv_func_printf_directive_b="guessing no";;
+                               # Guess no on Android.
+           linux*-android*)    gl_cv_func_printf_directive_b="guessing no";;
+                               # Guess no on native Windows.
+           mingw*)             gl_cv_func_printf_directive_b="guessing no";;
+                               # If we don't know, obey --enable-cross-guesses.
+           *)                  gl_cv_func_printf_directive_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.
@@ -1648,81 +1692,83 @@ AC_DEFUN([gl_VSNPRINTF_ZEROSIZE_C99]
 dnl 3 = gl_PRINTF_INFINITE
 dnl 4 = gl_PRINTF_INFINITE_LONG_DOUBLE
 dnl 5 = gl_PRINTF_DIRECTIVE_A
-dnl 6 = gl_PRINTF_DIRECTIVE_F
-dnl 7 = gl_PRINTF_DIRECTIVE_N
-dnl 8 = gl_PRINTF_DIRECTIVE_LS
-dnl 9 = gl_PRINTF_POSITIONS
-dnl 10 = gl_PRINTF_FLAG_GROUPING
-dnl 11 = gl_PRINTF_FLAG_LEFTADJUST
-dnl 12 = gl_PRINTF_FLAG_ZERO
-dnl 13 = gl_PRINTF_PRECISION
-dnl 14 = gl_PRINTF_ENOMEM
-dnl 15 = gl_SNPRINTF_PRESENCE
-dnl 16 = gl_SNPRINTF_TRUNCATION_C99
-dnl 17 = gl_SNPRINTF_RETVAL_C99
-dnl 18 = gl_SNPRINTF_DIRECTIVE_N
-dnl 19 = gl_SNPRINTF_SIZE1
-dnl 20 = gl_VSNPRINTF_ZEROSIZE_C99
+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
 dnl 1 = checking whether printf supports size specifiers as in C99...
 dnl 2 = checking whether printf supports 'long double' arguments...
 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 'F' directive...
-dnl 7 = checking whether printf supports the 'n' directive...
-dnl 8 = checking whether printf supports the 'ls' directive...
-dnl 9 = checking whether printf supports POSIX/XSI format strings with positions...
-dnl 10 = checking whether printf supports the grouping flag...
-dnl 11 = checking whether printf supports the left-adjust flag correctly...
-dnl 12 = checking whether printf supports the zero flag correctly...
-dnl 13 = checking whether printf supports large precisions...
-dnl 14 = checking whether printf survives out-of-memory conditions...
-dnl 15 = checking for snprintf...
-dnl 16 = checking whether snprintf truncates the result as in C99...
-dnl 17 = checking whether snprintf returns a byte count as in C99...
-dnl 18 = checking whether snprintf fully supports the 'n' directive...
-dnl 19 = checking whether snprintf respects a size of 1...
-dnl 20 = checking whether vsnprintf respects a zero size as in C99...
+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
 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
-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
+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 61a80a8aa8..033e1916e5 100644
--- a/m4/snprintf-posix.m4
+++ b/m4/snprintf-posix.m4
@@ -1,4 +1,4 @@
-# snprintf-posix.m4 serial 14
+# snprintf-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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -38,37 +39,41 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX]
                   *yes)
                     case "$gl_cv_func_printf_directive_a" in
                       *yes)
-                        case "$gl_cv_func_printf_directive_f" in
+                        case "$gl_cv_func_printf_directive_b" in
                           *yes)
-                            case "$gl_cv_func_printf_directive_n" in
+                            case "$gl_cv_func_printf_directive_f" in
                               *yes)
-                                case "$gl_cv_func_printf_directive_ls" in
+                                case "$gl_cv_func_printf_directive_n" in
                                   *yes)
-                                    case "$gl_cv_func_printf_positions" in
+                                    case "$gl_cv_func_printf_directive_ls" 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
                                                                             ;;
@@ -113,6 +118,7 @@ AC_DEFUN([gl_FUNC_SNPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/sprintf-posix.m4 b/m4/sprintf-posix.m4
index 9d9258e17a..cfcbe37cce 100644
--- a/m4/sprintf-posix.m4
+++ b/m4/sprintf-posix.m4
@@ -1,4 +1,4 @@
-# sprintf-posix.m4 serial 12
+# sprintf-posix.m4 serial 13
 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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -31,27 +32,31 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX]
                 *yes)
                   case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_f" in
+                      case "$gl_cv_func_printf_directive_b" in
                         *yes)
-                          case "$gl_cv_func_printf_directive_n" in
+                          case "$gl_cv_func_printf_directive_f" in
                             *yes)
-                              case "$gl_cv_func_printf_directive_ls" in
+                              case "$gl_cv_func_printf_directive_n" in
                                 *yes)
-                                  case "$gl_cv_func_printf_positions" in
+                                  case "$gl_cv_func_printf_directive_ls" 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
                                                       ;;
@@ -85,6 +90,7 @@ AC_DEFUN([gl_FUNC_SPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/vasnprintf-posix.m4 b/m4/vasnprintf-posix.m4
index baf7cb437d..4983dfc50a 100644
--- a/m4/vasnprintf-posix.m4
+++ b/m4/vasnprintf-posix.m4
@@ -1,4 +1,4 @@
-# vasnprintf-posix.m4 serial 13
+# vasnprintf-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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -32,29 +33,33 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX]
                 *yes)
                   case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_f" in
+                      case "$gl_cv_func_printf_directive_b" in
                         *yes)
-                          case "$gl_cv_func_printf_directive_n" in
+                          case "$gl_cv_func_printf_directive_f" in
                             *yes)
-                              case "$gl_cv_func_printf_directive_ls" in
+                              case "$gl_cv_func_printf_directive_n" in
                                 *yes)
-                                  case "$gl_cv_func_printf_positions" in
+                                  case "$gl_cv_func_printf_directive_ls" 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
                                                       ;;
@@ -88,6 +93,7 @@ AC_DEFUN([gl_FUNC_VASNPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/vasnprintf.m4 b/m4/vasnprintf.m4
index cf451f9b03..b868aed08b 100644
--- a/m4/vasnprintf.m4
+++ b/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 40
+# vasnprintf.m4 serial 41
 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,
@@ -182,6 +182,21 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_A]
   esac
 ])
 
+# Extra prerequisites of lib/vasnprintf.c for supporting the 'b' directive.
+AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_B],
+[
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
+  case "$gl_cv_func_printf_directive_b" in
+    *yes)
+      ;;
+    *)
+      AC_DEFINE([NEED_PRINTF_DIRECTIVE_B], [1],
+        [Define if the vasnprintf implementation needs special code for
+         the 'b' directive.])
+      ;;
+  esac
+])
+
 # Extra prerequisites of lib/vasnprintf.c for supporting the 'F' directive.
 AC_DEFUN([gl_PREREQ_VASNPRINTF_DIRECTIVE_F],
 [
@@ -308,6 +323,7 @@ AC_DEFUN([gl_PREREQ_VASNPRINTF_WITH_EXTRAS]
   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_FLAG_GROUPING
diff --git a/m4/vasnwprintf-posix.m4 b/m4/vasnwprintf-posix.m4
index 9561bcf2b6..d9dc41fa97 100644
--- a/m4/vasnwprintf-posix.m4
+++ b/m4/vasnwprintf-posix.m4
@@ -1,4 +1,4 @@
-# vasnwprintf-posix.m4 serial 1
+# vasnwprintf-posix.m4 serial 2
 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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_VASNWPRINTF_POSIX]
   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_FLAG_GROUPING
diff --git a/m4/vasprintf-posix.m4 b/m4/vasprintf-posix.m4
index 7c198a6410..1537ad52d9 100644
--- a/m4/vasprintf-posix.m4
+++ b/m4/vasprintf-posix.m4
@@ -1,4 +1,4 @@
-# vasprintf-posix.m4 serial 13
+# vasprintf-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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -32,29 +33,33 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX]
                 *yes)
                   case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_f" in
+                      case "$gl_cv_func_printf_directive_b" in
                         *yes)
-                          case "$gl_cv_func_printf_directive_n" in
+                          case "$gl_cv_func_printf_directive_f" in
                             *yes)
-                              case "$gl_cv_func_printf_directive_ls" in
+                              case "$gl_cv_func_printf_directive_n" in
                                 *yes)
-                                  case "$gl_cv_func_printf_positions" in
+                                  case "$gl_cv_func_printf_directive_ls" 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
                                                       ;;
@@ -88,6 +93,7 @@ AC_DEFUN([gl_FUNC_VASPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/vdprintf-posix.m4 b/m4/vdprintf-posix.m4
index 47914cd177..eb9ab8c679 100644
--- a/m4/vdprintf-posix.m4
+++ b/m4/vdprintf-posix.m4
@@ -1,4 +1,4 @@
-# vdprintf-posix.m4 serial 3
+# vdprintf-posix.m4 serial 4
 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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -33,27 +34,31 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX]
                   *yes)
                     case "$gl_cv_func_printf_directive_a" in
                       *yes)
-                        case "$gl_cv_func_printf_directive_f" in
+                        case "$gl_cv_func_printf_directive_b" in
                           *yes)
-                            case "$gl_cv_func_printf_directive_n" in
+                            case "$gl_cv_func_printf_directive_f" in
                               *yes)
-                                case "$gl_cv_func_printf_directive_ls" in
+                                case "$gl_cv_func_printf_directive_n" in
                                   *yes)
-                                    case "$gl_cv_func_printf_positions" in
+                                    case "$gl_cv_func_printf_directive_ls" 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
                                                         ;;
@@ -88,6 +93,7 @@ AC_DEFUN([gl_FUNC_VDPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/vfprintf-posix.m4 b/m4/vfprintf-posix.m4
index ec68052214..17a8bad843 100644
--- a/m4/vfprintf-posix.m4
+++ b/m4/vfprintf-posix.m4
@@ -1,4 +1,4 @@
-# vfprintf-posix.m4 serial 14
+# vfprintf-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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -31,27 +32,31 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX]
                 *yes)
                   case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_f" in
+                      case "$gl_cv_func_printf_directive_b" in
                         *yes)
-                          case "$gl_cv_func_printf_directive_n" in
+                          case "$gl_cv_func_printf_directive_f" in
                             *yes)
-                              case "$gl_cv_func_printf_directive_ls" in
+                              case "$gl_cv_func_printf_directive_n" in
                                 *yes)
-                                  case "$gl_cv_func_printf_positions" in
+                                  case "$gl_cv_func_printf_directive_ls" 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
                                                       ;;
@@ -85,6 +90,7 @@ AC_DEFUN([gl_FUNC_VFPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/vsnprintf-posix.m4 b/m4/vsnprintf-posix.m4
index 5ea04a05e5..65805522d4 100644
--- a/m4/vsnprintf-posix.m4
+++ b/m4/vsnprintf-posix.m4
@@ -1,4 +1,4 @@
-# vsnprintf-posix.m4 serial 15
+# vsnprintf-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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -39,37 +40,41 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX]
                   *yes)
                     case "$gl_cv_func_printf_directive_a" in
                       *yes)
-                        case "$gl_cv_func_printf_directive_f" in
+                        case "$gl_cv_func_printf_directive_b" in
                           *yes)
-                            case "$gl_cv_func_printf_directive_n" in
+                            case "$gl_cv_func_printf_directive_f" in
                               *yes)
-                                case "$gl_cv_func_printf_directive_ls" in
+                                case "$gl_cv_func_printf_directive_n" in
                                   *yes)
-                                    case "$gl_cv_func_printf_positions" in
+                                    case "$gl_cv_func_printf_directive_ls" 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
                                                                             ;;
@@ -114,6 +119,7 @@ AC_DEFUN([gl_FUNC_VSNPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/m4/vsprintf-posix.m4 b/m4/vsprintf-posix.m4
index 3ca0178ebd..716f58f761 100644
--- a/m4/vsprintf-posix.m4
+++ b/m4/vsprintf-posix.m4
@@ -1,4 +1,4 @@
-# vsprintf-posix.m4 serial 12
+# vsprintf-posix.m4 serial 13
 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,
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX]
   AC_REQUIRE([gl_PRINTF_INFINITE])
   AC_REQUIRE([gl_PRINTF_INFINITE_LONG_DOUBLE])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_A])
+  AC_REQUIRE([gl_PRINTF_DIRECTIVE_B])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_F])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_N])
   AC_REQUIRE([gl_PRINTF_DIRECTIVE_LS])
@@ -31,27 +32,31 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX]
                 *yes)
                   case "$gl_cv_func_printf_directive_a" in
                     *yes)
-                      case "$gl_cv_func_printf_directive_f" in
+                      case "$gl_cv_func_printf_directive_b" in
                         *yes)
-                          case "$gl_cv_func_printf_directive_n" in
+                          case "$gl_cv_func_printf_directive_f" in
                             *yes)
-                              case "$gl_cv_func_printf_directive_ls" in
+                              case "$gl_cv_func_printf_directive_n" in
                                 *yes)
-                                  case "$gl_cv_func_printf_positions" in
+                                  case "$gl_cv_func_printf_directive_ls" 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
                                                       ;;
@@ -85,6 +90,7 @@ AC_DEFUN([gl_FUNC_VSPRINTF_POSIX]
     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_FLAG_GROUPING
diff --git a/tests/test-snprintf-posix.h b/tests/test-snprintf-posix.h
index 4db76deb75..579d34583d 100644
--- a/tests/test-snprintf-posix.h
+++ b/tests/test-snprintf-posix.h
@@ -435,6 +435,8 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
   { /* Positive infinity.  */
     int retval =
       my_snprintf (result, sizeof (result), "%La %d", Infinityl (), 33, 44, 55);
+    /* Note: This assertion fails under valgrind.
+       Reported at <https://bugs.kde.org/show_bug.cgi?id=424044>.  */
     ASSERT (strcmp (result, "inf 33") == 0);
     ASSERT (retval == strlen (result));
   }
@@ -3053,4 +3055,70 @@ test_function (int (*my_snprintf) (char *, size_t, const char *, ...))
     ASSERT (retval == strlen (result));
   }
 #endif
+
+  /* Test the support of the 'b' conversion specifier for binary output of
+     integers.  */
+
+  { /* Zero.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%b %d", 0, 33, 44, 55);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* A positive number.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* A large positive number.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%b %d", 0xFFFFFFFEU, 33, 44, 55);
+    ASSERT (strcmp (result, "11111111111111111111111111111110 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* Width.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%20b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* Width given as argument.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%*b %d", 20, 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%*b %d", -20, 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* FLAG_LEFT.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%-20b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* FLAG_ALT with zero.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%#b %d", 0, 33, 44, 55);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* FLAG_ALT with a positive number.  */
+    int retval =
+      my_snprintf (result, sizeof (result), "%#b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "0b11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
 }
diff --git a/tests/test-sprintf-posix.h b/tests/test-sprintf-posix.h
index 979254acc7..863d084b99 100644
--- a/tests/test-sprintf-posix.h
+++ b/tests/test-sprintf-posix.h
@@ -421,6 +421,8 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
   { /* Positive infinity.  */
     int retval =
       my_sprintf (result, "%La %d", Infinityl (), 33, 44, 55);
+    /* Note: This assertion fails under valgrind.
+       Reported at <https://bugs.kde.org/show_bug.cgi?id=424044>.  */
     ASSERT (strcmp (result, "inf 33") == 0);
     ASSERT (retval == strlen (result));
   }
@@ -3035,4 +3037,70 @@ test_function (int (*my_sprintf) (char *, const char *, ...))
     ASSERT (retval == strlen (result));
   }
 #endif
+
+  /* Test the support of the 'b' conversion specifier for binary output of
+     integers.  */
+
+  { /* Zero.  */
+    int retval =
+      my_sprintf (result, "%b %d", 0, 33, 44, 55);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* A positive number.  */
+    int retval =
+      my_sprintf (result, "%b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* A large positive number.  */
+    int retval =
+      my_sprintf (result, "%b %d", 0xFFFFFFFEU, 33, 44, 55);
+    ASSERT (strcmp (result, "11111111111111111111111111111110 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* Width.  */
+    int retval =
+      my_sprintf (result, "%20b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* Width given as argument.  */
+    int retval =
+      my_sprintf (result, "%*b %d", 20, 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    int retval =
+      my_sprintf (result, "%*b %d", -20, 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* FLAG_LEFT.  */
+    int retval =
+      my_sprintf (result, "%-20b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* FLAG_ALT with zero.  */
+    int retval =
+      my_sprintf (result, "%#b %d", 0, 33, 44, 55);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
+
+  { /* FLAG_ALT with a positive number.  */
+    int retval =
+      my_sprintf (result, "%#b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "0b11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+  }
 }
diff --git a/tests/test-vasnprintf-posix.c b/tests/test-vasnprintf-posix.c
index 4a83f6d243..c6e1e2f650 100644
--- a/tests/test-vasnprintf-posix.c
+++ b/tests/test-vasnprintf-posix.c
@@ -562,6 +562,8 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
     char *result =
       my_asnprintf (NULL, &length, "%La %d", Infinityl (), 33, 44, 55);
     ASSERT (result != NULL);
+    /* Note: This assertion fails under valgrind.
+       Reported at <https://bugs.kde.org/show_bug.cgi?id=424044>.  */
     ASSERT (strcmp (result, "inf 33") == 0);
     ASSERT (length == strlen (result));
     free (result);
@@ -3974,6 +3976,97 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
   }
 #endif
 
+  /* Test the support of the 'b' conversion specifier for binary output of
+     integers.  */
+
+  { /* Zero.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%b %d", 0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11000000111001 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* A large positive number.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%b %d", 0xFFFFFFFEU, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11111111111111111111111111111110 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%20b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%*b %d", 20, 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%*b %d", -20, 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%-20b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT with zero.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%#b %d", 0, 33, 44, 55);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT with a positive number.  */
+    size_t length;
+    char *result =
+      my_asnprintf (NULL, &length, "%#b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "0b11000000111001 33") == 0);
+    ASSERT (length == strlen (result));
+    free (result);
+  }
+
 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__
   /* Test that the 'I' flag is supported.  */
   {
diff --git a/tests/test-vasnwprintf-posix.c b/tests/test-vasnwprintf-posix.c
index f686bfb9fe..c609a104ff 100644
--- a/tests/test-vasnwprintf-posix.c
+++ b/tests/test-vasnwprintf-posix.c
@@ -562,6 +562,8 @@ test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *,
     wchar_t *result =
       my_asnwprintf (NULL, &length, L"%La %d", Infinityl (), 33, 44, 55);
     ASSERT (result != NULL);
+    /* Note: This assertion fails under valgrind.
+       Reported at <https://bugs.kde.org/show_bug.cgi?id=424044>.  */
     ASSERT (wcscmp (result, L"inf 33") == 0);
     ASSERT (length == wcslen (result));
     free (result);
@@ -3982,6 +3984,97 @@ test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *,
   }
 #endif
 
+  /* Test the support of the 'b' conversion specifier for binary output of
+     integers.  */
+
+  { /* Zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%b %d", 0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"11000000111001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* A large positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%b %d", 0xFFFFFFFEU, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"11111111111111111111111111111110 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%20b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"      11000000111001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*b %d", 20, 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"      11000000111001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%*b %d", -20, 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"11000000111001       33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%-20b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (wcscmp (result, L"11000000111001       33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT with zero.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#b %d", 0, 33, 44, 55);
+    ASSERT (wcscmp (result, L"0 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT with a positive number.  */
+    size_t length;
+    wchar_t *result =
+      my_asnwprintf (NULL, &length, L"%#b %d", 12345, 33, 44, 55);
+    ASSERT (wcscmp (result, L"0b11000000111001 33") == 0);
+    ASSERT (length == wcslen (result));
+    free (result);
+  }
+
 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) && !defined __UCLIBC__
   /* Test that the 'I' flag is supported.  */
   {
diff --git a/tests/test-vasprintf-posix.c b/tests/test-vasprintf-posix.c
index 8563502c47..13b3a1bca9 100644
--- a/tests/test-vasprintf-posix.c
+++ b/tests/test-vasprintf-posix.c
@@ -543,6 +543,8 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     int retval =
       my_asprintf (&result, "%La %d", Infinityl (), 33, 44, 55);
     ASSERT (result != NULL);
+    /* Note: This assertion fails under valgrind.
+       Reported at <https://bugs.kde.org/show_bug.cgi?id=424044>.  */
     ASSERT (strcmp (result, "inf 33") == 0);
     ASSERT (retval == strlen (result));
     free (result);
@@ -3914,6 +3916,97 @@ test_function (int (*my_asprintf) (char **, const char *, ...))
     free (result);
   }
 #endif
+
+  /* Test the support of the 'b' conversion specifier for binary output of
+     integers.  */
+
+  { /* Zero.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%b %d", 0, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* A positive number.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* A large positive number.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%b %d", 0xFFFFFFFEU, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11111111111111111111111111111110 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* Width.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%20b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* Width given as argument.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%*b %d", 20, 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "      11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* Negative width given as argument (cf. FLAG_LEFT below).  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%*b %d", -20, 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* FLAG_LEFT.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%-20b %d", 12345, 33, 44, 55);
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "11000000111001       33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT with zero.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%#b %d", 0, 33, 44, 55);
+    ASSERT (strcmp (result, "0 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
+
+  { /* FLAG_ALT with a positive number.  */
+    char *result;
+    int retval =
+      my_asprintf (&result, "%#b %d", 12345, 33, 44, 55);
+    ASSERT (strcmp (result, "0b11000000111001 33") == 0);
+    ASSERT (retval == strlen (result));
+    free (result);
+  }
 }
 
 static int
-- 
2.34.1

Reply via email to