1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-07 06:43:00 +03:00

C2x scanf %b support

ISO C2x defines scanf %b for input of binary integers (with an
optional 0b or 0B prefix).  Implement such support, along with the
corresponding SCNb* macros in <inttypes.h>.  Unlike the support for
binary integers with 0b or 0B prefix with scanf %i, this is supported
in all versions of scanf (independent of the standards mode used for
compilation), because there are no backwards compatibility concerns
(%b wasn't previously a supported format) the way there were for %i.

Tested for x86_64 and x86.
This commit is contained in:
Joseph Myers
2023-06-19 19:40:34 +00:00
parent 5f83b2674e
commit 2d88df5411
5 changed files with 248 additions and 9 deletions

View File

@@ -1381,6 +1381,10 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
base = 8;
goto number;
case L_('b'): /* Binary integer. */
base = 2;
goto number;
case L_('u'): /* Unsigned decimal integer. */
base = 10;
goto number;
@@ -1428,10 +1432,11 @@ __vfscanf_internal (FILE *s, const char *format, va_list argptr,
c = inchar ();
}
}
else if ((mode_flags & SCANF_ISOC23_BIN_CST) != 0
&& base == 0
&& width != 0
&& TOLOWER (c) == L_('b'))
else if (width != 0
&& TOLOWER (c) == L_('b')
&& (base == 2
|| ((mode_flags & SCANF_ISOC23_BIN_CST) != 0
&& base == 0)))
{
base = 2;
if (width > 0)