1 /* Copyright (C) 2008-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
24 #if __GLIBC_USE_DEPRECATED_SCANF
25 # error "This file should not be compiled with deprecated scanf"
31 printf ("test at line %d failed\n", __LINE__); \
34 static int __attribute__ ((format (scanf
, 2, 3)))
35 xsscanf (const char *str
, const char *fmt
, ...)
39 int ret
= vsscanf (str
, fmt
, ap
);
44 static int __attribute__ ((format (scanf
, 1, 2)))
45 xscanf (const char *fmt
, ...)
49 int ret
= vscanf (fmt
, ap
);
54 static int __attribute__ ((format (scanf
, 2, 3)))
55 xfscanf (FILE *f
, const char *fmt
, ...)
59 int ret
= vfscanf (f
, fmt
, ap
);
74 if (xsscanf (" 0.25s x", "%e%3c", &f
, c
) != 2)
76 else if (f
!= 0.25 || memcmp (c
, "s x", 3) != 0)
78 if (xsscanf (" 1.25s x", "%ms%2c", &sp
, c
) != 2)
82 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
84 memset (sp
, 'x', sizeof "1.25s");
87 if (xsscanf (" 2.25s x", "%las%2c", &d
, c
) != 2)
89 else if (d
!= 2.25 || memcmp (c
, " x", 2) != 0)
91 if (xsscanf (" 3.25S x", "%4mS%3c", &lsp
, c
) != 2)
95 if (wcscmp (lsp
, L
"3.25") != 0 || memcmp (c
, "S x", 3) != 0)
97 memset (lsp
, 'x', sizeof L
"3.25");
100 if (xsscanf ("4.25[0-9.] x", "%m[0-9.]%8c", &sp
, c
) != 2)
104 if (strcmp (sp
, "4.25") != 0 || memcmp (c
, "[0-9.] x", 8) != 0)
106 memset (sp
, 'x', sizeof "4.25");
109 if (xsscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d
, c
) != 2)
111 else if (d
!= 5.25 || memcmp (c
, " x", 2) != 0)
114 const char *tmpdir
= getenv ("TMPDIR");
115 if (tmpdir
== NULL
|| tmpdir
[0] == '\0')
118 char fname
[strlen (tmpdir
) + sizeof "/tst-scanf16.XXXXXX"];
119 sprintf (fname
, "%s/tst-scanf16.XXXXXX", tmpdir
);
121 /* Create a temporary file. */
122 int fd
= mkstemp (fname
);
126 FILE *fp
= fdopen (fd
, "w+");
131 if (fputs (" 1.25s x", fp
) == EOF
)
133 if (fseek (fp
, 0, SEEK_SET
) != 0)
135 if (xfscanf (fp
, "%ms%2c", &sp
, c
) != 2)
139 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
141 memset (sp
, 'x', sizeof "1.25s");
145 if (freopen (fname
, "r", stdin
) == NULL
)
149 if (xscanf ("%ms%2c", &sp
, c
) != 2)
153 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
155 memset (sp
, 'x', sizeof "1.25s");