10 printf ("test at line %d failed\n", __LINE__); \
14 xsscanf (const char *str
, const char *fmt
, ...)
18 int ret
= vsscanf (str
, fmt
, ap
);
24 xscanf (const char *fmt
, ...)
28 int ret
= vscanf (fmt
, ap
);
34 xfscanf (FILE *f
, const char *fmt
, ...)
38 int ret
= vfscanf (f
, fmt
, ap
);
53 if (xsscanf (" 0.25s x", "%e%3c", &f
, c
) != 2)
55 else if (f
!= 0.25 || memcmp (c
, "s x", 3) != 0)
57 if (xsscanf (" 1.25s x", "%as%2c", &sp
, c
) != 2)
61 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
63 memset (sp
, 'x', sizeof "1.25s");
66 if (xsscanf (" 2.25s x", "%las%2c", &d
, c
) != 2)
68 else if (d
!= 2.25 || memcmp (c
, " x", 2) != 0)
70 if (xsscanf (" 3.25S x", "%4aS%3c", &lsp
, c
) != 2)
74 if (wcscmp (lsp
, L
"3.25") != 0 || memcmp (c
, "S x", 3) != 0)
76 memset (lsp
, 'x', sizeof L
"3.25");
79 if (xsscanf ("4.25[0-9.] x", "%a[0-9.]%8c", &sp
, c
) != 2)
83 if (strcmp (sp
, "4.25") != 0 || memcmp (c
, "[0-9.] x", 8) != 0)
85 memset (sp
, 'x', sizeof "4.25");
88 if (xsscanf ("5.25[0-9.] x", "%la[0-9.]%2c", &d
, c
) != 2)
90 else if (d
!= 5.25 || memcmp (c
, " x", 2) != 0)
93 const char *tmpdir
= getenv ("TMPDIR");
94 if (tmpdir
== NULL
|| tmpdir
[0] == '\0')
97 char fname
[strlen (tmpdir
) + sizeof "/tst-scanf16.XXXXXX"];
98 sprintf (fname
, "%s/tst-scanf16.XXXXXX", tmpdir
);
102 /* Create a temporary file. */
103 int fd
= mkstemp (fname
);
107 FILE *fp
= fdopen (fd
, "w+");
112 if (fputs (" 1.25s x", fp
) == EOF
)
114 if (fseek (fp
, 0, SEEK_SET
) != 0)
116 if (xfscanf (fp
, "%as%2c", &sp
, c
) != 2)
120 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
122 memset (sp
, 'x', sizeof "1.25s");
126 if (freopen (fname
, "r", stdin
) == NULL
)
130 if (xscanf ("%as%2c", &sp
, c
) != 2)
134 if (strcmp (sp
, "1.25s") != 0 || memcmp (c
, " x", 2) != 0)
136 memset (sp
, 'x', sizeof "1.25s");