Updated to fedora-glibc-20071010T2047
[glibc.git] / stdio-common / scanf15.c
blobcc8aa2e6a6a954a9098f84d76eacf57f195c0ca2
1 #undef _GNU_SOURCE
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
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <wchar.h>
14 #define FAIL() \
15 do { \
16 result = 1; \
17 printf ("test at line %d failed\n", __LINE__); \
18 } while (0)
20 int
21 main (void)
23 float f;
24 double d;
25 char c[8];
26 int result = 0;
28 if (sscanf (" 0.25s x", "%e%3c", &f, c) != 2)
29 FAIL ();
30 else if (f != 0.25 || memcmp (c, "s x", 3) != 0)
31 FAIL ();
32 if (sscanf (" 1.25s x", "%as%2c", &f, c) != 2)
33 FAIL ();
34 else if (f != 1.25 || memcmp (c, " x", 2) != 0)
35 FAIL ();
36 if (sscanf (" 2.25s x", "%las%2c", &d, c) != 2)
37 FAIL ();
38 else if (d != 2.25 || memcmp (c, " x", 2) != 0)
39 FAIL ();
40 if (sscanf (" 3.25S x", "%4aS%2c", &f, c) != 2)
41 FAIL ();
42 else if (f != 3.25 || memcmp (c, " x", 2) != 0)
43 FAIL ();
44 if (sscanf (" 4.25[0-9.] x", "%a[0-9.]%2c", &f, c) != 2)
45 FAIL ();
46 else if (f != 4.25 || memcmp (c, " x", 2) != 0)
47 FAIL ();
48 if (sscanf (" 5.25[0-9.] x", "%la[0-9.]%2c", &d, c) != 2)
49 FAIL ();
50 else if (d != 5.25 || memcmp (c, " x", 2) != 0)
51 FAIL ();
53 return result;