2 #define _XOPEN_SOURCE 600
3 /* The following macro definitions are a hack. They word around disabling
4 the GNU extension while still using a few internal headers. */
5 #define u_char unsigned char
6 #define u_short unsigned short
7 #define u_int unsigned int
8 #define u_long unsigned long
17 printf ("test at line %d failed\n", __LINE__); \
28 if (sscanf (" 0.25s x", "%e%3c", &f
, c
) != 2)
30 else if (f
!= 0.25 || memcmp (c
, "s x", 3) != 0)
32 if (sscanf (" 1.25s x", "%as%2c", &f
, c
) != 2)
34 else if (f
!= 1.25 || memcmp (c
, " x", 2) != 0)
36 if (sscanf (" 2.25s x", "%las%2c", &d
, c
) != 2)
38 else if (d
!= 2.25 || memcmp (c
, " x", 2) != 0)
40 if (sscanf (" 3.25S x", "%4aS%2c", &f
, c
) != 2)
42 else if (f
!= 3.25 || memcmp (c
, " x", 2) != 0)
44 if (sscanf (" 4.25[0-9.] x", "%a[0-9.]%2c", &f
, c
) != 2)
46 else if (f
!= 4.25 || memcmp (c
, " x", 2) != 0)
48 if (sscanf (" 5.25[0-9.] x", "%la[0-9.]%2c", &d
, c
) != 2)
50 else if (d
!= 5.25 || memcmp (c
, " x", 2) != 0)
53 const char *tmpdir
= getenv ("TMPDIR");
54 if (tmpdir
== NULL
|| tmpdir
[0] == '\0')
57 char fname
[strlen (tmpdir
) + sizeof "/tst-scanf15.XXXXXX"];
58 sprintf (fname
, "%s/tst-scanf15.XXXXXX", tmpdir
);
62 /* Create a temporary file. */
63 int fd
= mkstemp (fname
);
67 FILE *fp
= fdopen (fd
, "w+");
72 if (fputs (" 1.25s x", fp
) == EOF
)
74 if (fseek (fp
, 0, SEEK_SET
) != 0)
76 if (fscanf (fp
, "%as%2c", &f
, c
) != 2)
78 else if (f
!= 1.25 || memcmp (c
, " x", 2) != 0)
81 if (freopen (fname
, "r", stdin
) == NULL
)
85 if (scanf ("%as%2c", &f
, c
) != 2)
87 else if (f
!= 1.25 || memcmp (c
, " x", 2) != 0)