about summary refs log tree commit diff
path: root/wcsmbs/wchar.h
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2023-03-02 19:10:37 +0000
committerJoseph Myers <joseph@codesourcery.com>2023-03-02 19:10:37 +0000
commitdee2bea048b688b643a9a3b44b26ca9f7a706fe8 (patch)
tree3e7cd1057154850968d13023bc2e082cfc7940ad /wcsmbs/wchar.h
parent51aeab9a363a0d000d0912aa3d6490463a26fba2 (diff)
downloadglibc-dee2bea048b688b643a9a3b44b26ca9f7a706fe8.tar.gz
glibc-dee2bea048b688b643a9a3b44b26ca9f7a706fe8.tar.xz
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 'wcsmbs/wchar.h')
-rw-r--r--wcsmbs/wchar.h76
1 files changed, 65 insertions, 11 deletions
diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index cde0d32b0a..7ab99ba93b 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -762,9 +762,34 @@ extern int swscanf (const wchar_t *__restrict __s,
    functions are at alternative names.  When __LDBL_COMPAT or
    __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI are in effect, this is handled in
    bits/wchar-ldbl.h.  */
-#if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \
+# 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 (fwscanf, (__FILE *__restrict __stream,
+				 const wchar_t *__restrict __format, ...),
+		       __isoc23_fwscanf)
+     /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
+extern int __REDIRECT (wscanf, (const wchar_t *__restrict __format, ...),
+		       __isoc23_wscanf)
+     /* __attribute__ ((__format__ (__wscanf__, 1, 2))) */;
+extern int __REDIRECT_NTH (swscanf, (const wchar_t *__restrict __s,
+				     const wchar_t *__restrict __format,
+				     ...), __isoc23_swscanf)
+     /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
+#   else
+extern int __isoc23_fwscanf (__FILE *__restrict __stream,
+			     const wchar_t *__restrict __format, ...);
+extern int __isoc23_wscanf (const wchar_t *__restrict __format, ...);
+extern int __isoc23_swscanf (const wchar_t *__restrict __s,
+			     const wchar_t *__restrict __format, ...)
+     __THROW;
+#    define fwscanf __isoc23_fwscanf
+#    define wscanf __isoc23_wscanf
+#    define swscanf __isoc23_swscanf
+#   endif
+#  else
+#   ifdef __REDIRECT
 extern int __REDIRECT (fwscanf, (__FILE *__restrict __stream,
 				 const wchar_t *__restrict __format, ...),
 		       __isoc99_fwscanf)
@@ -776,16 +801,17 @@ extern int __REDIRECT_NTH (swscanf, (const wchar_t *__restrict __s,
 				     const wchar_t *__restrict __format,
 				     ...), __isoc99_swscanf)
      /* __attribute__ ((__format__ (__wscanf__, 2, 3))) */;
-#  else
+#   else
 extern int __isoc99_fwscanf (__FILE *__restrict __stream,
 			     const wchar_t *__restrict __format, ...);
 extern int __isoc99_wscanf (const wchar_t *__restrict __format, ...);
 extern int __isoc99_swscanf (const wchar_t *__restrict __s,
 			     const wchar_t *__restrict __format, ...)
      __THROW;
-#   define fwscanf __isoc99_fwscanf
-#   define wscanf __isoc99_wscanf
-#   define swscanf __isoc99_swscanf
+#    define fwscanf __isoc99_fwscanf
+#    define wscanf __isoc99_wscanf
+#    define swscanf __isoc99_swscanf
+#   endif
 #  endif
 # endif
 
@@ -818,7 +844,34 @@ extern int vswscanf (const wchar_t *__restrict __s,
      && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
      && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K) \
      && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
-#  ifdef __REDIRECT
+#  if __GLIBC_USE (C2X_STRTOL)
+#   ifdef __REDIRECT
+extern int __REDIRECT (vfwscanf, (__FILE *__restrict __s,
+				  const wchar_t *__restrict __format,
+				  __gnuc_va_list __arg), __isoc23_vfwscanf)
+     /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
+extern int __REDIRECT (vwscanf, (const wchar_t *__restrict __format,
+				 __gnuc_va_list __arg), __isoc23_vwscanf)
+     /* __attribute__ ((__format__ (__wscanf__, 1, 0))) */;
+extern int __REDIRECT_NTH (vswscanf, (const wchar_t *__restrict __s,
+				      const wchar_t *__restrict __format,
+				      __gnuc_va_list __arg), __isoc23_vswscanf)
+     /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
+#   else
+extern int __isoc23_vfwscanf (__FILE *__restrict __s,
+			      const wchar_t *__restrict __format,
+			      __gnuc_va_list __arg);
+extern int __isoc23_vwscanf (const wchar_t *__restrict __format,
+			     __gnuc_va_list __arg);
+extern int __isoc23_vswscanf (const wchar_t *__restrict __s,
+			      const wchar_t *__restrict __format,
+			      __gnuc_va_list __arg) __THROW;
+#    define vfwscanf __isoc23_vfwscanf
+#    define vwscanf __isoc23_vwscanf
+#    define vswscanf __isoc23_vswscanf
+#   endif
+#  else
+#   ifdef __REDIRECT
 extern int __REDIRECT (vfwscanf, (__FILE *__restrict __s,
 				  const wchar_t *__restrict __format,
 				  __gnuc_va_list __arg), __isoc99_vfwscanf)
@@ -830,7 +883,7 @@ extern int __REDIRECT_NTH (vswscanf, (const wchar_t *__restrict __s,
 				      const wchar_t *__restrict __format,
 				      __gnuc_va_list __arg), __isoc99_vswscanf)
      /* __attribute__ ((__format__ (__wscanf__, 2, 0))) */;
-#  else
+#   else
 extern int __isoc99_vfwscanf (__FILE *__restrict __s,
 			      const wchar_t *__restrict __format,
 			      __gnuc_va_list __arg);
@@ -839,9 +892,10 @@ extern int __isoc99_vwscanf (const wchar_t *__restrict __format,
 extern int __isoc99_vswscanf (const wchar_t *__restrict __s,
 			      const wchar_t *__restrict __format,
 			      __gnuc_va_list __arg) __THROW;
-#   define vfwscanf __isoc99_vfwscanf
-#   define vwscanf __isoc99_vwscanf
-#   define vswscanf __isoc99_vswscanf
+#    define vfwscanf __isoc99_vfwscanf
+#    define vwscanf __isoc99_vwscanf
+#    define vswscanf __isoc99_vswscanf
+#   endif
 #  endif
 # endif