glibc/wcsmbs
Joseph Myers 309548bec3 Support C2X printf %b, %B
C2X adds a printf %b format (see
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2630.pdf>, accepted
for C2X), for outputting integers in binary.  It also has recommended
practice for a corresponding %B format (like %b, but %#B starts the
output with 0B instead of 0b).  Add support for these formats to
glibc.

One existing test uses %b as an example of an unknown format, to test
how glibc printf handles unknown formats; change that to %v.  Use of
%b and %B as user-registered format specifiers continues to work (and
we already have a test that covers that, tst-printfsz.c).

Note that C2X also has scanf %b support, plus support for binary
constants starting 0b in strtol (base 0 and 2) and scanf %i (strtol
base 0 and scanf %i coming from a previous paper that added binary
integer literals).  I intend to implement those features in a separate
patch or patches; as discussed in the thread starting at
<https://sourceware.org/pipermail/libc-alpha/2020-December/120414.html>,
they will be more complicated because they involve adding extra public
symbols to ensure compatibility with existing code that might not
expect 0b constants to be handled by strtol base 0 and 2 and scanf %i,
whereas simply adding a new format specifier poses no such
compatibility concerns.

Note that the actual conversion from integer to string uses existing
code in _itoa.c.  That code has special cases for bases 8, 10 and 16,
probably so that the compiler can optimize division by an integer
constant in the code for those bases.  If desired such special cases
could easily be added for base 2 as well, but that would be an
optimization, not actually needed for these printf formats to work.

Tested for x86_64 and x86.  Also tested with build-many-glibcs.py for
aarch64-linux-gnu with GCC mainline to make sure that the test does
indeed build with GCC 12 (where format checking warnings are enabled
for most of the test).
2021-11-10 15:52:21 +00:00
..
bits Make sure that the fortified function conditionals are constant 2021-10-20 18:12:41 +05:30
btowc.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
c16rtomb.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
c32rtomb.c
Depend
isoc99_fwscanf.c
isoc99_swscanf.c
isoc99_vfwscanf.c
isoc99_vswscanf.c
isoc99_vwscanf.c
isoc99_wscanf.c
Makefile Support C2X printf %b, %B 2021-11-10 15:52:21 +00:00
mbrlen.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
mbrtoc16.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
mbrtoc32.c
mbrtowc.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
mbsinit.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
mbsnrtowcs.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
mbsrtowcs_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
mbsrtowcs.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
test-char-types.c
test-wcpcpy.c
test-wcpncpy.c
test-wcscat.c
test-wcschr.c
test-wcschrnul.c
test-wcscmp.c
test-wcscpy.c
test-wcscspn.c
test-wcslen.c
test-wcsncat.c
test-wcsncmp.c
test-wcsncpy.c
test-wcsnlen.c
test-wcspbrk.c
test-wcsrchr.c
test-wcsspn.c
test-wmemchr.c
test-wmemcmp.c
test-wmemset.c
tst-btowc.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
tst-c16-surrogate.c
tst-c16c32-1.c
tst-c32-state.c
tst-fgetwc-after-eof.c
tst-mbrtowc2.c
tst-mbrtowc.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
tst-mbsrtowcs.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
tst-mbstowcs.c
tst-wchar-h.c
tst-wcpncpy.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
tst-wcrtomb.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
tst-wcsnlen.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
tst-wcstod-nan-locale.c
tst-wcstod-nan-sign.c
tst-wcstod-round.c
tst-wcstof.c
tst-wcstol-locale.c
tst-wprintf-binary.c Support C2X printf %b, %B 2021-11-10 15:52:21 +00:00
uchar.h
Versions
wchar.h Enable support for GCC 11 -Wmismatched-dealloc. 2021-05-16 15:21:18 -06:00
wcpcpy.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcpncpy.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcrtomb.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsatcliff.c
wcscasecmp_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcscasecmp.c
wcscat.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcschr.c
wcschrnul.c
wcscmp.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcscoll_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcscoll.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcscpy.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcscspn.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsdup.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcslen.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsmbs-tst1.c
wcsmbsload.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsmbsload.h Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsncase_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsncase.c
wcsncat.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsncmp.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsncpy.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsnlen.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsnrtombs.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcspbrk.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsrchr.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsrtombs.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsspn.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsstr.c
wcstod_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstod_nan.c
wcstod.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstof_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstof_nan.c
wcstof.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstok.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstol_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstol.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstold_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstold_nan.c
wcstold.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstoll_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstoll.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstoul_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstoul.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstoull_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstoull.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcswidth.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsxfrm_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcsxfrm.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wctob.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcwidth.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcwidth.h Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wmemchr.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wmemcmp.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wmemcpy.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wmemmove.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wmempcpy.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wmemset.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30