Fixed and unified pthread_once.
[glibc.git] / stdlib / tst-strtoll.c
blob0c77254d5264b455915a16dfbd94d32b531ea58a
1 /* My bet is this was written by Chris Torek.
2 I reformatted and ansidecl-ized it, and tweaked it a little. */
4 #include <ctype.h>
5 #include <stdio.h>
6 #include <errno.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <limits.h>
11 struct ltest
13 const char *str; /* Convert this. */
14 unsigned long long int expect; /* To get this. */
15 int base; /* Use this base. */
16 char left; /* With this left over. */
17 int err; /* And this in errno. */
19 static const struct ltest tests[] =
21 /* First, signed numbers: */
22 /* simple... */
23 {"123", 123, 0, 0, 0},
24 {"+123", 123, 0, 0, 0},
25 {" 123", 123, 0, 0, 0},
26 {" 123 ", 123, 0, ' ', 0},
27 {" -17", -17, 0, 0, 0},
29 /* implicit base... */
30 {"0123", 0123, 0, 0, 0},
31 {"0123a", 0123, 0, 'a', 0},
32 {"01239", 0123, 0, '9', 0},
33 {"0x123", 0x123, 0, 0, 0},
34 {"-0x123", -0x123, 0, 0, 0},
35 {"0x0xc", 0, 0, 'x', 0},
36 {" +0x123fg", 0x123f, 0, 'g', 0},
38 /* explicit base... */
39 {"123", 0x123, 16, 0, 0},
40 {"0x123", 0x123, 16, 0, 0},
41 {"123", 0123, 8, 0, 0},
42 {"0123", 0123, 8, 0, 0},
43 {"0123", 123, 10, 0, 0},
44 {"0x123", 0, 10, 'x', 0},
46 /* case insensitivity... */
47 {"abcd", 0xabcd, 16, 0, 0},
48 {"AbCd", 0xabcd, 16, 0, 0},
49 {"0xABCD", 0xabcd, 16, 0, 0},
50 {"0Xabcd", 0xabcd, 16, 0, 0},
52 /* odd bases... */
53 {"0xyz", 33 * 35 + 34, 35, 'z', 0},
54 {"yz!", 34 * 36 + 35, 36, '!', 0},
55 {"-yz", -(34*36 + 35), 36, 0, 0},
56 {"GhI4", ((16*20 + 17)*20 + 18)*20 + 4, 20, 0, 0},
58 /* special case for the 32-bit version of strtoll,
59 from a ncftp configure test */
60 {"99000000001", 1000000000ll * 99ll + 1ll, 0, 0},
62 /* extremes... */
63 {"9223372036854775807", 9223372036854775807ll, 0, 0, 0},
64 {"9223372036854775808", 9223372036854775807ll, 0, 0, ERANGE},
65 {"922337203685477580777", 9223372036854775807ll, 0, 0, ERANGE},
66 {"9223372036854775810", 9223372036854775807ll, 0, 0, ERANGE},
67 {"-2147483648", -2147483648ll, 0, 0, 0},
68 {"-9223372036854775808", -9223372036854775807ll - 1, 0, 0, 0},
69 {"-9223372036854775809", -9223372036854775807ll - 1, 0, 0, ERANGE},
70 {"0x112233445566778899z", 9223372036854775807ll, 16, 'z', ERANGE},
71 {"0xFFFFFFFFFFFF00FF" , 9223372036854775807ll, 0, 0, ERANGE},
73 {"111111111111111111111111111111111111111111111111111111111111111",
74 9223372036854775807ll, 2, 0, 0},
75 {"1000000000000000000000000000000000000000000000000000000000000000",
76 9223372036854775807ll, 2, 0, ERANGE},
77 {"2021110011022210012102010021220101220221",
78 9223372036854775807ll, 3, 0, 0},
79 {"2021110011022210012102010021220101220222",
80 9223372036854775807ll, 3, 0, ERANGE},
81 {"13333333333333333333333333333333", 9223372036854775807ll, 4, 0, 0},
82 {"20000000000000000000000000000000", 9223372036854775807ll, 4, 0, ERANGE},
83 {"1104332401304422434310311212", 9223372036854775807ll, 5, 0, 0},
84 {"1104332401304422434310311213", 9223372036854775807ll, 5, 0, ERANGE},
85 {"1540241003031030222122211", 9223372036854775807ll, 6, 0, 0},
86 {"1540241003031030222122212", 9223372036854775807ll, 6, 0, ERANGE},
87 {"22341010611245052052300", 9223372036854775807ll, 7, 0, 0},
88 {"22341010611245052052301", 9223372036854775807ll, 7, 0, ERANGE},
89 {"777777777777777777777", 9223372036854775807ll, 8, 0, 0},
90 {"1000000000000000000000", 9223372036854775807ll, 8, 0, ERANGE},
91 {"67404283172107811827", 9223372036854775807ll, 9, 0, 0},
92 {"67404283172107811828", 9223372036854775807ll, 9, 0, ERANGE},
93 {"9223372036854775807", 9223372036854775807ll, 10, 0, 0},
94 {"9223372036854775808", 9223372036854775807ll, 10, 0, ERANGE},
95 {"1728002635214590697", 9223372036854775807ll, 11, 0, 0},
96 {"1728002635214590698", 9223372036854775807ll, 11, 0, ERANGE},
97 {"41a792678515120367", 9223372036854775807ll, 12, 0, 0},
98 {"41a792678515120368", 9223372036854775807ll, 12, 0, ERANGE},
99 {"10b269549075433c37", 9223372036854775807ll, 13, 0, 0},
100 {"10b269549075433c38", 9223372036854775807ll, 13, 0, ERANGE},
101 {"4340724c6c71dc7a7", 9223372036854775807ll, 14, 0, 0},
102 {"4340724c6c71dc7a8", 9223372036854775807ll, 14, 0, ERANGE},
103 {"160e2ad3246366807", 9223372036854775807ll, 15, 0, 0},
104 {"160e2ad3246366808", 9223372036854775807ll, 15, 0, ERANGE},
105 {"7fffffffffffffff", 9223372036854775807ll, 16, 0, 0},
106 {"8000000000000000", 9223372036854775807ll, 16, 0, ERANGE},
107 {"33d3d8307b214008", 9223372036854775807ll, 17, 0, 0},
108 {"33d3d8307b214009", 9223372036854775807ll, 17, 0, ERANGE},
109 {"16agh595df825fa7", 9223372036854775807ll, 18, 0, 0},
110 {"16agh595df825fa8", 9223372036854775807ll, 18, 0, ERANGE},
111 {"ba643dci0ffeehh", 9223372036854775807ll, 19, 0, 0},
112 {"ba643dci0ffeehi", 9223372036854775807ll, 19, 0, ERANGE},
113 {"5cbfjia3fh26ja7", 9223372036854775807ll, 20, 0, 0},
114 {"5cbfjia3fh26ja8", 9223372036854775807ll, 20, 0, ERANGE},
115 {"2heiciiie82dh97", 9223372036854775807ll, 21, 0, 0},
116 {"2heiciiie82dh98", 9223372036854775807ll, 21, 0, ERANGE},
117 {"1adaibb21dckfa7", 9223372036854775807ll, 22, 0, 0},
118 {"1adaibb21dckfa8", 9223372036854775807ll, 22, 0, ERANGE},
119 {"i6k448cf4192c2", 9223372036854775807ll, 23, 0, 0},
120 {"i6k448cf4192c3", 9223372036854775807ll, 23, 0, ERANGE},
121 {"acd772jnc9l0l7", 9223372036854775807ll, 24, 0, 0},
122 {"acd772jnc9l0l8", 9223372036854775807ll, 24, 0, ERANGE},
123 {"64ie1focnn5g77", 9223372036854775807ll, 25, 0, 0},
124 {"64ie1focnn5g78", 9223372036854775807ll, 25, 0, ERANGE},
125 {"3igoecjbmca687", 9223372036854775807ll, 26, 0, 0},
126 {"3igoecjbmca688", 9223372036854775807ll, 26, 0, ERANGE},
127 {"27c48l5b37oaop", 9223372036854775807ll, 27, 0, 0},
128 {"27c48l5b37oaoq", 9223372036854775807ll, 27, 0, ERANGE},
129 {"1bk39f3ah3dmq7", 9223372036854775807ll, 28, 0, 0},
130 {"1bk39f3ah3dmq8", 9223372036854775807ll, 28, 0, ERANGE},
131 {"q1se8f0m04isb", 9223372036854775807ll, 29, 0, 0},
132 {"q1se8f0m04isc", 9223372036854775807ll, 29, 0, ERANGE},
133 {"hajppbc1fc207", 9223372036854775807ll, 30, 0, 0},
134 {"hajppbc1fc208", 9223372036854775807ll, 30, 0, ERANGE},
135 {"bm03i95hia437", 9223372036854775807ll, 31, 0, 0},
136 {"bm03i95hia438", 9223372036854775807ll, 31, 0, ERANGE},
137 {"7vvvvvvvvvvvv", 9223372036854775807ll, 32, 0, 0},
138 {"8000000000000", 9223372036854775807ll, 32, 0, ERANGE},
139 {"5hg4ck9jd4u37", 9223372036854775807ll, 33, 0, 0},
140 {"5hg4ck9jd4u38", 9223372036854775807ll, 33, 0, ERANGE},
141 {"3tdtk1v8j6tpp", 9223372036854775807ll, 34, 0, 0},
142 {"3tdtk1v8j6tpq", 9223372036854775807ll, 34, 0, ERANGE},
143 {"2pijmikexrxp7", 9223372036854775807ll, 35, 0, 0},
144 {"2pijmikexrxp8", 9223372036854775807ll, 35, 0, ERANGE},
145 {"1y2p0ij32e8e7", 9223372036854775807ll, 36, 0, 0},
146 {"1y2p0ij32e8e8", 9223372036854775807ll, 36, 0, ERANGE},
148 {"-1000000000000000000000000000000000000000000000000000000000000000",
149 -9223372036854775808ull, 2, 0, 0},
150 {"-1000000000000000000000000000000000000000000000000000000000000001",
151 -9223372036854775808ull, 2, 0, ERANGE},
152 {"-2021110011022210012102010021220101220222",
153 -9223372036854775808ull, 3, 0, 0},
154 {"-2021110011022210012102010021220101221000",
155 -9223372036854775808ull, 3, 0, ERANGE},
156 {"-20000000000000000000000000000000", -9223372036854775808ull, 4, 0, 0},
157 {"-20000000000000000000000000000001", -9223372036854775808ull, 4, 0, ERANGE},
158 {"-1104332401304422434310311213", -9223372036854775808ull, 5, 0, 0},
159 {"-1104332401304422434310311214", -9223372036854775808ull, 5, 0, ERANGE},
160 {"-1540241003031030222122212", -9223372036854775808ull, 6, 0, 0},
161 {"-1540241003031030222122213", -9223372036854775808ull, 6, 0, ERANGE},
162 {"-22341010611245052052301", -9223372036854775808ull, 7, 0, 0},
163 {"-22341010611245052052302", -9223372036854775808ull, 7, 0, ERANGE},
164 {"-1000000000000000000000", -9223372036854775808ull, 8, 0, 0},
165 {"-1000000000000000000001", -9223372036854775808ull, 8, 0, ERANGE},
166 {"-67404283172107811828", -9223372036854775808ull, 9, 0, 0},
167 {"-67404283172107811830", -9223372036854775808ull, 9, 0, ERANGE},
168 {"-9223372036854775808", -9223372036854775808ull, 10, 0, 0},
169 {"-9223372036854775809", -9223372036854775808ull, 10, 0, ERANGE},
170 {"-1728002635214590698", -9223372036854775808ull, 11, 0, 0},
171 {"-1728002635214590699", -9223372036854775808ull, 11, 0, ERANGE},
172 {"-41a792678515120368", -9223372036854775808ull, 12, 0, 0},
173 {"-41a792678515120369", -9223372036854775808ull, 12, 0, ERANGE},
174 {"-10b269549075433c38", -9223372036854775808ull, 13, 0, 0},
175 {"-10b269549075433c39", -9223372036854775808ull, 13, 0, ERANGE},
176 {"-4340724c6c71dc7a8", -9223372036854775808ull, 14, 0, 0},
177 {"-4340724c6c71dc7a9", -9223372036854775808ull, 14, 0, ERANGE},
178 {"-160e2ad3246366808", -9223372036854775808ull, 15, 0, 0},
179 {"-160e2ad3246366809", -9223372036854775808ull, 15, 0, ERANGE},
180 {"-8000000000000000", -9223372036854775808ull, 16, 0, 0},
181 {"-8000000000000001", -9223372036854775808ull, 16, 0, ERANGE},
182 {"-33d3d8307b214009", -9223372036854775808ull, 17, 0, 0},
183 {"-33d3d8307b21400a", -9223372036854775808ull, 17, 0, ERANGE},
184 {"-16agh595df825fa8", -9223372036854775808ull, 18, 0, 0},
185 {"-16agh595df825fa9", -9223372036854775808ull, 18, 0, ERANGE},
186 {"-ba643dci0ffeehi", -9223372036854775808ull, 19, 0, 0},
187 {"-ba643dci0ffeei0", -9223372036854775808ull, 19, 0, ERANGE},
188 {"-5cbfjia3fh26ja8", -9223372036854775808ull, 20, 0, 0},
189 {"-5cbfjia3fh26ja9", -9223372036854775808ull, 20, 0, ERANGE},
190 {"-2heiciiie82dh98", -9223372036854775808ull, 21, 0, 0},
191 {"-2heiciiie82dh99", -9223372036854775808ull, 21, 0, ERANGE},
192 {"-1adaibb21dckfa8", -9223372036854775808ull, 22, 0, 0},
193 {"-1adaibb21dckfa9", -9223372036854775808ull, 22, 0, ERANGE},
194 {"-i6k448cf4192c3", -9223372036854775808ull, 23, 0, 0},
195 {"-i6k448cf4192c4", -9223372036854775808ull, 23, 0, ERANGE},
196 {"-acd772jnc9l0l8", -9223372036854775808ull, 24, 0, 0},
197 {"-acd772jnc9l0l9", -9223372036854775808ull, 24, 0, ERANGE},
198 {"-64ie1focnn5g78", -9223372036854775808ull, 25, 0, 0},
199 {"-64ie1focnn5g79", -9223372036854775808ull, 25, 0, ERANGE},
200 {"-3igoecjbmca688", -9223372036854775808ull, 26, 0, 0},
201 {"-3igoecjbmca689", -9223372036854775808ull, 26, 0, ERANGE},
202 {"-27c48l5b37oaoq", -9223372036854775808ull, 27, 0, 0},
203 {"-27c48l5b37oap0", -9223372036854775808ull, 27, 0, ERANGE},
204 {"-1bk39f3ah3dmq8", -9223372036854775808ull, 28, 0, 0},
205 {"-1bk39f3ah3dmq9", -9223372036854775808ull, 28, 0, ERANGE},
206 {"-q1se8f0m04isc", -9223372036854775808ull, 29, 0, 0},
207 {"-q1se8f0m04isd", -9223372036854775808ull, 29, 0, ERANGE},
208 {"-hajppbc1fc208", -9223372036854775808ull, 30, 0, 0},
209 {"-hajppbc1fc209", -9223372036854775808ull, 30, 0, ERANGE},
210 {"-bm03i95hia438", -9223372036854775808ull, 31, 0, 0},
211 {"-bm03i95hia439", -9223372036854775808ull, 31, 0, ERANGE},
212 {"-8000000000000", -9223372036854775808ull, 32, 0, 0},
213 {"-8000000000001", -9223372036854775808ull, 32, 0, ERANGE},
214 {"-5hg4ck9jd4u38", -9223372036854775808ull, 33, 0, 0},
215 {"-5hg4ck9jd4u39", -9223372036854775808ull, 33, 0, ERANGE},
216 {"-3tdtk1v8j6tpq", -9223372036854775808ull, 34, 0, 0},
217 {"-3tdtk1v8j6tpr", -9223372036854775808ull, 34, 0, ERANGE},
218 {"-2pijmikexrxp8", -9223372036854775808ull, 35, 0, 0},
219 {"-2pijmikexrxp9", -9223372036854775808ull, 35, 0, ERANGE},
220 {"-1y2p0ij32e8e8", -9223372036854775808ull, 36, 0, 0},
221 {"-1y2p0ij32e8e9", -9223372036854775808ull, 36, 0, ERANGE},
222 {NULL, 0, 0, 0, 0},
224 /* Then unsigned. */
225 {" 0", 0, 0, 0, 0},
226 {"0xffffffffg", 0xffffffff, 0, 'g', 0},
227 {"0xffffffffffffffffg", 0xffffffffffffffffull, 0, 'g', 0},
228 {"-0xfedcba987654321", 0xf0123456789abcdfull, 0, 0, 0},
229 {"0xf1f2f3f4f5f6f7f8f9", 0xffffffffffffffffull, 0, 0, ERANGE},
230 {"-0x123456789abcdef01", 0xffffffffffffffffull, 0, 0, ERANGE},
232 {"1111111111111111111111111111111111111111111111111111111111111111",
233 0xffffffffffffffff, 2, 0, 0},
234 {"10000000000000000000000000000000000000000000000000000000000000000",
235 0xffffffffffffffff, 2, 0, ERANGE},
236 {"11112220022122120101211020120210210211220",
237 0xffffffffffffffff, 3, 0, 0},
238 {"11112220022122120101211020120210210211221",
239 0xffffffffffffffff, 3, 0, ERANGE},
240 {"33333333333333333333333333333333", 0xffffffffffffffff, 4, 0, 0},
241 {"100000000000000000000000000000000", 0xffffffffffffffff, 4, 0, ERANGE},
242 {"2214220303114400424121122430", 0xffffffffffffffff, 5, 0, 0},
243 {"2214220303114400424121122431", 0xffffffffffffffff, 5, 0, ERANGE},
244 {"3520522010102100444244423", 0xffffffffffffffff, 6, 0, 0},
245 {"3520522010102100444244424", 0xffffffffffffffff, 6, 0, ERANGE},
246 {"45012021522523134134601", 0xffffffffffffffff, 7, 0, 0},
247 {"45012021522523134134602", 0xffffffffffffffff, 7, 0, ERANGE},
248 {"1777777777777777777777", 0xffffffffffffffff, 8, 0, 0},
249 {"2000000000000000000000", 0xffffffffffffffff, 8, 0, ERANGE},
250 {"145808576354216723756", 0xffffffffffffffff, 9, 0, 0},
251 {"145808576354216723757", 0xffffffffffffffff, 9, 0, ERANGE},
252 {"18446744073709551615", 0xffffffffffffffff, 10, 0, 0},
253 {"18446744073709551616", 0xffffffffffffffff, 10, 0, ERANGE},
254 {"335500516a429071284", 0xffffffffffffffff, 11, 0, 0},
255 {"335500516a429071285", 0xffffffffffffffff, 11, 0, ERANGE},
256 {"839365134a2a240713", 0xffffffffffffffff, 12, 0, 0},
257 {"839365134a2a240714", 0xffffffffffffffff, 12, 0, ERANGE},
258 {"219505a9511a867b72", 0xffffffffffffffff, 13, 0, 0},
259 {"219505a9511a867b73", 0xffffffffffffffff, 13, 0, ERANGE},
260 {"8681049adb03db171", 0xffffffffffffffff, 14, 0, 0},
261 {"8681049adb03db172", 0xffffffffffffffff, 14, 0, ERANGE},
262 {"2c1d56b648c6cd110", 0xffffffffffffffff, 15, 0, 0},
263 {"2c1d56b648c6cd111", 0xffffffffffffffff, 15, 0, ERANGE},
264 {"ffffffffffffffff", 0xffffffffffffffff, 16, 0, 0},
265 {"10000000000000000", 0xffffffffffffffff, 16, 0, ERANGE},
266 {"67979g60f5428010", 0xffffffffffffffff, 17, 0, 0},
267 {"67979g60f5428011", 0xffffffffffffffff, 17, 0, ERANGE},
268 {"2d3fgb0b9cg4bd2f", 0xffffffffffffffff, 18, 0, 0},
269 {"2d3fgb0b9cg4bd2g", 0xffffffffffffffff, 18, 0, ERANGE},
270 {"141c8786h1ccaagg", 0xffffffffffffffff, 19, 0, 0},
271 {"141c8786h1ccaagh", 0xffffffffffffffff, 19, 0, ERANGE},
272 {"b53bjh07be4dj0f", 0xffffffffffffffff, 20, 0, 0},
273 {"b53bjh07be4dj0g", 0xffffffffffffffff, 20, 0, ERANGE},
274 {"5e8g4ggg7g56dif", 0xffffffffffffffff, 21, 0, 0},
275 {"5e8g4ggg7g56dig", 0xffffffffffffffff, 21, 0, ERANGE},
276 {"2l4lf104353j8kf", 0xffffffffffffffff, 22, 0, 0},
277 {"2l4lf104353j8kg", 0xffffffffffffffff, 22, 0, ERANGE},
278 {"1ddh88h2782i515", 0xffffffffffffffff, 23, 0, 0},
279 {"1ddh88h2782i516", 0xffffffffffffffff, 23, 0, ERANGE},
280 {"l12ee5fn0ji1if", 0xffffffffffffffff, 24, 0, 0},
281 {"l12ee5fn0ji1ig", 0xffffffffffffffff, 24, 0, ERANGE},
282 {"c9c336o0mlb7ef", 0xffffffffffffffff, 25, 0, 0},
283 {"c9c336o0mlb7eg", 0xffffffffffffffff, 25, 0, ERANGE},
284 {"7b7n2pcniokcgf", 0xffffffffffffffff, 26, 0, 0},
285 {"7b7n2pcniokcgg", 0xffffffffffffffff, 26, 0, ERANGE},
286 {"4eo8hfam6fllmo", 0xffffffffffffffff, 27, 0, 0},
287 {"4eo8hfam6fllmp", 0xffffffffffffffff, 27, 0, ERANGE},
288 {"2nc6j26l66rhof", 0xffffffffffffffff, 28, 0, 0},
289 {"2nc6j26l66rhog", 0xffffffffffffffff, 28, 0, ERANGE},
290 {"1n3rsh11f098rn", 0xffffffffffffffff, 29, 0, 0},
291 {"1n3rsh11f098ro", 0xffffffffffffffff, 29, 0, ERANGE},
292 {"14l9lkmo30o40f", 0xffffffffffffffff, 30, 0, 0},
293 {"14l9lkmo30o40g", 0xffffffffffffffff, 30, 0, ERANGE},
294 {"nd075ib45k86f", 0xffffffffffffffff, 31, 0, 0},
295 {"nd075ib45k86g", 0xffffffffffffffff, 31, 0, ERANGE},
296 {"fvvvvvvvvvvvv", 0xffffffffffffffff, 32, 0, 0},
297 {"g000000000000", 0xffffffffffffffff, 32, 0, ERANGE},
298 {"b1w8p7j5q9r6f", 0xffffffffffffffff, 33, 0, 0},
299 {"b1w8p7j5q9r6g", 0xffffffffffffffff, 33, 0, ERANGE},
300 {"7orp63sh4dphh", 0xffffffffffffffff, 34, 0, 0},
301 {"7orp63sh4dphi", 0xffffffffffffffff, 34, 0, ERANGE},
302 {"5g24a25twkwff", 0xffffffffffffffff, 35, 0, 0},
303 {"5g24a25twkwfg", 0xffffffffffffffff, 35, 0, ERANGE},
304 {"3w5e11264sgsf", 0xffffffffffffffff, 36, 0, 0},
305 {"3w5e11264sgsg", 0xffffffffffffffff, 36, 0, ERANGE},
306 {NULL, 0, 0, 0, 0},
309 /* Prototypes for local functions. */
310 static void expand (char *dst, int c);
313 main (void)
315 const struct ltest *lt;
316 char *ep;
317 int status = 0;
318 int save_errno;
320 for (lt = tests; lt->str != NULL; ++lt)
322 long long int l;
324 errno = 0;
325 l = strtoll (lt->str, &ep, lt->base);
326 save_errno = errno;
327 printf ("strtoll(\"%s\", , %d) test %u",
328 lt->str, lt->base, (unsigned int) (lt - tests));
329 if (l == (long long int) lt->expect && *ep == lt->left
330 && save_errno == lt->err)
331 puts("\tOK");
332 else
334 puts("\tBAD");
335 if (l != (long long int) lt->expect)
336 printf(" returns %lld, expected %lld\n",
337 l, (long long int) lt->expect);
338 if (lt->left != *ep)
340 char exp1[5], exp2[5];
341 expand (exp1, *ep);
342 expand (exp2, lt->left);
343 printf (" leaves '%s', expected '%s'\n", exp1, exp2);
345 if (save_errno != lt->err)
346 printf (" errno %d (%s) instead of %d (%s)\n",
347 save_errno, strerror (save_errno),
348 lt->err, strerror (lt->err));
349 status = 1;
353 for (++lt; lt->str != NULL; lt++)
355 unsigned long long int ul;
357 errno = 0;
358 ul = strtoull (lt->str, &ep, lt->base);
359 save_errno = errno;
360 printf ("strtoull(\"%s\", , %d) test %u",
361 lt->str, lt->base, (unsigned int) (lt - tests));
362 if (ul == lt->expect && *ep == lt->left && save_errno == lt->err)
363 puts("\tOK");
364 else
366 puts ("\tBAD");
367 if (ul != lt->expect)
368 printf (" returns %llu, expected %llu\n",
369 ul, lt->expect);
370 if (lt->left != *ep)
372 char exp1[5], exp2[5];
373 expand (exp1, *ep);
374 expand (exp2, lt->left);
375 printf (" leaves '%s', expected '%s'\n", exp1, exp2);
377 if (save_errno != lt->err)
378 printf (" errno %d (%s) instead of %d (%s)\n",
379 save_errno, strerror (save_errno),
380 lt->err, strerror (lt->err));
381 status = 1;
385 return status ? EXIT_FAILURE : EXIT_SUCCESS;
388 static void
389 expand (dst, c)
390 char *dst;
391 int c;
393 if (isprint (c))
395 dst[0] = c;
396 dst[1] = '\0';
398 else
399 (void) sprintf (dst, "%#.3o", (unsigned int) c);