aboutsummaryrefslogtreecommitdiff
path: root/stdio-common
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/Makefile22
-rw-r--r--stdio-common/Versions8
-rw-r--r--stdio-common/isoc23_fscanf.c35
-rw-r--r--stdio-common/isoc23_scanf.c35
-rw-r--r--stdio-common/isoc23_sscanf.c37
-rw-r--r--stdio-common/isoc23_vfscanf.c28
-rw-r--r--stdio-common/isoc23_vscanf.c27
-rw-r--r--stdio-common/isoc23_vsscanf.c28
-rw-r--r--stdio-common/tst-scanf-binary-c11.c28
-rw-r--r--stdio-common/tst-scanf-binary-c2x.c31
-rw-r--r--stdio-common/tst-scanf-binary-gnu11.c26
-rw-r--r--stdio-common/tst-scanf-binary-gnu89.c26
-rw-r--r--stdio-common/tst-scanf-binary-main.c189
-rw-r--r--stdio-common/vfscanf-internal.c10
14 files changed, 530 insertions, 0 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 92a3499a94..a14ee487ea 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -47,6 +47,12 @@ routines := \
isoc99_vfscanf \
isoc99_vscanf \
isoc99_vsscanf \
+ isoc23_fscanf \
+ isoc23_scanf \
+ isoc23_sscanf \
+ isoc23_vfscanf \
+ isoc23_vscanf \
+ isoc23_vsscanf \
itoa-digits \
itoa-udigits \
itowa-digits \
@@ -214,6 +220,10 @@ tests := \
tst-put-error \
tst-renameat2 \
tst-rndseek \
+ tst-scanf-binary-c11 \
+ tst-scanf-binary-c2x \
+ tst-scanf-binary-gnu11 \
+ tst-scanf-binary-gnu89 \
tst-scanf-round \
tst-setvbuf1 \
tst-sprintf \
@@ -415,6 +425,10 @@ CFLAGS-isoc99_vfscanf.c += -fexceptions
CFLAGS-isoc99_vscanf.c += -fexceptions
CFLAGS-isoc99_fscanf.c += -fexceptions
CFLAGS-isoc99_scanf.c += -fexceptions
+CFLAGS-isoc23_vfscanf.c += -fexceptions
+CFLAGS-isoc23_vscanf.c += -fexceptions
+CFLAGS-isoc23_fscanf.c += -fexceptions
+CFLAGS-isoc23_scanf.c += -fexceptions
CFLAGS-dprintf.c += $(config-cflags-wno-ignored-attributes)
@@ -440,6 +454,14 @@ CFLAGS-tst-bz11319-fortify2.c += -D_FORTIFY_SOURCE=2
CFLAGS-tst-memstream-string.c += -fno-builtin-fprintf
+# Some versions of GCC supported for building glibc do not support -std=c2x, so
+# the test for that version uses -std=c11 and then _ISOC2X_SOURCE is defined in
+# the test as needed.
+CFLAGS-tst-scanf-binary-c11.c += -std=c11 -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-scanf-binary-c2x.c += -std=c11 -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-scanf-binary-gnu11.c += -std=gnu11 -DOBJPFX=\"$(objpfx)\"
+CFLAGS-tst-scanf-binary-gnu89.c += -std=gnu89 -DOBJPFX=\"$(objpfx)\"
+
CPPFLAGS += $(libio-mtsafe)
$(objpfx)tst-setvbuf1.out: /dev/null $(objpfx)tst-setvbuf1
diff --git a/stdio-common/Versions b/stdio-common/Versions
index 522f302198..4bcfc3fb41 100644
--- a/stdio-common/Versions
+++ b/stdio-common/Versions
@@ -63,6 +63,14 @@ libc {
GLIBC_2.29 {
# SHLIB_COMPAT(GLIBC_2_0, GLIBC_2_29) used in iovfscanf.c etc.
}
+ GLIBC_2.38 {
+ __isoc23_scanf;
+ __isoc23_vscanf;
+ __isoc23_fscanf;
+ __isoc23_vfscanf;
+ __isoc23_sscanf;
+ __isoc23_vsscanf;
+ }
GLIBC_PRIVATE {
# global variables
_itoa_lower_digits;
diff --git a/stdio-common/isoc23_fscanf.c b/stdio-common/isoc23_fscanf.c
new file mode 100644
index 0000000000..dc19f57bec
--- /dev/null
+++ b/stdio-common/isoc23_fscanf.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <libioP.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+/* Read formatted input from STREAM according to the format string FORMAT. */
+int
+__isoc23_fscanf (FILE *stream, const char *format, ...)
+{
+ va_list arg;
+ int done;
+
+ va_start (arg, format);
+ done = __vfscanf_internal (stream, format, arg,
+ SCANF_ISOC99_A | SCANF_ISOC23_BIN_CST);
+ va_end (arg);
+
+ return done;
+}
diff --git a/stdio-common/isoc23_scanf.c b/stdio-common/isoc23_scanf.c
new file mode 100644
index 0000000000..22b5aaebda
--- /dev/null
+++ b/stdio-common/isoc23_scanf.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <libioP.h>
+
+/* Read formatted input from stdin according to the format string FORMAT. */
+int
+__isoc23_scanf (const char *format, ...)
+{
+ va_list arg;
+ int done;
+
+ va_start (arg, format);
+ done = __vfscanf_internal (stdin, format, arg,
+ SCANF_ISOC99_A | SCANF_ISOC23_BIN_CST);
+ va_end (arg);
+
+ return done;
+}
diff --git a/stdio-common/isoc23_sscanf.c b/stdio-common/isoc23_sscanf.c
new file mode 100644
index 0000000000..1da4c53846
--- /dev/null
+++ b/stdio-common/isoc23_sscanf.c
@@ -0,0 +1,37 @@
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdarg.h>
+#include <libio/strfile.h>
+
+/* Read formatted input from S, according to the format string FORMAT. */
+int
+__isoc23_sscanf (const char *s, const char *format, ...)
+{
+ va_list arg;
+ int done;
+ _IO_strfile sf;
+ FILE *f = _IO_strfile_read (&sf, s);
+
+ va_start (arg, format);
+ done = __vfscanf_internal (f, format, arg,
+ SCANF_ISOC99_A | SCANF_ISOC23_BIN_CST);
+ va_end (arg);
+
+ return done;
+}
+libc_hidden_def (__isoc23_sscanf)
diff --git a/stdio-common/isoc23_vfscanf.c b/stdio-common/isoc23_vfscanf.c
new file mode 100644
index 0000000000..d1411a2d65
--- /dev/null
+++ b/stdio-common/isoc23_vfscanf.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <libioP.h>
+#include <stdio.h>
+
+/* Read formatted input from STREAM according to the format string FORMAT. */
+int
+__isoc23_vfscanf (FILE *stream, const char *format, va_list args)
+{
+ return __vfscanf_internal (stream, format, args,
+ SCANF_ISOC99_A | SCANF_ISOC23_BIN_CST);
+}
+libc_hidden_def (__isoc23_vfscanf)
diff --git a/stdio-common/isoc23_vscanf.c b/stdio-common/isoc23_vscanf.c
new file mode 100644
index 0000000000..81be184c3b
--- /dev/null
+++ b/stdio-common/isoc23_vscanf.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <libioP.h>
+#include <stdio.h>
+
+/* Read formatted input from STDIN according to the format string FORMAT. */
+int
+__isoc23_vscanf (const char *format, va_list args)
+{
+ return __vfscanf_internal (stdin, format, args,
+ SCANF_ISOC99_A | SCANF_ISOC23_BIN_CST);
+}
diff --git a/stdio-common/isoc23_vsscanf.c b/stdio-common/isoc23_vsscanf.c
new file mode 100644
index 0000000000..6cc9a89edc
--- /dev/null
+++ b/stdio-common/isoc23_vsscanf.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1993-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <libio/strfile.h>
+
+int
+__isoc23_vsscanf (const char *string, const char *format, va_list args)
+{
+ _IO_strfile sf;
+ FILE *f = _IO_strfile_read (&sf, string);
+ return __vfscanf_internal (f, format, args,
+ SCANF_ISOC99_A | SCANF_ISOC23_BIN_CST);
+}
+libc_hidden_def (__isoc23_vsscanf)
diff --git a/stdio-common/tst-scanf-binary-c11.c b/stdio-common/tst-scanf-binary-c11.c
new file mode 100644
index 0000000000..1869bb6881
--- /dev/null
+++ b/stdio-common/tst-scanf-binary-c11.c
@@ -0,0 +1,28 @@
+/* Test scanf functions with C2X binary integers (narrow strings,
+ no extensions to C11).
+ Copyright (C) 2022-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#undef _GNU_SOURCE
+
+#define CHAR char
+#define FNW
+#define L_(C) C
+#define TEST_C2X 0
+#define STD "c11"
+
+#include <tst-scanf-binary-main.c>
diff --git a/stdio-common/tst-scanf-binary-c2x.c b/stdio-common/tst-scanf-binary-c2x.c
new file mode 100644
index 0000000000..6033b1f375
--- /dev/null
+++ b/stdio-common/tst-scanf-binary-c2x.c
@@ -0,0 +1,31 @@
+/* Test scanf functions with C2X binary integers (narrow strings,
+ no extensions).
+ Copyright (C) 2022-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+/* Some versions of GCC supported for building glibc do not support
+ -std=c2x. */
+#undef _GNU_SOURCE
+#define _ISOC2X_SOURCE
+
+#define CHAR char
+#define FNW
+#define L_(C) C
+#define TEST_C2X 1
+#define STD "c2x"
+
+#include <tst-scanf-binary-main.c>
diff --git a/stdio-common/tst-scanf-binary-gnu11.c b/stdio-common/tst-scanf-binary-gnu11.c
new file mode 100644
index 0000000000..4bd49700d7
--- /dev/null
+++ b/stdio-common/tst-scanf-binary-gnu11.c
@@ -0,0 +1,26 @@
+/* Test scanf functions with C2X binary integers (narrow strings,
+ GNU extensions to C11).
+ Copyright (C) 2022-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define CHAR char
+#define FNW
+#define L_(C) C
+#define TEST_C2X 1
+#define STD "gnu11"
+
+#include <tst-scanf-binary-main.c>
diff --git a/stdio-common/tst-scanf-binary-gnu89.c b/stdio-common/tst-scanf-binary-gnu89.c
new file mode 100644
index 0000000000..5325732f7c
--- /dev/null
+++ b/stdio-common/tst-scanf-binary-gnu89.c
@@ -0,0 +1,26 @@
+/* Test scanf functions with C2X binary integers (narrow strings,
+ GNU extensions to C89).
+ Copyright (C) 2022-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#define CHAR char
+#define FNW
+#define L_(C) C
+#define TEST_C2X 0
+#define STD "gnu89"
+
+#include <tst-scanf-binary-main.c>
diff --git a/stdio-common/tst-scanf-binary-main.c b/stdio-common/tst-scanf-binary-main.c
new file mode 100644
index 0000000000..6b75cb32e5
--- /dev/null
+++ b/stdio-common/tst-scanf-binary-main.c
@@ -0,0 +1,189 @@
+/* Test scanf functions with C2X binary integers.
+ Copyright (C) 2022-2023 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <wchar.h>
+
+#include <support/check.h>
+#include <support/xstdio.h>
+
+#define CONCAT_(X, Y, Z) X ## Y ## Z
+#define CONCAT(X, Y, Z) CONCAT_ (X, Y, Z)
+#define FNX(FN1, FN2) CONCAT (FN1, FNW, FN2)
+#ifndef STDX
+# define STDX ""
+#endif
+
+#define INFILE OBJPFX "/tst-" STDX "scanf-binary-" STD "-in"
+
+static int
+wrap_vfscanf (FILE *fp, const CHAR *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ int ret = FNX (vf, scanf) (fp, format, ap);
+ va_end (ap);
+ return ret;
+}
+
+static int
+wrap_vscanf (const CHAR *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ int ret = FNX (v, scanf) (format, ap);
+ va_end (ap);
+ return ret;
+}
+
+static int
+wrap_vsscanf (const CHAR *s, const CHAR *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ int ret = FNX (vs, scanf) (s, format, ap);
+ va_end (ap);
+ return ret;
+}
+
+static void
+one_check (const CHAR *s, int expected, char expected_c)
+{
+ int ret;
+ FILE *fp;
+ int ret_i;
+ long int ret_l;
+ long long int ret_ll;
+ char ret_c;
+ fp = xfopen (INFILE, "w");
+ ret = FNX (fput, s) (s, fp);
+ TEST_VERIFY_EXIT (0 <= ret);
+ xfclose (fp);
+
+ if (!TEST_C2X)
+ {
+ expected = 0;
+ expected_c = s[0] == L_('-') ? s[2] : s[1];
+ }
+
+ ret = FNX (s, scanf) (s, L_("%i %c"), &ret_i, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_i, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ fp = xfopen (INFILE, "r");
+ ret = FNX (f, scanf) (fp, L_("%i %c"), &ret_i, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_i, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ xfclose (fp);
+ fp = xfreopen (INFILE, "r", stdin);
+ ret = FNX (, scanf) (L_("%i %c"), &ret_i, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_i, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ ret = wrap_vsscanf (s, L_("%i %c"), &ret_i, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_i, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ fp = xfopen (INFILE, "r");
+ ret = wrap_vfscanf (fp, L_("%i %c"), &ret_i, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_i, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ xfclose (fp);
+ fp = xfreopen (INFILE, "r", stdin);
+ ret = wrap_vscanf (L_("%i %c"), &ret_i, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_i, expected);
+ TEST_COMPARE (ret_c, expected_c);
+
+ ret = FNX (s, scanf) (s, L_("%li %c"), &ret_l, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_l, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ fp = xfopen (INFILE, "r");
+ ret = FNX (f, scanf) (fp, L_("%li %c"), &ret_l, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_l, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ xfclose (fp);
+ fp = xfreopen (INFILE, "r", stdin);
+ ret = FNX (, scanf) (L_("%li %c"), &ret_l, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_l, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ ret = wrap_vsscanf (s, L_("%li %c"), &ret_l, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_l, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ fp = xfopen (INFILE, "r");
+ ret = wrap_vfscanf (fp, L_("%li %c"), &ret_l, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_l, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ xfclose (fp);
+ fp = xfreopen (INFILE, "r", stdin);
+ ret = wrap_vscanf (L_("%li %c"), &ret_l, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_l, expected);
+ TEST_COMPARE (ret_c, expected_c);
+
+ ret = FNX (s, scanf) (s, L_("%lli %c"), &ret_ll, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_ll, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ fp = xfopen (INFILE, "r");
+ ret = FNX (f, scanf) (fp, L_("%lli %c"), &ret_ll, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_ll, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ xfclose (fp);
+ fp = xfreopen (INFILE, "r", stdin);
+ ret = FNX (, scanf) (L_("%lli %c"), &ret_ll, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_ll, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ ret = wrap_vsscanf (s, L_("%lli %c"), &ret_ll, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_ll, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ fp = xfopen (INFILE, "r");
+ ret = wrap_vfscanf (fp, L_("%lli %c"), &ret_ll, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_ll, expected);
+ TEST_COMPARE (ret_c, expected_c);
+ xfclose (fp);
+ fp = xfreopen (INFILE, "r", stdin);
+ ret = wrap_vscanf (L_("%lli %c"), &ret_ll, &ret_c);
+ TEST_COMPARE (ret, 2);
+ TEST_COMPARE (ret_ll, expected);
+ TEST_COMPARE (ret_c, expected_c);
+}
+
+static int
+do_test (void)
+{
+ one_check (L_("0b101 x"), 5, 'x');
+ one_check (L_("0B101 x"), 5, 'x');
+ one_check (L_("-0b11111 y"), -31, 'y');
+ one_check (L_("-0B11111 y"), -31, 'y');
+ return 0;
+}
+
+#include <support/test-driver.c>
diff --git a/stdio-common/vfscanf-internal.c b/stdio-common/vfscanf-internal.c
index 4fec12345c..d9675bd4b1 100644
--- a/stdio-common/vfscanf-internal.c
+++ b/stdio-common/vfscanf-internal.c
@@ -1428,6 +1428,16 @@ __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'))
+ {
+ base = 2;
+ if (width > 0)
+ --width;
+ c = inchar ();
+ }
else if (base == 0)
base = 8;
}