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
18 printf ("test at line %d failed\n", __LINE__); \
29 if (sscanf (" 0.25s x", "%e%3c", &f
, c
) != 2)
31 else if (f
!= 0.25 || memcmp (c
, "s x", 3) != 0)
33 if (sscanf (" 1.25s x", "%as%2c", &f
, c
) != 2)
35 else if (f
!= 1.25 || memcmp (c
, " x", 2) != 0)
37 if (sscanf (" 2.25s x", "%las%2c", &d
, c
) != 2)
39 else if (d
!= 2.25 || memcmp (c
, " x", 2) != 0)
41 if (sscanf (" 3.25S x", "%4aS%2c", &f
, c
) != 2)
43 else if (f
!= 3.25 || memcmp (c
, " x", 2) != 0)
45 if (sscanf (" 4.25[0-9.] x", "%a[0-9.]%2c", &f
, c
) != 2)
47 else if (f
!= 4.25 || memcmp (c
, " x", 2) != 0)
49 if (sscanf (" 5.25[0-9.] x", "%la[0-9.]%2c", &d
, c
) != 2)
51 else if (d
!= 5.25 || memcmp (c
, " x", 2) != 0)
54 const char *tmpdir
= getenv ("TMPDIR");
55 if (tmpdir
== NULL
|| tmpdir
[0] == '\0')
58 char fname
[strlen (tmpdir
) + sizeof "/tst-scanf15.XXXXXX"];
59 sprintf (fname
, "%s/tst-scanf15.XXXXXX", tmpdir
);
63 /* Create a temporary file. */
64 int fd
= mkstemp (fname
);
68 FILE *fp
= fdopen (fd
, "w+");
73 if (fputs (" 1.25s x", fp
) == EOF
)
75 if (fseek (fp
, 0, SEEK_SET
) != 0)
77 if (fscanf (fp
, "%as%2c", &f
, c
) != 2)
79 else if (f
!= 1.25 || memcmp (c
, " x", 2) != 0)
82 if (freopen (fname
, "r", stdin
) == NULL
)
86 if (scanf ("%as%2c", &f
, c
) != 2)
88 else if (f
!= 1.25 || memcmp (c
, " x", 2) != 0)