2 #define _XOPEN_SOURCE 600
4 /* The following macro definitions are a hack. They word around disabling
5 the GNU extension while still using a few internal headers. */
6 #define u_char unsigned char
7 #define u_short unsigned short
8 #define u_int unsigned int
9 #define u_long unsigned long
19 printf ("test at line %d failed\n", __LINE__); \
23 xsscanf (const char *str, const char *fmt, ...)
27 int ret = vsscanf (str, fmt, ap);
33 xscanf (const char *fmt, ...)
37 int ret = vscanf (fmt, ap);
43 xfscanf (FILE *f, const char *fmt, ...)
47 int ret = vfscanf (f, fmt, ap);
60 if (xsscanf (" 0.25s x", "%e%3c", &f, c) != 2)
62 else if (f != 0.25 || memcmp (c, "s x", 3) != 0)
64 if (xsscanf (" 1.25s x", "%as%2c", &f, c) != 2)
66 else if (f != 1.25 || memcmp (c, " x", 2) != 0)
68 if (xsscanf (" 2.25s x", "%las%2c", &d, c) != 2)
70 else if (d != 2.25 || memcmp (c, " x", 2) != 0)
72 if (xsscanf (" 3.25S x", "%4aS%2c", &f, c) != 2)
74 else if (f != 3.25 || memcmp (c, " x", 2) != 0)
76 if (xsscanf (" 4.25[0-9.] x", "%a[0-9.]%2c", &f, c) != 2)
78 else if (f != 4.25 || memcmp (c, " x", 2) != 0)
80 if (xsscanf (" 5.25[0-9.] x", "%la[0-9.]%2c", &d, c) != 2)
82 else if (d != 5.25 || memcmp (c, " x", 2) != 0)
85 const char *tmpdir = getenv ("TMPDIR");
86 if (tmpdir == NULL || tmpdir[0] == '\0')
89 char fname[strlen (tmpdir) + sizeof "/tst-scanf17.XXXXXX"];
90 sprintf (fname, "%s/tst-scanf17.XXXXXX", tmpdir);
94 /* Create a temporary file. */
95 int fd = mkstemp (fname);
99 FILE *fp = fdopen (fd, "w+");
104 if (fputs (" 1.25s x", fp) == EOF)
106 if (fseek (fp, 0, SEEK_SET) != 0)
108 if (xfscanf (fp, "%as%2c", &f, c) != 2)
110 else if (f != 1.25 || memcmp (c, " x", 2) != 0)
113 if (freopen (fname, "r", stdin) == NULL)
117 if (xscanf ("%as%2c", &f, c) != 2)
119 else if (f != 1.25 || memcmp (c, " x", 2) != 0)