diff options
author | Joseph Myers <joseph@codesourcery.com> | 2023-03-02 19:10:37 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2023-03-02 19:10:37 +0000 |
commit | dee2bea048b688b643a9a3b44b26ca9f7a706fe8 (patch) | |
tree | 3e7cd1057154850968d13023bc2e082cfc7940ad /libio/stdio.h | |
parent | 51aeab9a363a0d000d0912aa3d6490463a26fba2 (diff) | |
download | glibc-dee2bea048b688b643a9a3b44b26ca9f7a706fe8.tar glibc-dee2bea048b688b643a9a3b44b26ca9f7a706fe8.tar.gz glibc-dee2bea048b688b643a9a3b44b26ca9f7a706fe8.tar.bz2 glibc-dee2bea048b688b643a9a3b44b26ca9f7a706fe8.zip |
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.
Diffstat (limited to 'libio/stdio.h')
-rw-r--r-- | libio/stdio.h | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/libio/stdio.h b/libio/stdio.h index ed80420a2b..857f02888d 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -430,7 +430,28 @@ extern int sscanf (const char *__restrict __s, #include <bits/floatn.h> #if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \ && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0 -# ifdef __REDIRECT +# if __GLIBC_USE (C2X_STRTOL) +# ifdef __REDIRECT +extern int __REDIRECT (fscanf, (FILE *__restrict __stream, + const char *__restrict __format, ...), + __isoc23_fscanf) __wur; +extern int __REDIRECT (scanf, (const char *__restrict __format, ...), + __isoc23_scanf) __wur; +extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s, + const char *__restrict __format, ...), + __isoc23_sscanf); +# else +extern int __isoc23_fscanf (FILE *__restrict __stream, + const char *__restrict __format, ...) __wur; +extern int __isoc23_scanf (const char *__restrict __format, ...) __wur; +extern int __isoc23_sscanf (const char *__restrict __s, + const char *__restrict __format, ...) __THROW; +# define fscanf __isoc23_fscanf +# define scanf __isoc23_scanf +# define sscanf __isoc23_sscanf +# endif +# else +# ifdef __REDIRECT extern int __REDIRECT (fscanf, (FILE *__restrict __stream, const char *__restrict __format, ...), __isoc99_fscanf) __wur; @@ -439,15 +460,16 @@ extern int __REDIRECT (scanf, (const char *__restrict __format, ...), extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s, const char *__restrict __format, ...), __isoc99_sscanf); -# else +# else extern int __isoc99_fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __wur; extern int __isoc99_scanf (const char *__restrict __format, ...) __wur; extern int __isoc99_sscanf (const char *__restrict __s, const char *__restrict __format, ...) __THROW; -# define fscanf __isoc99_fscanf -# define scanf __isoc99_scanf -# define sscanf __isoc99_sscanf +# define fscanf __isoc99_fscanf +# define scanf __isoc99_scanf +# define sscanf __isoc99_sscanf +# endif # endif #endif @@ -474,7 +496,37 @@ extern int vsscanf (const char *__restrict __s, /* Same redirection as above for the v*scanf family. */ # if !__GLIBC_USE (DEPRECATED_SCANF) -# if defined __REDIRECT && !defined __LDBL_COMPAT \ +# if __GLIBC_USE (C2X_STRTOL) +# if defined __REDIRECT && !defined __LDBL_COMPAT \ + && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0 +extern int __REDIRECT (vfscanf, + (FILE *__restrict __s, + const char *__restrict __format, __gnuc_va_list __arg), + __isoc23_vfscanf) + __attribute__ ((__format__ (__scanf__, 2, 0))) __wur; +extern int __REDIRECT (vscanf, (const char *__restrict __format, + __gnuc_va_list __arg), __isoc23_vscanf) + __attribute__ ((__format__ (__scanf__, 1, 0))) __wur; +extern int __REDIRECT_NTH (vsscanf, + (const char *__restrict __s, + const char *__restrict __format, + __gnuc_va_list __arg), __isoc23_vsscanf) + __attribute__ ((__format__ (__scanf__, 2, 0))); +# elif !defined __REDIRECT +extern int __isoc23_vfscanf (FILE *__restrict __s, + const char *__restrict __format, + __gnuc_va_list __arg) __wur; +extern int __isoc23_vscanf (const char *__restrict __format, + __gnuc_va_list __arg) __wur; +extern int __isoc23_vsscanf (const char *__restrict __s, + const char *__restrict __format, + __gnuc_va_list __arg) __THROW; +# define vfscanf __isoc23_vfscanf +# define vscanf __isoc23_vscanf +# define vsscanf __isoc23_vsscanf +# endif +# else +# if defined __REDIRECT && !defined __LDBL_COMPAT \ && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0 extern int __REDIRECT (vfscanf, (FILE *__restrict __s, @@ -489,7 +541,7 @@ extern int __REDIRECT_NTH (vsscanf, const char *__restrict __format, __gnuc_va_list __arg), __isoc99_vsscanf) __attribute__ ((__format__ (__scanf__, 2, 0))); -# elif !defined __REDIRECT +# elif !defined __REDIRECT extern int __isoc99_vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __wur; @@ -498,9 +550,10 @@ extern int __isoc99_vscanf (const char *__restrict __format, extern int __isoc99_vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __THROW; -# define vfscanf __isoc99_vfscanf -# define vscanf __isoc99_vscanf -# define vsscanf __isoc99_vsscanf +# define vfscanf __isoc99_vfscanf +# define vscanf __isoc99_vscanf +# define vsscanf __isoc99_vsscanf +# endif # endif # endif #endif /* Use ISO C9x. */ |