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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
Depend
isoc99_fwscanf.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
isoc99_swscanf.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
isoc99_vfwscanf.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
isoc99_vswscanf.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
isoc99_vwscanf.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
isoc99_wscanf.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcpcpy.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcpncpy.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcscat.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcschr.c
test-wcschrnul.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcscmp.c
test-wcscpy.c
test-wcscspn.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcslen.c
test-wcsncat.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcsncmp.c
test-wcsncpy.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcsnlen.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcspbrk.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wcsrchr.c
test-wcsspn.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wmemchr.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
test-wmemcmp.c
test-wmemset.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-btowc.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
tst-c16-surrogate.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-c16c32-1.c
tst-c32-state.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-fgetwc-after-eof.c [BZ 1190] Make EOF sticky in stdio. 2018-03-13 08:31:56 -04:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-wcstod-nan-sign.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-wcstod-round.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-wcstof.c
tst-wcstol-locale.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
tst-wprintf-binary.c Support C2X printf %b, %B 2021-11-10 15:52:21 +00:00
uchar.h Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcscat.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcschr.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcschrnul.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
wcstod_l.c Remove "Contributed by" lines 2021-09-03 22:06:44 +05:30
wcstod_nan.c Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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 Update copyright dates with scripts/update-copyrights 2021-01-02 12:17:34 -08:00
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