about summary refs log tree commit diff
path: root/stdio-common/tst-printf-binary-main.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2023-03-14 16:58:35 +0000
committerJoseph Myers <joseph@codesourcery.com>2023-03-14 16:58:35 +0000
commit2d4728e60621c8844ec679291aa5458c622d8f4f (patch)
tree67fc945e60ec333a3c423ee634e5f5d242402824 /stdio-common/tst-printf-binary-main.c
parent447273e0bf22a3d42e05e6b16d309f3f89879bea (diff)
downloadglibc-2d4728e60621c8844ec679291aa5458c622d8f4f.tar.gz
glibc-2d4728e60621c8844ec679291aa5458c622d8f4f.tar.xz
glibc-2d4728e60621c8844ec679291aa5458c622d8f4f.zip
Update printf %b/%B C2x support
WG14 recently accepted two additions to the printf/scanf %b/%B
support: there are now PRIb* and SCNb* macros in <inttypes.h>, and
printf %B is now an optional feature defined in normative text,
instead of recommended practice, with corresponding PRIB* macros that
can also be used to test whether that optional feature is supported.
See N3072 items 14 and 15 for details (those changes were accepted,
some other changes in that paper weren't).

Add the corresponding PRI* macros to glibc and update one place in the
manual referring to %B as recommended.  (SCNb* should naturally be
added at the same time as the corresponding scanf %b support.)

Tested for x86_64 and x86.
Diffstat (limited to 'stdio-common/tst-printf-binary-main.c')
-rw-r--r--stdio-common/tst-printf-binary-main.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/stdio-common/tst-printf-binary-main.c b/stdio-common/tst-printf-binary-main.c
index e94b8b5959..0784368d85 100644
--- a/stdio-common/tst-printf-binary-main.c
+++ b/stdio-common/tst-printf-binary-main.c
@@ -16,6 +16,7 @@
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <inttypes.h>
 #include <limits.h>
 #include <stdio.h>
 #include <string.h>
@@ -77,6 +78,58 @@ do_test (void)
 		"10000111011001010100001100100001", "%lB",
 		0xfedcba9987654321ul);
 #endif
+  CHECK_PRINTF ("0b11", "%#" PRIb8, (uint8_t) 3);
+  CHECK_PRINTF ("0b11", "%#" PRIb16, (uint16_t) 3);
+  CHECK_PRINTF ("0b10000111011001010100001100100001", "%#" PRIb32,
+		(uint32_t) 0x87654321);
+  CHECK_PRINTF ("0b11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIb64,
+		(uint64_t) 0xfedcba9987654321ull);
+  CHECK_PRINTF ("0b11", "%#" PRIbLEAST8, (uint_least8_t) 3);
+  CHECK_PRINTF ("0b11", "%#" PRIbLEAST16, (uint_least16_t) 3);
+  CHECK_PRINTF ("0b10000111011001010100001100100001", "%#" PRIbLEAST32,
+		(uint_least32_t) 0x87654321);
+  CHECK_PRINTF ("0b11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIbLEAST64,
+		(uint_least64_t) 0xfedcba9987654321ull);
+  CHECK_PRINTF ("0b11", "%#" PRIbFAST8, (uint_fast8_t) 3);
+  CHECK_PRINTF ("0b11", "%#" PRIbFAST16, (uint_fast16_t) 3);
+  CHECK_PRINTF ("0b10000111011001010100001100100001", "%#" PRIbFAST32,
+		(uint_fast32_t) 0x87654321);
+  CHECK_PRINTF ("0b11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIbFAST64,
+		(uint_fast64_t) 0xfedcba9987654321ull);
+  CHECK_PRINTF ("0b10000111011001010100001100100001", "%#" PRIbPTR,
+		(uintptr_t) 0x87654321);
+  CHECK_PRINTF ("0b11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIbMAX,
+		(uintmax_t) 0xfedcba9987654321ull);
+  CHECK_PRINTF ("0B11", "%#" PRIB8, (uint8_t) 3);
+  CHECK_PRINTF ("0B11", "%#" PRIB16, (uint16_t) 3);
+  CHECK_PRINTF ("0B10000111011001010100001100100001", "%#" PRIB32,
+		(uint32_t) 0x87654321);
+  CHECK_PRINTF ("0B11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIB64,
+		(uint64_t) 0xfedcba9987654321ull);
+  CHECK_PRINTF ("0B11", "%#" PRIBLEAST8, (uint_least8_t) 3);
+  CHECK_PRINTF ("0B11", "%#" PRIBLEAST16, (uint_least16_t) 3);
+  CHECK_PRINTF ("0B10000111011001010100001100100001", "%#" PRIBLEAST32,
+		(uint_least32_t) 0x87654321);
+  CHECK_PRINTF ("0B11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIBLEAST64,
+		(uint_least64_t) 0xfedcba9987654321ull);
+  CHECK_PRINTF ("0B11", "%#" PRIBFAST8, (uint_fast8_t) 3);
+  CHECK_PRINTF ("0B11", "%#" PRIBFAST16, (uint_fast16_t) 3);
+  CHECK_PRINTF ("0B10000111011001010100001100100001", "%#" PRIBFAST32,
+		(uint_fast32_t) 0x87654321);
+  CHECK_PRINTF ("0B11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIBFAST64,
+		(uint_fast64_t) 0xfedcba9987654321ull);
+  CHECK_PRINTF ("0B10000111011001010100001100100001", "%#" PRIBPTR,
+		(uintptr_t) 0x87654321);
+  CHECK_PRINTF ("0B11111110110111001011101010011001"
+		"10000111011001010100001100100001", "%#" PRIBMAX,
+		(uintmax_t) 0xfedcba9987654321ull);
   CHECK_PRINTF (" 1010", "%5b", 10u);
   CHECK_PRINTF (" 1010", "%5B", 10u);
   CHECK_PRINTF ("01010", "%05b", 10u);