From dee2bea048b688b643a9a3b44b26ca9f7a706fe8 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Thu, 2 Mar 2023 19:10:37 +0000 Subject: C2x scanf binary constant handling C2x adds binary integer constants starting with 0b or 0B, and supports those constants for the %i scanf format (in addition to the %b format, which isn't yet implemented for scanf in glibc). Implement that scanf support for glibc. As with the strtol support, this is incompatible with previous C standard versions, in that such an input string starting with 0b or 0B was previously required to be parsed as 0 (with the rest of the input potentially matching subsequent parts of the scanf format string). Thus this patch adds 12 new __isoc23_* functions per long double format (12, 24 or 36 depending on how many long double formats the glibc configuration supports), with appropriate header redirection support (generally very closely following that for the __isoc99_* scanf functions - note that __GLIBC_USE (DEPRECATED_SCANF) takes precedence over __GLIBC_USE (C2X_STRTOL), so the case of GNU extensions to C89 continues to get old-style GNU %a and does not get this new feature). The function names would remain as __isoc23_* even if C2x ends up published in 2024 rather than 2023. When scanf %b support is added, I think it will be appropriate for all versions of scanf to follow C2x rules for inputs to the %b format (given that there are no compatibility concerns for a new format). Tested for x86_64 (full glibc testsuite). The first version was also tested for powerpc (32-bit) and powerpc64le (stdio-common/ and wcsmbs/ tests), and with build-many-glibcs.py. --- libio/libioP.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'libio/libioP.h') diff --git a/libio/libioP.h b/libio/libioP.h index a5f0082..3850738 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -781,6 +781,9 @@ extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int) functions use. When the flag is set to zero, automatic allocation is enabled. + SCANF_ISOC23_BIN_CST, when set to one, indicates the %i accepts + binary constants starting 0b or 0B. + SCANF_LDBL_USES_FLOAT128 is used on platforms where the long double format used to be different from the IEC 60559 double format *and* also different from the Quadruple 128-bits IEC 60559 format (such as @@ -793,7 +796,8 @@ extern off64_t _IO_seekpos_unlocked (FILE *, off64_t, int) as the previous format on that platform. */ #define SCANF_LDBL_IS_DBL 0x0001 #define SCANF_ISOC99_A 0x0002 -#define SCANF_LDBL_USES_FLOAT128 0x0004 +#define SCANF_ISOC23_BIN_CST 0x0004 +#define SCANF_LDBL_USES_FLOAT128 0x0008 extern int __vfscanf_internal (FILE *fp, const char *format, va_list argp, unsigned int flags) -- cgit v1.1