5 #include <libc-internal.h>
10 printf ("test at line %d failed\n", __LINE__); \
23 if (sscanf (" 0.25s x", "%e%3c", &f
, c
) != 2)
25 else if (f
!= 0.25 || memcmp (c
, "s x", 3) != 0)
27 /* GCC in C99 mode treats %a as the C99 format expecting float *,
28 but glibc with _GNU_SOURCE treats %as as the GNU allocation
29 extension, so resulting in "warning: format '%a' expects argument
30 of type 'float *', but argument 3 has type 'char **'". This
31 applies to the other %as, %aS and %a[] formats below as well. */
32 DIAG_PUSH_NEEDS_COMMENT
;
33 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
34 if (sscanf (" 1.25s x", "%as%2c", &sp
, c
) != 2)
38 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
40 memset (sp
, 'x', sizeof "1.25s");
43 DIAG_POP_NEEDS_COMMENT
;
44 if (sscanf (" 2.25s x", "%las%2c", &d
, c
) != 2)
46 else if (d
!= 2.25 || memcmp (c
, " x", 2) != 0)
48 /* See explanation above. */
49 DIAG_PUSH_NEEDS_COMMENT
;
50 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
51 if (sscanf (" 3.25S x", "%4aS%3c", &lsp
, c
) != 2)
55 if (wcscmp (lsp
, L
"3.25") != 0 || memcmp (c
, "S x", 3) != 0)
57 memset (lsp
, 'x', sizeof L
"3.25");
60 if (sscanf ("4.25[0-9.] x", "%a[0-9.]%8c", &sp
, c
) != 2)
64 if (strcmp (sp
, "4.25") != 0 || memcmp (c
, "[0-9.] x", 8) != 0)
66 memset (sp
, 'x', sizeof "4.25");
69 DIAG_POP_NEEDS_COMMENT
;
70 if (sscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d
, c
) != 2)
72 else if (d
!= 5.25 || memcmp (c
, " x", 2) != 0)
75 const char *tmpdir
= getenv ("TMPDIR");
76 if (tmpdir
== NULL
|| tmpdir
[0] == '\0')
79 char fname
[strlen (tmpdir
) + sizeof "/tst-scanf14.XXXXXX"];
80 sprintf (fname
, "%s/tst-scanf14.XXXXXX", tmpdir
);
84 /* Create a temporary file. */
85 int fd
= mkstemp (fname
);
89 FILE *fp
= fdopen (fd
, "w+");
94 if (fputs (" 1.25s x", fp
) == EOF
)
96 if (fseek (fp
, 0, SEEK_SET
) != 0)
98 /* See explanation above. */
99 DIAG_PUSH_NEEDS_COMMENT
;
100 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
101 if (fscanf (fp
, "%as%2c", &sp
, c
) != 2)
105 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
107 memset (sp
, 'x', sizeof "1.25s");
110 DIAG_POP_NEEDS_COMMENT
;
112 if (freopen (fname
, "r", stdin
) == NULL
)
116 /* See explanation above. */
117 DIAG_PUSH_NEEDS_COMMENT
;
118 DIAG_IGNORE_NEEDS_COMMENT (4.9, "-Wformat");
119 if (scanf ("%as%2c", &sp
, c
) != 2)
123 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
125 memset (sp
, 'x', sizeof "1.25s");
128 DIAG_POP_NEEDS_COMMENT
;