configure tweaks, support $libc_add_on_config_subdirs
[glibc/pb-stable.git] / stdio-common / tstdiomisc.c
blobc1c68955bd92bf6a4356ddc2940e1f113624407c
1 #include <float.h>
2 #include <math.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <wchar.h>
7 static int
8 t1 (void)
10 int n = -1;
11 sscanf ("abc ", "abc %n", &n);
12 printf ("t1: count=%d\n", n);
14 return n != 5;
17 static int
18 t2 (void)
20 int result = 0;
21 int n;
22 long N;
23 int retval;
24 #define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
25 VAR = -1; \
26 retval = sscanf (INPUT, FORMAT, &VAR); \
27 printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
28 INPUT, FORMAT, retval, (long int) VAR); \
29 result |= retval != EXP_RES || VAR != EXP_VAL
31 SCAN ("12345", "%ld", N, 1, 12345);
32 SCAN ("12345", "%llllld", N, 0, -1);
33 SCAN ("12345", "%LLLLLd", N, 0, -1);
34 SCAN ("test ", "%*s%n", n, 0, 4);
35 SCAN ("test ", "%2*s%n", n, 0, -1);
36 SCAN ("12 ", "%l2d", n, 0, -1);
37 SCAN ("12 ", "%2ld", N, 1, 12);
39 n = -1;
40 N = -1;
41 retval = sscanf ("1 1", "%d %Z", &n, &N);
42 printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
43 retval, n, N); \
44 result |= retval != 1 || n != 1 || N != -1;
46 return result;
49 volatile double nanval;
50 volatile double infval;
51 volatile long double lnanval;
52 volatile long double linfval;
55 static int
56 F (void)
58 char buf[80];
59 wchar_t wbuf[40];
60 int result;
62 nanval = NAN;
64 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
65 nanval, nanval, nanval, nanval, nanval, nanval, nanval, nanval);
66 result = strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
67 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
69 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
70 -nanval, -nanval, -nanval, -nanval,
71 -nanval, -nanval, -nanval, -nanval);
72 result = strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
73 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
74 buf);
76 infval = DBL_MAX * DBL_MAX;
78 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
79 infval, infval, infval, infval, infval, infval, infval, infval);
80 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
81 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
83 snprintf (buf, sizeof buf, "%a %A %e %E %f %F %g %G",
84 -infval, -infval, -infval, -infval,
85 -infval, -infval, -infval, -infval);
86 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
87 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
88 buf);
90 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
91 nanval, nanval, nanval, nanval, nanval, nanval, nanval, nanval);
92 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
93 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
95 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
96 -nanval, -nanval, -nanval, -nanval,
97 -nanval, -nanval, -nanval, -nanval);
98 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
99 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
100 wbuf);
102 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
103 infval, infval, infval, infval, infval, infval, infval, infval);
104 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
105 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
107 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%a %A %e %E %f %F %g %G",
108 -infval, -infval, -infval, -infval,
109 -infval, -infval, -infval, -infval);
110 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
111 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
112 wbuf);
114 lnanval = NAN;
116 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
117 lnanval, lnanval, lnanval, lnanval,
118 lnanval, lnanval, lnanval, lnanval);
119 result = strcmp (buf, "nan NAN nan NAN nan NAN nan NAN") != 0;
120 printf ("expected \"nan NAN nan NAN nan NAN nan NAN\", got \"%s\"\n", buf);
122 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
123 -lnanval, -lnanval, -lnanval, -lnanval,
124 -lnanval, -lnanval, -lnanval, -lnanval);
125 result = strcmp (buf, "-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
126 printf ("expected \"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got \"%s\"\n",
127 buf);
129 linfval = LDBL_MAX * LDBL_MAX;
131 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
132 linfval, linfval, linfval, linfval,
133 linfval, linfval, linfval, linfval);
134 result |= strcmp (buf, "inf INF inf INF inf INF inf INF") != 0;
135 printf ("expected \"inf INF inf INF inf INF inf INF\", got \"%s\"\n", buf);
137 snprintf (buf, sizeof buf, "%La %LA %Le %LE %Lf %LF %Lg %LG",
138 -linfval, -linfval, -linfval, -linfval,
139 -linfval, -linfval, -linfval, -linfval);
140 result |= strcmp (buf, "-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
141 printf ("expected \"-inf -INF -inf -INF -inf -INF -inf -INF\", got \"%s\"\n",
142 buf);
144 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
145 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
146 lnanval, lnanval, lnanval, lnanval,
147 lnanval, lnanval, lnanval, lnanval);
148 result |= wcscmp (wbuf, L"nan NAN nan NAN nan NAN nan NAN") != 0;
149 printf ("expected L\"nan NAN nan NAN nan NAN nan NAN\", got L\"%S\"\n", wbuf);
151 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
152 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
153 -lnanval, -lnanval, -lnanval, -lnanval,
154 -lnanval, -lnanval, -lnanval, -lnanval);
155 result |= wcscmp (wbuf, L"-nan -NAN -nan -NAN -nan -NAN -nan -NAN") != 0;
156 printf ("expected L\"-nan -NAN -nan -NAN -nan -NAN -nan -NAN\", got L\"%S\"\n",
157 wbuf);
159 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
160 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
161 linfval, linfval, linfval, linfval,
162 linfval, linfval, linfval, linfval);
163 result |= wcscmp (wbuf, L"inf INF inf INF inf INF inf INF") != 0;
164 printf ("expected L\"inf INF inf INF inf INF inf INF\", got L\"%S\"\n", wbuf);
166 swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]),
167 L"%La %LA %Le %LE %Lf %LF %Lg %LG",
168 -linfval, -linfval, -linfval, -linfval,
169 -linfval, -linfval, -linfval, -linfval);
170 result |= wcscmp (wbuf, L"-inf -INF -inf -INF -inf -INF -inf -INF") != 0;
171 printf ("expected L\"-inf -INF -inf -INF -inf -INF -inf -INF\", got L\"%S\"\n",
172 wbuf);
174 return result;
178 main (int argc, char *argv[])
180 int result = 0;
182 result |= t1 ();
183 result |= t2 ();
184 result |= F ();
186 result |= fflush (stdout) == EOF;
188 return result;