]> git.sur5r.net Git - cc65/blob - test/misc/sitest.c
remote TABs in doc/ and test/
[cc65] / test / misc / sitest.c
1 /*
2   !!DESCRIPTION!! C99 WCHAR test
3   !!ORIGIN!!
4   !!LICENCE!!     public domain
5 */
6
7 /*
8         sitest -- exercise features of C99 <stdint.h> and <inttypes.h>
9
10         This source code has been placed into the PUBLIC DOMAIN by its author.
11
12         last edit:      1999/11/05      gwyn@arl.mil
13
14         Tries to accommodate pre-C99 versions of <inttypes.h>.
15
16         Takes advantage of __Q8_* symbols defined by a particular
17         implementation of <stdint.h>, but doesn't require them.
18
19         NOTE:   This is not a thorough validation test of the facilities.
20 */
21
22 #define NO_INTERNAL_WCHAR
23 /*#define STANDALONE*/
24
25 #include        <errno.h>
26 #include        <limits.h>              /* for CHAR_BIT */
27 #include        <stdio.h>
28 #include        <stddef.h>              /* for ptrdiff_t */
29 #include        <stdlib.h>
30 #include        <string.h>
31
32 #if !defined(STANDARD_C99) && !defined(STANDARD_CC65)
33
34 #error "this test checks C99 features, which are not available in the selected standard."
35
36 #else
37
38 #ifdef NO_WCHAR
39
40 #warn "this test checks C99 features, but NO_WCHAR is defined so the test will most definetly fails."
41
42 #endif
43
44 #include        <inttypes.h>            /* embeds <stdint.h> */
45
46 #include        <signal.h>              /* for sig_atomic_t */
47
48 #if     defined(INTMAX_MAX)             /* <inttypes.h> has C99 features */
49 #include        <wchar.h>
50 #endif
51
52 #include        <inttypes.h>            /* test idempotency */
53
54 #ifdef STANDALONE
55
56 FILE *outfile=NULL;
57 #define opentest(x) outfile=stdout;
58 #define closetest(x)
59
60 #else
61
62 #endif
63
64 #if     __STDC_VERSION__ >= 199901
65 #ifndef __Q8_QT
66 #define __Q8_QT long long
67 #endif
68 #endif
69
70 #ifdef  PRIdMAX
71 #define HAVE_PRIdMAX
72 #ifndef __Q8_MT
73 #define __Q8_MT intmax_t
74 #endif
75 #else
76 #ifdef  PRIdLEAST64
77 #ifndef __Q8_MT
78 #define __Q8_MT int_least64_t
79 #endif
80 #define PRIdMAX PRIdLEAST64
81 #else
82 #ifndef __Q8_MT
83 #define __Q8_MT long
84 #endif
85 #define PRIdMAX "ld"
86 #endif
87 #endif
88
89 #ifdef  PRIuMAX
90 #define HAVE_PRIuMAX
91 #define U__Q8_MT        uintmax_t
92 #else
93 #ifdef  PRIuLEAST64
94 #define U__Q8_MT        uint_least64_t
95 #define PRIuMAX PRIuLEAST64
96 #else
97 #define U__Q8_MT        unsigned long
98 #define PRIuMAX "lu"
99 #endif
100 #endif
101
102 #define STR_SUB(s)      # s
103 #define STRINGIZE(s)    STR_SUB(s)      /* extra level to expand argument */
104
105 #if     defined(SCNo32) || defined(PRIo32)
106 static int32_t          int32;
107 #endif
108 static int_least16_t    intl16;
109 static uint_least16_t   uintl16;
110 static uint_fast16_t    uintf16;
111 static intmax_t         intmax;
112 static uintmax_t        uintmax;
113
114 int
115 main()  {
116         int     status = 0;             /* exit status to be returned */
117
118         
119         /* <stdint.h> features: */
120
121         printf("CHAR_BIT=%u\n", (unsigned)CHAR_BIT );
122         printf("sizeof(char)=%u\n", (unsigned)sizeof(char));    /* s.b. 1 */
123         printf("sizeof(short)=%u\n", (unsigned)sizeof(short));
124         printf("sizeof(int)=%u\n", (unsigned)sizeof(int));
125         printf("sizeof(long)=%u\n", (unsigned)sizeof(long));
126 #ifdef  __Q8_QT
127         printf("sizeof(long long)=%u\n", (unsigned)sizeof(__Q8_QT));
128 #else
129         printf("*** long long isn't defined ***\n");
130 #endif
131         printf("sizeof(intmax_t)=%u\n", (unsigned)sizeof(intmax_t));
132         printf("sizeof(ptrdiff_t)=%u\n", (unsigned)sizeof(ptrdiff_t));
133         printf("sizeof(size_t)=%u\n", (unsigned)sizeof(size_t));
134         printf("sizeof(sig_atomic_t)=%u\n", (unsigned)sizeof(sig_atomic_t));
135         printf("sizeof(wchar_t)=%u\n", (unsigned)sizeof(wchar_t));
136 #if     defined(WINT_MAX) || __STDC_VERSION__ >= 199901
137         printf("sizeof(wint_t)=%u\n", (unsigned)sizeof(wint_t));
138 #else
139         printf("*** wint_t isn't defined ***\n");
140         status = EXIT_FAILURE;
141 #endif
142 #ifdef  INT8_MAX
143         printf("sizeof(int8_t)=%u\n", (unsigned)sizeof(int8_t));
144         printf("sizeof(uint8_t)=%u\n", (unsigned)sizeof(uint8_t));
145 #endif
146 #ifdef  INT9_MAX
147         printf("sizeof(int9_t)=%u\n", (unsigned)sizeof(int9_t));
148         printf("sizeof(uint9_t)=%u\n", (unsigned)sizeof(uint9_t));
149 #endif
150 #ifdef  INT12_MAX
151         printf("sizeof(int12_t)=%u\n", (unsigned)sizeof(int12_t));
152         printf("sizeof(uint12_t)=%u\n", (unsigned)sizeof(uint12_t));
153 #endif
154 #ifdef  INT16_MAX
155         printf("sizeof(int16_t)=%u\n", (unsigned)sizeof(int16_t));
156         printf("sizeof(uint16_t)=%u\n", (unsigned)sizeof(uint16_t));
157 #endif
158 #ifdef  INT18_MAX
159         printf("sizeof(int18_t)=%u\n", (unsigned)sizeof(int18_t));
160         printf("sizeof(uint18_t)=%u\n", (unsigned)sizeof(uint18_t));
161 #endif
162 #ifdef  INT24_MAX
163         printf("sizeof(int24_t)=%u\n", (unsigned)sizeof(int24_t));
164         printf("sizeof(uint24_t)=%u\n", (unsigned)sizeof(uint24_t));
165 #endif
166 #ifdef  INT32_MAX
167         printf("sizeof(int32_t)=%u\n", (unsigned)sizeof(int32_t));
168         printf("sizeof(uint32_t)=%u\n", (unsigned)sizeof(uint32_t));
169 #endif
170 #ifdef  INT36_MAX
171         printf("sizeof(int36_t)=%u\n", (unsigned)sizeof(int36_t));
172         printf("sizeof(uint36_t)=%u\n", (unsigned)sizeof(uint36_t));
173 #endif
174 #ifdef  INT40_MAX
175         printf("sizeof(int40_t)=%u\n", (unsigned)sizeof(int40_t));
176         printf("sizeof(uint40_t)=%u\n", (unsigned)sizeof(uint40_t));
177 #endif
178 #ifdef  INT48_MAX
179         printf("sizeof(int48_t)=%u\n", (unsigned)sizeof(int48_t));
180         printf("sizeof(uint48_t)=%u\n", (unsigned)sizeof(uint48_t));
181 #endif
182 #ifdef  INT60_MAX
183         printf("sizeof(int60_t)=%u\n", (unsigned)sizeof(int60_t));
184         printf("sizeof(uint60_t)=%u\n", (unsigned)sizeof(uint60_t));
185 #endif
186 #ifdef  INT64_MAX
187         printf("sizeof(int64_t)=%u\n", (unsigned)sizeof(int64_t));
188         printf("sizeof(uint64_t)=%u\n", (unsigned)sizeof(uint64_t));
189 #endif
190 #ifdef  INT72_MAX
191         printf("sizeof(int72_t)=%u\n", (unsigned)sizeof(int72_t));
192         printf("sizeof(uint72_t)=%u\n", (unsigned)sizeof(uint72_t));
193 #endif
194 #ifdef  INT128_MAX
195         printf("sizeof(int128_t)=%u\n", (unsigned)sizeof(int128_t));
196         printf("sizeof(uint128_t)=%u\n", (unsigned)sizeof(uint128_t));
197 #endif
198         printf("sizeof(int_least8_t)=%u\n", (unsigned)sizeof(int_least8_t));
199         printf("sizeof(uint_least8_t)=%u\n", (unsigned)sizeof(uint_least8_t));
200         printf("sizeof(int_least16_t)=%u\n", (unsigned)sizeof(int_least16_t));
201         printf("sizeof(uint_least16_t)=%u\n", (unsigned)sizeof(uint_least16_t));
202         printf("sizeof(int_least32_t)=%u\n", (unsigned)sizeof(int_least32_t));
203         printf("sizeof(uint_least32_t)=%u\n", (unsigned)sizeof(uint_least32_t));
204 #ifdef  INT_LEAST64_MAX
205         printf("sizeof(int_least64_t)=%u\n", (unsigned)sizeof(int_least64_t));
206         printf("sizeof(uint_least64_t)=%u\n", (unsigned)sizeof(uint_least64_t));
207 #else
208         printf("*** uint_least64_t isn't defined ***\n");
209         status = EXIT_FAILURE;
210 #endif
211 #ifdef  INT_LEAST128_MAX
212         printf("sizeof(int_least128_t)=%u\n", (unsigned)sizeof(int_least128_t));
213         printf("sizeof(uint_least128_t)=%u\n",
214                 (unsigned)sizeof(uint_least128_t));
215 #endif
216         printf("sizeof(int_fast8_t)=%u\n", (unsigned)sizeof(int_fast8_t));
217         printf("sizeof(uint_fast8_t)=%u\n", (unsigned)sizeof(uint_fast8_t));
218         printf("sizeof(int_fast16_t)=%u\n", (unsigned)sizeof(int_fast16_t));
219         printf("sizeof(uint_fast16_t)=%u\n", (unsigned)sizeof(uint_fast16_t));
220         printf("sizeof(int_fast32_t)=%u\n", (unsigned)sizeof(int_fast32_t));
221         printf("sizeof(uint_fast32_t)=%u\n", (unsigned)sizeof(uint_fast32_t));
222 #ifdef  INT_FAST64_MAX
223         printf("sizeof(int_fast64_t)=%u\n", (unsigned)sizeof(int_fast64_t));
224         printf("sizeof(uint_fast64_t)=%u\n", (unsigned)sizeof(uint_fast64_t));
225 #else
226         printf("*** int_fast64_t isn't defined ***\n");
227         status = EXIT_FAILURE;
228 #endif
229 #ifdef  INT_FAST128_MAX
230         printf("sizeof(int_fast128_t)=%u\n", (unsigned)sizeof(int_fast128_t));
231         printf("sizeof(uint_fast128_t)=%u\n", (unsigned)sizeof(uint_fast128_t));
232 #endif
233 #if     defined(INTPTR_MAX)
234         printf("sizeof(intptr_t)=%u\n", (unsigned)sizeof(intptr_t));
235 #if     defined(UINTPTR_MAX)
236         printf("sizeof(uintptr_t)=%u\n", (unsigned)sizeof(uintptr_t));
237 #else
238         printf("*** intptr_t is defined but uintptr_t isn't ***\n");
239         status = EXIT_FAILURE;
240 #endif
241 #elif   defined(UINTPTR_MAX)
242         printf("sizeof(uintptr_t)=%u\n", (unsigned)sizeof(uintptr_t));
243         printf("*** uintptr_t is defined but intptr_t isn't ***\n");
244         status = EXIT_FAILURE;
245 #else
246         printf("*** neither intptr_t nor uintptr_t is defined ***\n");
247         status = EXIT_FAILURE;
248 #endif
249 #ifdef  INTMAX_MAX
250         printf("sizeof(intmax_t)=%u\n", (unsigned)sizeof(intmax_t));
251         printf("sizeof(uintmax_t)=%u\n", (unsigned)sizeof(uintmax_t));
252 #else
253         printf("*** intmax_t isn't defined ***\n");
254         status = EXIT_FAILURE;
255 #endif
256
257 #ifdef  INT8_MAX
258         printf("INT8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT8_MIN);
259         printf("INT8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT8_MAX);
260         printf("UINT8_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT8_MAX);
261 #endif
262 #ifdef  INT9_MAX
263         printf("INT9_MIN=%"PRIdMAX"\n", (__Q8_MT)INT9_MIN);
264         printf("INT9_MAX=%"PRIdMAX"\n", (__Q8_MT)INT9_MAX);
265         printf("UINT9_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT9_MAX);
266 #endif
267 #ifdef  INT12_MAX
268         printf("INT12_MIN=%"PRIdMAX"\n", (__Q8_MT)INT12_MIN);
269         printf("INT12_MAX=%"PRIdMAX"\n", (__Q8_MT)INT12_MAX);
270         printf("UINT12_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT12_MAX);
271 #endif
272 #ifdef  INT16_MAX
273         printf("INT16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT16_MIN);
274         printf("INT16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT16_MAX);
275         printf("UINT16_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT16_MAX);
276 #endif
277 #ifdef  INT18_MAX
278         printf("INT18_MIN=%"PRIdMAX"\n", (__Q8_MT)INT18_MIN);
279         printf("INT18_MAX=%"PRIdMAX"\n", (__Q8_MT)INT18_MAX);
280         printf("UINT18_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT18_MAX);
281 #endif
282 #ifdef  INT24_MAX
283         printf("INT24_MIN=%"PRIdMAX"\n", (__Q8_MT)INT24_MIN);
284         printf("INT24_MAX=%"PRIdMAX"\n", (__Q8_MT)INT24_MAX);
285         printf("UINT24_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT24_MAX);
286 #endif
287 #ifdef  INT32_MAX
288         printf("INT32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT32_MIN);
289         printf("INT32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT32_MAX);
290         printf("UINT32_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT32_MAX);
291 #endif
292 #ifdef  INT36_MAX
293         printf("INT36_MIN=%"PRIdMAX"\n", (__Q8_MT)INT36_MIN);
294         printf("INT36_MAX=%"PRIdMAX"\n", (__Q8_MT)INT36_MAX);
295         printf("UINT36_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT36_MAX);
296 #endif
297 #ifdef  INT40_MAX
298         printf("INT40_MIN=%"PRIdMAX"\n", (__Q8_MT)INT40_MIN);
299         printf("INT40_MAX=%"PRIdMAX"\n", (__Q8_MT)INT40_MAX);
300         printf("UINT40_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT40_MAX);
301 #endif
302 #ifdef  INT48_MAX
303         printf("INT48_MIN=%"PRIdMAX"\n", (__Q8_MT)INT48_MIN);
304         printf("INT48_MAX=%"PRIdMAX"\n", (__Q8_MT)INT48_MAX);
305         printf("UINT48_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT48_MAX);
306 #endif
307 #ifdef  INT60_MAX
308         printf("INT60_MIN=%"PRIdMAX"\n", (__Q8_MT)INT60_MIN);
309         printf("INT60_MAX=%"PRIdMAX"\n", (__Q8_MT)INT60_MAX);
310         printf("UINT60_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT60_MAX);
311 #endif
312 #ifdef  INT64_MAX
313         printf("INT64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT64_MIN);
314         printf("INT64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT64_MAX);
315         printf("UINT64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT64_MAX);
316 #endif
317 #ifdef  INT72_MAX
318         printf("INT72_MIN=%"PRIdMAX"\n", (__Q8_MT)INT72_MIN);
319         printf("INT72_MAX=%"PRIdMAX"\n", (__Q8_MT)INT72_MAX);
320         printf("UINT72_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT72_MAX);
321 #endif
322 #ifdef  INT128_MAX
323         printf("INT128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT128_MIN);
324         printf("INT128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT128_MAX);
325         printf("UINT128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT128_MAX);
326 #endif
327         printf("INT_LEAST8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST8_MIN);
328         printf("INT_LEAST8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST8_MAX);
329         printf("UINT_LEAST8_MAX=%"PRIuMAX"\n",
330                 (U__Q8_MT)UINT_LEAST8_MAX);
331         printf("INT_LEAST16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST16_MIN);
332         printf("INT_LEAST16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST16_MAX);
333         printf("UINT_LEAST16_MAX=%"PRIuMAX"\n",
334                 (U__Q8_MT)UINT_LEAST16_MAX);
335         printf("INT_LEAST32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST32_MIN);
336         printf("INT_LEAST32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST32_MAX);
337         printf("UINT_LEAST32_MAX=%"PRIuMAX"\n",
338                 (U__Q8_MT)UINT_LEAST32_MAX);
339 #ifdef  INT_LEAST64_MAX
340         printf("INT_LEAST64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST64_MIN);
341         printf("INT_LEAST64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST64_MAX);
342         printf("UINT_LEAST64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_LEAST64_MAX);
343 #endif
344 #ifdef  INT_LEAST128_MAX
345         printf("INT_LEAST128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST128_MIN);
346         printf("INT_LEAST128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_LEAST128_MAX);
347         printf("UINT_LEAST128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_LEAST128_MAX);
348 #endif
349         printf("INT_FAST8_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST8_MIN);
350         printf("INT_FAST8_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST8_MAX);
351         printf("UINT_FAST8_MAX=%"PRIuMAX"\n",
352                 (U__Q8_MT)UINT_FAST8_MAX);
353         printf("INT_FAST16_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST16_MIN);
354         printf("INT_FAST16_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST16_MAX);
355         printf("UINT_FAST16_MAX=%"PRIuMAX"\n",
356                 (U__Q8_MT)UINT_FAST16_MAX);
357         printf("INT_FAST32_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST32_MIN);
358         printf("INT_FAST32_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST32_MAX);
359         printf("UINT_FAST32_MAX=%"PRIuMAX"\n",
360                 (U__Q8_MT)UINT_FAST32_MAX);
361 #ifdef  INT_FAST64_MAX
362         printf("INT_FAST64_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST64_MIN);
363         printf("INT_FAST64_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST64_MAX);
364         printf("UINT_FAST64_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_FAST64_MAX);
365 #endif
366 #ifdef  INT_FAST128_MAX
367         printf("INT_FAST128_MIN=%"PRIdMAX"\n", (__Q8_MT)INT_FAST128_MIN);
368         printf("INT_FAST128_MAX=%"PRIdMAX"\n", (__Q8_MT)INT_FAST128_MAX);
369         printf("UINT_FAST128_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINT_FAST128_MAX);
370 #endif
371 #ifdef  INTPTR_MAX
372         printf("INTPTR_MIN=%"PRIdMAX"\n", (__Q8_MT)INTPTR_MIN);
373         printf("INTPTR_MAX=%"PRIdMAX"\n", (__Q8_MT)INTPTR_MAX);
374 #endif
375 #ifdef  UINTPTR_MAX
376         printf("UINTPTR_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINTPTR_MAX);
377 #endif
378 #ifdef  INTMAX_MAX
379         printf("INTMAX_MIN=%"PRIdMAX"\n", (__Q8_MT)INTMAX_MIN);
380         printf("INTMAX_MAX=%"PRIdMAX"\n", (__Q8_MT)INTMAX_MAX);
381         printf("UINTMAX_MAX=%"PRIuMAX"\n", (U__Q8_MT)UINTMAX_MAX);
382 #endif
383 #ifdef  PTRDIFF_MAX
384         printf("PTRDIFF_MIN=%"PRIdMAX"\n", (__Q8_MT)PTRDIFF_MIN);
385         printf("PTRDIFF_MAX=%"PRIdMAX"\n", (__Q8_MT)PTRDIFF_MAX);
386 #endif
387 #ifdef  SIG_ATOMIC_MAX
388 #if     SIG_ATOMIC_MIN < 0
389         printf("SIG_ATOMIC_MIN=%"PRIdMAX"\n", (__Q8_MT)SIG_ATOMIC_MIN);
390         printf("SIG_ATOMIC_MAX=%"PRIdMAX"\n", (__Q8_MT)SIG_ATOMIC_MAX);
391 #else
392         printf("SIG_ATOMIC_MIN=%"PRIuMAX"\n", (U__Q8_MT)SIG_ATOMIC_MIN);
393         printf("SIG_ATOMIC_MAX=%"PRIuMAX"\n", (U__Q8_MT)SIG_ATOMIC_MAX);
394 #endif
395 #endif
396 #ifdef  SIZE_MAX
397         printf("SIZE_MAX=%"PRIuMAX"\n", (U__Q8_MT)SIZE_MAX);
398 #endif
399
400 #ifdef  WCHAR_MAX
401 #if     WCHAR_MIN < 0
402         printf("WCHAR_MIN=%"PRIdMAX"\n", (__Q8_MT)WCHAR_MIN);
403         printf("WCHAR_MAX=%"PRIdMAX"\n", (__Q8_MT)WCHAR_MAX);
404 #else
405         printf("WCHAR_MIN=%"PRIuMAX"\n", (U__Q8_MT)WCHAR_MIN);
406         printf("WCHAR_MAX=%"PRIuMAX"\n", (U__Q8_MT)WCHAR_MAX);
407 #endif
408 #endif
409 #ifdef  WINT_MAX
410 #if     WINT_MIN < 0
411         printf("WINT_MIN=%"PRIdMAX"\n", (__Q8_MT)WINT_MIN);
412         printf("WINT_MAX=%"PRIdMAX"\n", (__Q8_MT)WINT_MAX);
413 #else
414         printf("WINT_MIN=%"PRIuMAX"\n", (U__Q8_MT)WINT_MIN);
415         printf("WINT_MAX=%"PRIuMAX"\n", (U__Q8_MT)WINT_MAX);
416 #endif
417 #endif
418
419         /*
420                 7.18.4  Macros for integer constants
421         */
422
423         /* INTn_C for n=8 and 16 were at one point unimplementable
424            on most platforms, so they're treated as "optional": */
425 #ifdef  INT8_C
426         if ( INT8_C(-123) != -123 )
427                 printf("*** INT8_C(-123) produced %"PRIdMAX" ***\n",
428                        (__Q8_MT)INT8_C(-123)
429                       );
430         if ( UINT8_C(123) != 123 )
431                 printf("*** UINT8_C(123) produced %"PRIuMAX" ***\n",
432                        (U__Q8_MT)UINT8_C(123)
433                       );
434 #endif
435 #ifdef  INT16_C
436         if ( INT16_C(-12345) != -12345 )
437                 printf("*** INT16_C(-12345) produced %"PRIdMAX" ***\n",
438                        (__Q8_MT)INT16_C(-12345)
439                       );
440         if ( UINT16_C(12345) != 12345 )
441                 printf("*** UINT16_C(12345) produced %"PRIuMAX" ***\n",
442                        (U__Q8_MT)UINT16_C(12345)
443                       );
444 #endif
445         if ( INT32_C(-123456789) != -123456789 )
446                 printf("*** INT32_C(-123456789) produced %"PRIdMAX" ***\n",
447                        (__Q8_MT)INT32_C(-123456789)
448                       );
449         if ( UINT32_C(123456789) != 123456789 )
450                 printf("*** UINT32_C(123456789) produced %"PRIuMAX" ***\n",
451                        (U__Q8_MT)UINT32_C(123456789)
452                       );
453 #ifdef  INT_LEAST64_MAX
454         if ( INT64_C(-1234567890123456789) != -1234567890123456789 )
455                 printf("*** INT64_C(-1234567890123456789) produced %"PRIdMAX
456                        " ***\n",
457                        (__Q8_MT)INT64_C(-1234567890123456789)
458                       );
459         if ( UINT64_C(1234567890123456789) != 1234567890123456789 )
460                 printf("*** UINT64_C(1234567890123456789) produced %"PRIuMAX
461                        " ***\n",
462                        (U__Q8_MT)UINT64_C(1234567890123456789)
463                       );
464 #endif
465 #ifdef  INTMAX_MAX
466         if ( INTMAX_C(-1234567890123456789) != -1234567890123456789 )
467                 printf("*** INTMAX_C(-1234567890123456789) produced %"PRIdMAX
468                        " ***\n",
469                        (__Q8_MT)INTMAX_C(-1234567890123456789)
470                       );
471         if ( UINTMAX_C(1234567890123456789) != 1234567890123456789 )
472                 printf("*** UINTMAX_C(1234567890123456789) produced %"PRIuMAX
473                        " ***\n",
474                        (U__Q8_MT)UINTMAX_C(1234567890123456789)
475                       );
476 #endif
477
478         /* <inttypes.h> features: */
479
480 #if     __STDC_VERSION__ >= 199901
481         printf("sizeof(imaxdiv_t)=%u\n", (unsigned)sizeof(imaxdiv_t));
482 #endif
483
484         /*
485                 7.8.1   Macros for format specifiers
486         */
487
488         {
489         /* scanf these strings */
490         static const char       in_dn[] = "Z119bZ";
491         static const char       in_dmo[] = "Z-0119bZ";
492         static const char       in_dspx[] = "Z \t\n +0X119bZ";
493         static const char       in_dsmx[] = "Z \t\n -0x119bZ";
494         static const char       in_dsn[] = "Z \t\n 119bZ";
495         static const char       in_dp[] = "Z+119bZ";
496         static const char       in_dpx[] = "Z+0X119bz";
497
498         /* sprintf into this */
499         static char             buffer[1024];
500
501 #if 1
502
503 #define SCAN(buf,fs,var,exp)    if ( sscanf(buf, "Z%" fs, &var) != 1 ) \
504                                         { \
505                                         printf("***%s=",fs, STR_SUB(fs) \
506                                                " failed ***\n" \
507                                               ); \
508                                         status = EXIT_FAILURE; \
509                                         } \
510                                 else if ( var != (exp) ) \
511                                         { \
512                                         printf("***%s=",fs,  STR_SUB(fs) \
513                                                " should be: " STR_SUB(exp) \
514                                                ", was: %" fs " ***\n", var \
515                                               ); \
516                                         status = EXIT_FAILURE; \
517                                         } \
518                                 else    /* for trailing semicolon */
519
520 #define PRINT(fs,var,exp)       if ( sprintf(buffer, "%" fs, var ) <= 0 ) \
521                                         { \
522                                         printf("***%s=",fs, STR_SUB(fs) \
523                                                " failed ***\n" \
524                                               ); \
525                                         status = EXIT_FAILURE; \
526                                         } \
527                                 else if ( strcmp(buffer, STR_SUB(exp)) != 0 ) \
528                                         { \
529                                         printf("***%s=",fs,  STR_SUB(fs) \
530                                                " should be: " STR_SUB(exp) \
531                                                ", was: %s ***\n", buffer \
532                                               ); \
533                                         status = EXIT_FAILURE; \
534                                         } \
535                                 else    /* for trailing semicolon */
536
537 #else
538                                                                  
539 #define SCAN(buf,fs,var,exp)
540 #define PRINT(fs,var,exp)
541
542 #endif
543                                                                  
544 #ifdef  SCNo32
545
546         SCAN(in_dn, SCNo32, int32, 9);
547
548 #endif
549 #ifdef  PRIo32
550         PRINT(PRIo32, int32, 11);
551 #endif
552         SCAN(in_dmo, SCNiLEAST16, intl16, -9);
553         SCAN(in_dspx, SCNdLEAST16, intl16, 0);
554         SCAN(in_dsmx, SCNiLEAST16, intl16, -4507);
555         PRINT(PRIdLEAST16, intl16, -4507);
556         PRINT(PRIiLEAST16, intl16, -4507);
557         SCAN(in_dsn, SCNxLEAST16, uintl16, 4507);
558         PRINT(PRIoLEAST16, uintl16, 10633);
559         PRINT(PRIuLEAST16, uintl16, 4507);
560         PRINT(PRIxLEAST16, uintl16, 119b);
561         PRINT(PRIXLEAST16, uintl16, 119B);
562         SCAN(in_dp, SCNxFAST16, uintf16, 4507);
563         PRINT(PRIxFAST16, uintf16, 119b);
564 #ifdef  SCNdMAX
565         SCAN(in_dp, SCNdMAX, intmax, 119);
566 #endif
567 #ifdef  PRIiMAX
568         PRINT(PRIiMAX, intmax, 119);
569 #endif
570 #ifdef  SCNoMAX
571         SCAN(in_dpx, SCNoMAX, uintmax, 0);
572 #endif
573 #ifdef  PRIxMAX
574         PRINT(PRIxMAX, uintmax, 0);
575 #endif
576         /* Obviously there should be a much larger battery of such tests. */
577         }
578
579 #if     defined(INTMAX_MAX)             /* <inttypes.h> has C99 features */
580         /*
581                 7.8.2   Functions for greatest-width integer types
582         */
583
584         {
585         static struct
586                 {
587                 intmax_t        input;
588                 intmax_t        expect;
589                 }       abs_data[] =
590                 {
591 #ifdef  INT8_MAX
592           { INT8_MAX,           INT8_MAX,   },
593           { -INT8_MAX,          INT8_MAX,   },
594          {      UINT8_MAX,              UINT8_MAX,  },
595 #endif
596
597 #if 0
598   
599 #ifdef  INT16_MAX
600          {      INT16_MAX,              INT16_MAX,  },
601          {      -INT16_MAX,             INT16_MAX,  },
602          {      UINT16_MAX,             UINT16_MAX, },
603 #endif
604 #ifdef  INT32_MAX
605          {      INT32_MAX,              INT32_MAX,  },
606          {      -INT32_MAX,             INT32_MAX,  },
607 #ifdef  INT_LEAST64_MAX                 /* else might support only 32 bits */
608          {      UINT32_MAX,             UINT32_MAX, },
609 #endif
610 #endif
611 #ifdef  INT64_MAX
612          {      INT64_MAX,              INT64_MAX,  },
613          {      -INT64_MAX,             INT64_MAX,  },
614 #endif
615          {      INT_LEAST8_MAX,         INT_LEAST8_MAX,      },
616          {      -INT_LEAST8_MAX,        INT_LEAST8_MAX,      },
617          {      UINT_LEAST8_MAX,        UINT_LEAST8_MAX,     },
618          {      INT_LEAST16_MAX,        INT_LEAST16_MAX,     },
619          {      -INT_LEAST16_MAX,       INT_LEAST16_MAX,     },
620          {      UINT_LEAST16_MAX,       UINT_LEAST16_MAX,    },
621          {      INT_LEAST32_MAX,        INT_LEAST32_MAX,     },
622          {      -INT_LEAST32_MAX,       INT_LEAST32_MAX,     },
623 #ifdef  INT_LEAST64_MAX
624          {      UINT_LEAST32_MAX,       UINT_LEAST32_MAX,    },
625          {      INT_LEAST64_MAX,        INT_LEAST64_MAX,     },
626          {      -INT_LEAST64_MAX,       INT_LEAST64_MAX,     },
627 #endif
628          {      INT_FAST8_MAX,          INT_FAST8_MAX,       },
629          {      -INT_FAST8_MAX, INT_FAST8_MAX,           },
630          {      UINT_FAST8_MAX, UINT_FAST8_MAX,          },
631          {      INT_FAST16_MAX, INT_FAST16_MAX,          },
632          {      -INT_FAST16_MAX,        INT_FAST16_MAX,      },
633          {      UINT_FAST16_MAX,        UINT_FAST16_MAX,     },
634          {      INT_FAST32_MAX, INT_FAST32_MAX,          },
635          {      -INT_FAST32_MAX,        INT_FAST32_MAX,      },
636 #ifdef  INT_FAST64_MAX
637          {      UINT_FAST32_MAX,        UINT_FAST32_MAX,     },
638          {      INT_FAST64_MAX, INT_FAST64_MAX,          },
639          {      -INT_FAST64_MAX,        INT_FAST64_MAX,      },
640 #endif
641 #ifdef  INTPTR_MAX
642          {      INTPTR_MAX,             INTPTR_MAX,              },
643          {      -INTPTR_MAX,            INTPTR_MAX,          },
644 #endif
645 #ifdef  UINTPTR_MAX
646          {      UINTPTR_MAX,            UINTPTR_MAX,         },
647 #endif
648          {      INTMAX_MAX,             INTMAX_MAX,              },
649 #ifdef  PTRDIFF_MAX
650          {      PTRDIFF_MAX,            PTRDIFF_MAX,         },
651 #endif
652 #ifdef  SIG_ATOMIC_MAX
653          {      SIG_ATOMIC_MAX,         SIG_ATOMIC_MAX,      },
654 #if     SIG_ATOMIC_MIN < 0
655          {      -SIG_ATOMIC_MAX,        SIG_ATOMIC_MAX,      },
656 #endif
657 #endif
658 #ifdef  SIZE_MAX
659          {      SIZE_MAX,               SIZE_MAX,                },
660 #endif
661 #ifdef  WCHAR_MAX
662          {      WCHAR_MAX,              WCHAR_MAX,               },
663 #if     WCHAR_MIN < 0
664          {      -WCHAR_MAX,             WCHAR_MAX,               },
665 #endif
666 #endif
667 #ifdef  WINT_MAX
668          {      WINT_MAX,               WINT_MAX,                },
669 #if     WINT_MIN < 0
670          {  -WINT_MAX,          WINT_MAX,                },
671 #endif
672 #endif
673          {      127,                            127,                 },
674          {      -127,                           127,                 },
675          {      128,                            128,                 },
676          {      -127-1,                         128,                 },
677          {      255,                            255,                 },
678          {      -256+1,                         255,                 },
679          {      256,                            256,                 },
680          {      -256,                           256,                 },
681          {      32767,                          32767,               },
682          {      -32767,                         32767,               },
683          {      32768,                          32768,               },
684          {      -32767-1,                       32768,               },
685          {      65535,                          65535,               },
686          {      -65536+1,                       65535,               },
687          {      65536,                          65536,               },
688          {      -65536,                         65536,               },
689          {      2147483647,                     2147483647,          },
690          {      -2147483647,                    2147483647,      },
691          {      2147483648,                     2147483648,          },
692          {      -2147483647-1,                  2147483648,      },
693 #ifdef  INT_LEAST64_MAX                 /* else might support only 32 bits */
694          {      4294967295,                     4294967295,          },
695          {      -4294967296+1,                  4294967295,      },
696          {      4294967296,                     4294967296,          },
697          {      -4294967296,                    4294967296,      },
698          {      9223372036854775807,            9223372036854775807,    },
699          {      -9223372036854775807,           9223372036854775807,    },
700          {      1234567890123456789,            1234567890123456789,    },
701          {      -1234567890123456789,           1234567890123456789,    },
702 #endif
703          {      1,                              1,                                  },
704          {      -1,                             1,                                  },
705          {      2,                              2,                                  },
706          {      -2,                             2,                                  },
707          {      10,                             10,                                 },
708          {      -10,                            10,                             },
709          {      16,                             16,                                 },
710          {      -16,                            16,                             },
711 #endif
712                 /* Other test cases can be added here. */
713          {      0,              0       /* terminates the list */              },
714                 },      *adp = abs_data;
715
716         do      {
717                 if ( (intmax = imaxabs(adp->input)) != adp->expect )
718                         {
719                         printf("*** imaxabs(%"PRIdMAX") failed; should be: %"
720                                PRIdMAX", was: %"PRIdMAX" ***\n",
721                                adp->input, adp->expect, intmax
722                               );
723                         status = EXIT_FAILURE;
724                         }
725 //              } while ( adp++->input != 0 );
726                 } while ( (adp++)->input != 0 );
727         }
728
729         {
730         imaxdiv_t       result;
731         static struct
732                 {
733                 intmax_t        numer;
734                 intmax_t        denom;
735                 intmax_t        exp_quot;
736                 intmax_t        exp_rem;
737                 }       div_data[] =
738                 {
739         {       0, 1,                           0, 0,   },
740 #if 0
741         {       0, -1,                          0, 0,   },
742         {       0, 2,                           0, 0,   },
743         {       0, -2,                          0, 0,   },
744         {       0, 5,                           0, 0,   },
745         {       0, -5,                          0, 0,   },
746         {       1, 1,                           1, 0,   },
747         {       1, -1,                          -1, 0,  },
748         {       1, 2,                           0, 1,   },
749         {       1, -2,                          0, 1,   },
750         {       1, 5,                           0, 1,   },
751         {       1, -5,                          0, 1,   },
752         {       -1, 1,                          -1, 0,  },
753         {       -1, -1,                         1, 0,   },
754         {       -1, 2,                          0, -1,  },
755         {       -1, -2,                         0, -1,  },
756         {       -1, 5,                          0, -1,  },
757         {       -1, -5,                         0, -1,  },
758         {       2, 1,                           2, 0,   },
759         {       2, -1,                          -2, 0,  },
760         {       2, 2,                           1, 0,   },
761         {       2, -2,                          -1, 0,  },
762         {       2, 5,                           0, 2,   },
763         {       2, -5,                          0, 2,   },
764         {       -2, 1,                          -2, 0,  },
765         {       -2, -1,                         2, 0,   },
766         {       -2, 2,                          -1, 0,  },
767         {       -2, -2,                         1, 0,   },
768         {       -2, 5,                          0, -2,  },
769         {       -2, -5,                         0, -2,  },
770         {       17, 5,                          3, 2,   },
771         {       -17, -5,                        3, -2,  },
772         {       17, -5,                         -3, 2,  },
773         {       -17, 5,                         -3, -2, },
774         {       2147483647, 1,                  2147483647, 0,         },
775         {       -2147483647, 1,                 -2147483647, 0,        },
776         {       2147483648, 1,                  2147483648, 0,         },
777         {       -2147483647-1, 1,               -2147483647-1, 0,      },
778         {       2147483647, 2,                  1073741823, 1,         },
779         {       -2147483647, 2,                 -1073741823, -1,       },
780         {       2147483648, 2,                  1073741824, 0,         },
781         {       -2147483647-1, 2,               -1073741824, 0,        },
782 #ifdef  INT_LEAST64_MAX                 /* else might support only 32 bits */
783         {       4294967295, 1,                  4294967295, 0,         },
784         {       -4294967296+1, 1,               -4294967296+1, 0,      },
785         {       4294967296, 1,                  4294967296, 0,         },
786         {       -4294967296, 1,                 -4294967296, 0,        },
787         {       4294967295, -1,                 -4294967296+1, 0,      },
788         {       -4294967296+1, -1,              4294967295, 0,         },
789         {       4294967296, -1,                 -4294967296, 0,        },
790         {       -4294967296, -1,                4294967296, 0,         },
791         {       4294967295, 2,                  2147483647, 1,         },
792         {       -4294967296+1, 2,               -2147483647, -1,       },
793         {       4294967296, 2,                  2147483648, 0,         },
794         {       -4294967296, 2,                 -2147483647-1, 0,      },
795         {       4294967295, 2147483647,         2, 1,              },
796         {       -4294967296+1, 2147483647,      -2, -1,            },
797         {       4294967296, 2147483647,         2, 2,              },
798         {       -4294967296, 2147483647,        -2, -2,            },
799         {       4294967295, -2147483647,        -2, 1,             },
800         {       -4294967296+1, -2147483647,     2, -1,             },
801         {       4294967296, -2147483647,        -2, 2,             },
802         {       -4294967296, -2147483647,       2, -2,             },
803         {       4294967295, 2147483648,         1, 2147483647,     },
804         {       -4294967296+1, 2147483648,      -1, -2147483647,   },
805         {       4294967296, 2147483648,         2, 0,              },
806         {       -4294967296, 2147483648,        -2, 0,             },
807         {       4294967295, -2147483647-1,      -1, 2147483647,    },
808         {       -4294967296+1, -2147483647-1,   1, -2147483647,},
809         {       4294967296, -2147483647-1,      -2, 0,             },
810         {       -4294967296, -2147483647-1,     2, 0,              },
811         {       9223372036854775807, 1,         9223372036854775807, 0,         },
812         {       -9223372036854775807, 1,        -9223372036854775807, 0,        },
813         {       9223372036854775807, 2,         4611686018427387903, 1,         },
814         {       -9223372036854775807, 2,        -4611686018427387903, -1,       },
815 #endif
816 #endif
817                 /* There should be a much larger battery of such tests. */
818         {       0, 0,           0, 0 }, /* 0 denom terminates the list */
819                 },      *ddp;
820
821 #if 0
822         for ( ddp = div_data; ddp->denom != 0; ++ddp )
823                 if ( (result = imaxdiv(ddp->numer, ddp->denom)).quot
824                      != ddp->exp_quot || result.rem != ddp->exp_rem
825                    )    {
826 //                      printf("*** imaxdiv(%"PRIdMAX",%"PRIdMAX
827 //                             ") failed; should be: (%"PRIdMAX",%"PRIdMAX
828 //                             "), was: (%"PRIdMAX",%"PRIdMAX") ***\n",
829 //                             ddp->numer, ddp->denom, ddp->exp_quot,
830 //                             ddp->exp_rem, result.quot, result.rem
831 //                            );
832                         printf("err:imaxdiv(%"PRIdMAX",%"PRIdMAX
833                                ") = (%"PRIdMAX",%"PRIdMAX
834                                "), is: (%"PRIdMAX",%"PRIdMAX")\n",
835                                ddp->numer, ddp->denom, ddp->exp_quot,
836                                ddp->exp_rem, result.quot, result.rem
837                               );
838                         status = EXIT_FAILURE;
839                         }
840 #endif
841         }
842         
843         {
844         char            *endptr;
845         wchar_t         *wendptr;
846         static char     saved[64];      /* holds copy of input string */
847         static wchar_t  wnptr[64];      /* holds wide copy of test string */
848         static int      warned;         /* "warned for null endptr" flag */
849         register int    i;
850         static struct
851                 {
852                 char *          nptr;
853                 int             base;
854                 intmax_t        exp_val;
855                 int             exp_len;
856                 }       str_data[] =
857                 {
858         {       "", 0,                          0, 0,      },
859         {       "", 2,                          0, 0,      },
860         {       "", 8,                          0, 0,      },
861         {       "", 9,                          0, 0,      },
862         {       "", 10,                         0, 0,      },
863         {       "", 16,                         0, 0,      },
864         {       "", 36,                         0, 0,      },
865         {       "0", 0,                         0, 1,      },
866         {       "0", 2,                         0, 1,      },
867         {       "0", 8,                         0, 1,      },
868         {       "0", 9,                         0, 1,      },
869         {       "0", 10,                        0, 1,      },
870         {       "0", 16,                        0, 1,      },
871         {       "0", 36,                        0, 1,      },
872         {       "+0", 0,                        0, 2,      },
873         {       "+0", 2,                        0, 2,      },
874         {       "+0", 8,                        0, 2,      },
875         {       "+0", 9,                        0, 2,      },
876         {       "+0", 10,                       0, 2,      },
877         {       "+0", 16,                       0, 2,      },
878         {       "+0", 36,                       0, 2,      },
879         {       "-0", 0,                        0, 2,      },
880         {       "-0", 2,                        0, 2,      },
881         {       "-0", 8,                        0, 2,      },
882         {       "-0", 9,                        0, 2,      },
883         {       "-0", 10,                       0, 2,      },
884         {       "-0", 16,                       0, 2,      },
885         {       "-0", 36,                       0, 2,      },
886         {       "Inf", 0,                       0, 0,      },
887         {       "Inf", 2,                       0, 0,      },
888         {       "Inf", 8,                       0, 0,      },
889         {       "Inf", 9,                       0, 0,      },
890         {       "Inf", 10,                      0, 0,      },
891         {       "Inf", 16,                      0, 0,      },
892         {       "Inf", 36,                      24171, 3,  },
893         {       "+Inf", 0,                      0, 0,      },
894         {       "+Inf", 2,                      0, 0,      },
895         {       "+Inf", 8,                      0, 0,      },
896         {       "+Inf", 9,                      0, 0,      },
897         {       "+Inf", 10,                     0, 0,      },
898         {       "+Inf", 16,                     0, 0,      },
899         {       "+Inf", 36,                     24171, 4,  },
900         {       "-Inf", 0,                      0, 0,      },
901         {       "-Inf", 2,                      0, 0,      },
902         {       "-Inf", 8,                      0, 0,      },
903         {       "-Inf", 9,                      0, 0,      },
904         {       "-Inf", 10,                     0, 0,      },
905         {       "-Inf", 16,                     0, 0,      },
906         {       "-Inf", 36,                     -24171, 4, },
907         {       "inf", 0,                       0, 0,      },
908         {       "inf", 2,                       0, 0,      },
909         {       "inf", 8,                       0, 0,      },
910         {       "inf", 9,                       0, 0,      },
911         {       "inf", 10,                      0, 0,      },
912         {       "inf", 16,                      0, 0,      },
913         {       "inf", 36,                      24171, 3,  },
914         {       "+inf", 0,                      0, 0,      },
915         {       "+inf", 2,                      0, 0,      },
916         {       "+inf", 8,                      0, 0,      },
917         {       "+inf", 9,                      0, 0,      },
918         {       "+inf", 10,                     0, 0,      },
919         {       "+inf", 16,                     0, 0,      },
920         {       "+inf", 36,                     24171, 4,  },
921         {       "-inf", 0,                      0, 0,      },
922         {       "-inf", 2,                      0, 0,      },
923         {       "-inf", 8,                      0, 0,      },
924         {       "-inf", 9,                      0, 0,      },
925         {       "-inf", 10,                     0, 0,      },
926         {       "-inf", 16,                     0, 0,      },
927         {       "-inf", 36,                     -24171, 4, },
928         {       "119b8Z", 0,                    119, 3,         },
929         {       "119bZ", 0,                     119, 3,             },
930         {       "-0119bZ", 0,                   -9, 4,          },
931         {       " \t\n 0X119bZ", 0,             4507, 10,       },
932         {       " \t\n +0X119bZ", 0,            4507, 11,   },
933         {       " \t\n -0x119bZ", 0,            -4507, 11,  },
934         {       " \t\n 119bZ", 0,               119, 7,         },
935         {       "+119bZ", 0,                    119, 4,         },
936         {       "+0X119bz", 0,                  4507, 7,        },
937         {       "119b8Z", 2,                    3, 2,           },
938         {       "119bZ", 2,                     3, 2,               },
939         {       "-0119bZ", 2,                   -3, 4,          },
940         {       " \t\n 0X119bZ", 2,             0, 5,           },
941         {       " \t\n +0X119bZ", 2,            0, 6,       },
942         {       " \t\n -0x119bZ", 2,            0, 6,       },
943         {       " \t\n 119bZ", 2,               3, 6,           },
944         {       "+119bZ", 2,                    3, 3,           },
945         {       "+0X119bz", 2,                  0, 2,           },
946         {       "119b8Z", 8,                    9, 2,           },
947         {       "119bZ", 8,                     9, 2,               },
948         {       "-0119bZ", 8,                   -9, 4,          },
949         {       " \t\n 0X119bZ", 8,             0, 5,           },
950         {       " \t\n +0X119bZ", 8,            0, 6,       },
951         {       " \t\n -0x119bZ", 8,            0, 6,       },
952         {       " \t\n 119bZ", 8,               9, 6,           },
953         {       "+119bZ", 8,                    9, 3,           },
954         {       "+0X119bz", 8,                  0, 2,           },
955         {       "119b8Z", 9,                    10, 2,          },
956         {       "119bZ", 9,                     10, 2,              },
957         {       "-0119bZ", 9,                   -10, 4,         },
958         {       " \t\n 0X119bZ", 9,             0, 5,           },
959         {       " \t\n +0X119bZ", 9,            0, 6,       },
960         {       " \t\n -0x119bZ", 9,            0, 6,       },
961         {       " \t\n 119bZ", 9,               10, 6,          },
962         {       "+119bZ", 9,                    10, 3,          },
963         {       "+0X119bz", 9,                  0, 2,           },
964         {       "119b8Z", 10,                   119, 3,         },
965         {       "119bZ", 10,                    119, 3,         },
966         {       "-0119bZ", 10,                  -119, 5,        },
967         {       " \t\n 0X119bZ", 10,            0, 5,       },
968         {       " \t\n +0X119bZ", 10,           0, 6,       },
969         {       " \t\n -0x119bZ", 10,           0, 6,       },
970         {       " \t\n 119bZ", 10,              119, 7,         },
971         {       "+119bZ", 10,                   119, 4,         },
972         {       "+0X119bz", 10,                 0, 2,           },
973         {       "119b8Z", 16,                   72120, 5,       },
974         {       "119bZ", 16,                    4507, 4,        },
975         {       "-0119bZ", 16,                  -4507, 6,       },
976         {       " \t\n 0X119bZ", 16,            4507, 10,   },
977         {       " \t\n +0X119bZ", 16,           4507, 11,   },
978         {       " \t\n -0x119bZ", 16,           -4507, 11,  },
979         {       " \t\n 119bZ", 16,              4507,8,         },
980         {       "+119bZ", 16,                   4507, 5,        },
981         {       "+0X119bz", 16,                 4507, 7,        },
982         {       "119b8Z", 36,                   62580275, 6,    },
983         {       "119bZ", 36,                    1738367, 5,     },
984         {       "-0119bZ", 36,                  -1738367, 7,                 },
985         {       " \t\n 0X119bZ", 36,            1997122175, 11,          },
986         {       " \t\n +0X119bZ", 36,           1997122175, 12,          },
987         {       " \t\n -0x119bZ", 36,           -1997122175, 12,         },
988         {       " \t\n 119bZ", 36,              1738367, 9,                  },
989         {       "+119bZ", 36,                   1738367, 6,                  },
990         {       "+0X119bz", 36,                 1997122175, 8,               },
991                 /* There should be a much larger battery of such tests. */
992         {       "127", 0,                       127, 3,                          },
993         {       "-127", 0,                      -127, 4,                         },
994         {       "128", 0,                       128, 3,                          },
995         {       "-128", 0,                      -127-1, 4,                       },
996         {       "255", 0,                       255, 3,                          },
997         {       "-255", 0,                      -255, 4,                         },
998         {       "256", 0,                       256, 3,                          },
999         {       "-256", 0,                      -255-1, 4,                       },
1000         {       "32767", 0,                     32767, 5,                        },
1001         {       "-32767", 0,                    -32767, 6,                   },
1002         {       "32768", 0,                     32768, 5,                        },
1003         {       "-32768", 0,                    -32767-1, 6,                 },
1004         {       "65535", 0,                     65535, 5,                        },
1005         {       "-65535", 0,                    -65536+1, 6,                 },
1006         {       "65536", 0,                     65536, 5,                        },
1007         {       "-65536", 0,                    -65536, 6,                   },
1008         {       "2147483647", 0,                2147483647, 10,              },
1009         {       "-2147483647", 0,               -2147483647, 11,             },
1010         {       "2147483648", 0,                2147483648, 10,              },
1011         {       "-2147483648", 0,               -2147483647-1, 11,           },
1012         {       "4294967295", 0,                4294967295, 10,              },
1013         {       "-4294967295", 0,               -4294967296+1, 11,           },
1014         {       "4294967296", 0,                4294967296, 10,              },
1015         {       "-4294967296", 0,               -4294967296, 11,                        },
1016         {       "9223372036854775807", 0,       9223372036854775807, 19,            },
1017         {       "-9223372036854775807", 0,      -9223372036854775807, 20,           },
1018         {       "1234567890123456789", 0,       1234567890123456789, 19,            },
1019         {       "-1234567890123456789", 0,      -1234567890123456789, 20,           },
1020         {       "1", 0,                         1, 1,                                       },
1021         {       "-1", 0,                        -1, 2,                                      },
1022         {       "2", 0,                         2, 1,                                       },
1023         {       "-2", 0,                        -2, 2,                                      },
1024         {       "10", 0,                        10, 2,                                      },
1025         {       "-10", 0,                       -10, 3,                                     },
1026         {       "16", 0,                        16, 2,                                      },
1027         {       "-16", 0,                       -16, 3,                                     },
1028                 /* Other test cases can be added here. */
1029         {       NULL, 0,        0, 0 }, /* terminates the list */
1030                 },      *sdp;
1031
1032         for ( sdp = str_data; sdp->nptr != NULL ; ++sdp )
1033                 {
1034                 /*
1035                         7.8.2.3 The strtoimax and strtoumax functions
1036                 */
1037
1038                 strcpy(saved, sdp->nptr);
1039
1040                 errno = 0;              /* shouldn't be changed */
1041
1042                 if ( (intmax = strtoimax(sdp->nptr, &endptr, sdp->base))
1043                   != sdp->exp_val
1044                    )    {
1045                         int     save = errno;
1046
1047                         printf("*** strtoimax(%s,,%d) failed; should be: %"
1048                                PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
1049                                sdp->base, sdp->exp_val, intmax
1050                               );
1051                         status = EXIT_FAILURE;
1052                         errno = save;
1053                         }
1054                 else if ( endptr != sdp->nptr + sdp->exp_len )
1055                         {
1056                         int     save = errno;
1057
1058                         printf("*** strtoimax(%s,,%d) returned wrong endptr"
1059                                " ***\n", sdp->nptr, sdp->base
1060                               );
1061                         status = EXIT_FAILURE;
1062                         errno = save;
1063                         }
1064
1065                 if ( errno != 0 )
1066                         {
1067                         printf("*** strtoimax modified errno ***\n");
1068                         status = EXIT_FAILURE;
1069                         }
1070
1071                 if ( strcmp(sdp->nptr, saved) != 0 )
1072                         {
1073                         printf("*** strtoimax modified its input ***\n");
1074                         status = EXIT_FAILURE;
1075                         strcpy(saved, sdp->nptr);
1076                         }
1077
1078                 if ( sdp->exp_val >= 0 )        /* else some sign extension */
1079                         {
1080                         errno = 0;      /* shouldn't be changed */
1081
1082                         if ( (uintmax = strtoumax(sdp->nptr, &endptr, sdp->base
1083                                                  )
1084                              ) != sdp->exp_val
1085                            )    {
1086                                 int     save = errno;
1087
1088                                 printf("*** strtoumax(%s,,%d) failed; "
1089                                        "should be: %"PRIuMAX", was: %"PRIuMAX
1090                                        " ***\n", sdp->nptr, sdp->base,
1091                                        sdp->exp_val, uintmax
1092                                       );
1093                                 status = EXIT_FAILURE;
1094                                 errno = save;
1095                                 }
1096                         else if ( endptr != sdp->nptr + sdp->exp_len )
1097                                 {
1098                                 int     save = errno;
1099
1100                                 printf("*** strtoumax(%s,,%d) returned wrong "
1101                                        "endptr ***\n", sdp->nptr, sdp->base
1102                                       );
1103                                 status = EXIT_FAILURE;
1104                                 errno = save;
1105                                 }
1106
1107                         if ( errno != 0 )
1108                                 {
1109                                 printf("*** strtoumax modified errno ***\n");
1110                                 status = EXIT_FAILURE;
1111                                 }
1112
1113                         if ( strcmp(sdp->nptr, saved) != 0 )
1114                                 {
1115                                 printf("*** strtoumax"
1116                                        " modified its input ***\n"
1117                                       );
1118                                 status = EXIT_FAILURE;
1119                                 strcpy(saved, sdp->nptr);
1120                                 }
1121                         }
1122
1123                 /* tests for null endptr */
1124
1125 #define WARN()  if (!warned) warned = 1, printf("*** Using null endptr: ***\n")
1126
1127                 warned = 0;
1128                 errno = 0;              /* shouldn't be changed */
1129
1130                 if ( (intmax = strtoimax(sdp->nptr, (char **)NULL, sdp->base))
1131                   != sdp->exp_val
1132                    )    {
1133                         int     save = errno;
1134
1135                         WARN();
1136                         printf("*** strtoimax(%s,NULL,%d) failed; "
1137                                "should be: %"PRIdMAX", was: %"PRIdMAX" ***\n",
1138                                sdp->nptr, sdp->base, sdp->exp_val, intmax
1139                               );
1140                         status = EXIT_FAILURE;
1141                         errno = save;
1142                         }
1143
1144                 if ( errno != 0 )
1145                         {
1146                         WARN();
1147                         printf("*** strtoimax modified errno ***\n");
1148                         status = EXIT_FAILURE;
1149                         }
1150
1151                 if ( strcmp(sdp->nptr, saved) != 0 )
1152                         {
1153                         WARN();
1154                         printf("*** strtoimax modified its input ***\n");
1155                         status = EXIT_FAILURE;
1156                         strcpy(saved, sdp->nptr);
1157                         }
1158
1159                 if ( sdp->exp_val >= 0 )        /* else some sign extension */
1160                         {
1161                         errno = 0;      /* shouldn't be changed */
1162
1163                         if ( (uintmax = strtoumax(sdp->nptr, (char **)NULL,
1164                                                   sdp->base
1165                                                  )
1166                              ) != sdp->exp_val
1167                            )    {
1168                                 int     save = errno;
1169
1170                                 WARN();
1171                                 printf("*** strtoumax(%s,NULL,%d) failed; "
1172                                        "should be: %"PRIuMAX", was: %"PRIuMAX
1173                                        " ***\n", sdp->nptr, sdp->base,
1174                                        sdp->exp_val, uintmax
1175                                       );
1176                                 status = EXIT_FAILURE;
1177                                 errno = save;
1178                                 }
1179
1180                          if ( errno != 0 )
1181                                 {
1182                                 WARN();
1183                                 printf("*** strtoumax modified errno ***\n");
1184                                 status = EXIT_FAILURE;
1185                                 }
1186
1187                          if ( strcmp(sdp->nptr, saved) != 0 )
1188                                 {
1189                                 WARN();
1190                                 printf("*** strtoumax"
1191                                        " modified its input ***\n"
1192                                       );
1193                                 status = EXIT_FAILURE;
1194                                 strcpy(saved, sdp->nptr);
1195                                 }
1196                         }
1197
1198                 /*
1199                         7.8.2.4 The wcstoimax and wcstoumax functions
1200                 */
1201
1202                 for ( i = 0; i < 64; ++i )
1203                         if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
1204                                 break;
1205
1206                 errno = 0;              /* shouldn't be changed */
1207
1208                 if ( (intmax = wcstoimax(wnptr, &wendptr, sdp->base))
1209                   != sdp->exp_val
1210                    )    {
1211                         int     save = errno;
1212
1213                         printf("*** wcstoimax(%s,,%d) failed; should be: %"
1214                                PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
1215                                sdp->base, sdp->exp_val, intmax
1216                               );
1217                         status = EXIT_FAILURE;
1218                         errno = save;
1219                         }
1220                 else if ( wendptr != wnptr + sdp->exp_len )
1221                         {
1222                         int     save = errno;
1223
1224                         printf("*** wcstoimax(%s,,%d) returned wrong endptr"
1225                                " ***\n", sdp->nptr, sdp->base
1226                               );
1227                         status = EXIT_FAILURE;
1228                         errno = save;
1229                         }
1230
1231                 if ( errno != 0 )
1232                         {
1233                         printf("*** wcstoimax modified errno ***\n");
1234                         status = EXIT_FAILURE;
1235                         }
1236
1237                 for ( i = 0; i < 64; ++i )
1238                         if ( wnptr[i] != sdp->nptr[i] )
1239                                 {
1240                                 printf("*** wcstoimax modified its input ***\n"
1241                                       );
1242                                 status = EXIT_FAILURE;
1243
1244                                 for ( ; i < 64; ++i )
1245                                         if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
1246                                                 break;
1247
1248                                 break;
1249                                 }
1250                         else if ( wnptr[i] == '\0' )
1251                                 break;
1252
1253                 if ( sdp->exp_val >= 0 )        /* else some sign extension */
1254                         {
1255                         errno = 0;      /* shouldn't be changed */
1256
1257                         if ( (uintmax = wcstoumax(wnptr, &wendptr, sdp->base)
1258                              ) != sdp->exp_val
1259                            )    {
1260                                 int     save = errno;
1261
1262                                 printf("*** wcstoumax(%s,,%d) failed; "
1263                                        "should be: %"PRIuMAX", was: %"PRIuMAX
1264                                        " ***\n", sdp->nptr, sdp->base,
1265                                        sdp->exp_val, uintmax
1266                                       );
1267                                 status = EXIT_FAILURE;
1268                                 errno = save;
1269                                 }
1270                         else if ( wendptr != wnptr + sdp->exp_len )
1271                                 {
1272                                 int     save = errno;
1273
1274                                 printf("*** wcstoumax(%s,,%d) returned wrong "
1275                                        "endptr ***\n", sdp->nptr, sdp->base
1276                                       );
1277                                 status = EXIT_FAILURE;
1278                                 errno = save;
1279                                 }
1280
1281                         if ( errno != 0 )
1282                                 {
1283                                 printf("*** wcstoumax modified errno ***\n");
1284                                 status = EXIT_FAILURE;
1285                                 }
1286
1287                         for ( i = 0; i < 64; ++i )
1288                                 if ( wnptr[i] != sdp->nptr[i] )
1289                                         {
1290                                         printf("*** wcstoumax"
1291                                                " modified its input ***\n"
1292                                               );
1293                                         status = EXIT_FAILURE;
1294
1295                                         for ( ; i < 64; ++i )
1296                                                 if ( (wnptr[i] = sdp->nptr[i])
1297                                                   == '\0'
1298                                                    )
1299                                                         break;
1300
1301                                         break;
1302                                         }
1303                                 else if ( wnptr[i] == '\0' )
1304                                         break;
1305                         }
1306
1307                 /* tests for null endptr */
1308
1309                 warned = 0;
1310                 errno = 0;              /* shouldn't be changed */
1311
1312                 if ( (intmax = wcstoimax(wnptr, (wchar_t **)NULL, sdp->base))
1313                   != sdp->exp_val
1314                    )    {
1315                         int     save = errno;
1316
1317                         WARN();
1318                         printf("*** wcstoimax(%s,NULL,%d) failed; should be: %"
1319                                PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
1320                                sdp->base, sdp->exp_val, intmax
1321                               );
1322                         status = EXIT_FAILURE;
1323                         errno = save;
1324                         }
1325
1326                 if ( errno != 0 )
1327                         {
1328                         WARN();
1329                         printf("*** wcstoimax modified errno ***\n");
1330                         status = EXIT_FAILURE;
1331                         }
1332
1333                 for ( i = 0; i < 64; ++i )
1334                         if ( wnptr[i] != sdp->nptr[i] )
1335                                 {
1336                                 WARN();
1337                                 printf("*** wcstoimax modified its input ***\n"
1338                                       );
1339                                 status = EXIT_FAILURE;
1340
1341                                 for ( ; i < 64; ++i )
1342                                         if ( (wnptr[i] = sdp->nptr[i])
1343                                           == '\0'
1344                                            )
1345                                                 break;
1346
1347                                 break;
1348                                 }
1349                         else if ( wnptr[i] == '\0' )
1350                                 break;
1351
1352                 if ( sdp->exp_val >= 0 )        /* else some sign extension */
1353                         {
1354                         errno = 0;      /* shouldn't be changed */
1355
1356                         if ( (uintmax = wcstoumax(wnptr, (wchar_t **)NULL,
1357                                                   sdp->base
1358                                                  )
1359                              ) != sdp->exp_val
1360                            )    {
1361                                 int     save = errno;
1362
1363                                 WARN();
1364                                 printf("*** wcstoumax(%s,NULL,%d) failed; "
1365                                        "should be: %"PRIuMAX", was: %"PRIuMAX
1366                                        " ***\n", sdp->nptr, sdp->base,
1367                                        sdp->exp_val, uintmax
1368                                       );
1369                                 status = EXIT_FAILURE;
1370                                 errno = save;
1371                                 }
1372
1373                          if ( errno != 0 )
1374                                 {
1375                                 WARN();
1376                                 printf("*** wcstoumax modified errno ***\n");
1377                                 status = EXIT_FAILURE;
1378                                 }
1379
1380                         for ( i = 0; i < 64; ++i )
1381                                 if ( wnptr[i] != sdp->nptr[i] )
1382                                         {
1383                                         WARN();
1384                                         printf("*** wcstoumax"
1385                                                " modified its input ***\n"
1386                                               );
1387                                         status = EXIT_FAILURE;
1388
1389                                         for ( ; i < 64; ++i )
1390                                                 if ( (wnptr[i] = sdp->nptr[i])
1391                                                   == '\0'
1392                                                    )
1393                                                         break;
1394
1395                                         break;
1396                                         }
1397                                 else if ( wnptr[i] == '\0' )
1398                                         break;
1399                         }
1400                 }
1401
1402         /*
1403                 7.8.2.3 The strtoimax and strtoumax functions (continued)
1404         */
1405
1406         if ( (intmax = strtoimax("1234567890123456789012345678901234567890"
1407                                  "1234567890123456789012345678901234567890"
1408                                  "1234567890123456789012345678901234567890"
1409                                  "1234567890123456789012345678901234567890"
1410                                  "1234567890123456789012345678901234567890"
1411                                  "1234567890123456789012345678901234567890",
1412                                  &endptr, 0
1413                                 )
1414              ) != INTMAX_MAX || errno != ERANGE
1415            )    {
1416                 printf("*** strtoimax failed overflow test ***\n");
1417                 status = EXIT_FAILURE;
1418                 }
1419
1420         if ( (intmax = strtoimax("+1234567890123456789012345678901234567890"
1421                                  "1234567890123456789012345678901234567890"
1422                                  "1234567890123456789012345678901234567890"
1423                                  "1234567890123456789012345678901234567890"
1424                                  "1234567890123456789012345678901234567890"
1425                                  "1234567890123456789012345678901234567890",
1426                                  &endptr, 0
1427                                 )
1428              ) != INTMAX_MAX || errno != ERANGE
1429            )    {
1430                 printf("*** strtoimax failed +overflow test ***\n");
1431                 status = EXIT_FAILURE;
1432                 }
1433
1434         if ( (intmax = strtoimax("-1234567890123456789012345678901234567890"
1435                                  "1234567890123456789012345678901234567890"
1436                                  "1234567890123456789012345678901234567890"
1437                                  "1234567890123456789012345678901234567890"
1438                                  "1234567890123456789012345678901234567890"
1439                                  "1234567890123456789012345678901234567890",
1440                                  &endptr, 0
1441                                 )
1442              ) != INTMAX_MIN || errno != ERANGE
1443            )    {
1444                 printf("*** strtoimax failed -overflow test ***\n");
1445                 status = EXIT_FAILURE;
1446                 }
1447
1448         if ( (uintmax = strtoumax("1234567890123456789012345678901234567890"
1449                                  "1234567890123456789012345678901234567890"
1450                                  "1234567890123456789012345678901234567890"
1451                                  "1234567890123456789012345678901234567890"
1452                                  "1234567890123456789012345678901234567890"
1453                                  "1234567890123456789012345678901234567890",
1454                                  &endptr, 0
1455                                 )
1456              ) != UINTMAX_MAX || errno != ERANGE
1457            )    {
1458                 printf("*** strtoumax failed overflow test ***\n");
1459                 status = EXIT_FAILURE;
1460                 }
1461
1462         if ( (uintmax = strtoumax("+1234567890123456789012345678901234567890"
1463                                  "1234567890123456789012345678901234567890"
1464                                  "1234567890123456789012345678901234567890"
1465                                  "1234567890123456789012345678901234567890"
1466                                  "1234567890123456789012345678901234567890"
1467                                  "1234567890123456789012345678901234567890",
1468                                  &endptr, 0
1469                                 )
1470              ) != UINTMAX_MAX || errno != ERANGE
1471            )    {
1472                 printf("*** strtoumax failed +overflow test ***\n");
1473                 status = EXIT_FAILURE;
1474                 }
1475
1476         if ( (uintmax = strtoumax("-1234567890123456789012345678901234567890"
1477                                  "1234567890123456789012345678901234567890"
1478                                  "1234567890123456789012345678901234567890"
1479                                  "1234567890123456789012345678901234567890"
1480                                  "1234567890123456789012345678901234567890"
1481                                  "1234567890123456789012345678901234567890",
1482                                  &endptr, 0
1483                                 )
1484              ) != UINTMAX_MAX || errno != ERANGE
1485            )    {
1486                 printf("*** strtoumax failed -overflow test ***\n");
1487                 status = EXIT_FAILURE;
1488                 }
1489
1490         /*
1491                 7.8.2.4 The wcstoimax and wcstoumax functions (continued)
1492         */
1493
1494 #ifdef NO_INTERNAL_WCHAR
1495                 printf("NO_INTERNAL_WCHAR\n");
1496 #else
1497
1498         if ( (intmax = wcstoimax(L"1234567890123456789012345678901234567890"
1499                                  L"1234567890123456789012345678901234567890"
1500                                  L"1234567890123456789012345678901234567890"
1501                                  L"1234567890123456789012345678901234567890"
1502                                  L"1234567890123456789012345678901234567890"
1503                                  L"1234567890123456789012345678901234567890",
1504                                  &wendptr, 0
1505                                 )
1506              ) != INTMAX_MAX || errno != ERANGE
1507            )    {
1508                 printf("*** wcstoimax failed overflow test ***\n");
1509                 status = EXIT_FAILURE;
1510                 }
1511
1512         if ( (intmax = wcstoimax(L"+1234567890123456789012345678901234567890"
1513                                  L"1234567890123456789012345678901234567890"
1514                                  L"1234567890123456789012345678901234567890"
1515                                  L"1234567890123456789012345678901234567890"
1516                                  L"1234567890123456789012345678901234567890"
1517                                  L"1234567890123456789012345678901234567890",
1518                                  &wendptr, 0
1519                                 )
1520              ) != INTMAX_MAX || errno != ERANGE
1521            )    {
1522                 printf("*** wcstoimax failed +overflow test ***\n");
1523                 status = EXIT_FAILURE;
1524                 }
1525
1526         if ( (intmax = wcstoimax(L"-1234567890123456789012345678901234567890"
1527                                  L"1234567890123456789012345678901234567890"
1528                                  L"1234567890123456789012345678901234567890"
1529                                  L"1234567890123456789012345678901234567890"
1530                                  L"1234567890123456789012345678901234567890"
1531                                  L"1234567890123456789012345678901234567890",
1532                                  &wendptr, 0
1533                                 )
1534              ) != INTMAX_MIN || errno != ERANGE
1535            )    {
1536                 printf("*** wcstoimax failed -overflow test ***\n");
1537                 status = EXIT_FAILURE;
1538                 }
1539
1540         if ( (uintmax = wcstoumax(L"1234567890123456789012345678901234567890"
1541                                  L"1234567890123456789012345678901234567890"
1542                                  L"1234567890123456789012345678901234567890"
1543                                  L"1234567890123456789012345678901234567890"
1544                                  L"1234567890123456789012345678901234567890"
1545                                  L"1234567890123456789012345678901234567890",
1546                                  &wendptr, 0
1547                                 )
1548              ) != UINTMAX_MAX || errno != ERANGE
1549            )    {
1550                 printf("*** wcstoumax failed overflow test ***\n");
1551                 status = EXIT_FAILURE;
1552                 }
1553
1554         if ( (uintmax = wcstoumax(L"+1234567890123456789012345678901234567890"
1555                                  L"1234567890123456789012345678901234567890"
1556                                  L"1234567890123456789012345678901234567890"
1557                                  L"1234567890123456789012345678901234567890"
1558                                  L"1234567890123456789012345678901234567890"
1559                                  L"1234567890123456789012345678901234567890",
1560                                  &wendptr, 0
1561                                 )
1562              ) != UINTMAX_MAX || errno != ERANGE
1563            )    {
1564                 printf("*** wcstoumax failed +overflow test ***\n");
1565                 status = EXIT_FAILURE;
1566                 }
1567
1568         if ( (uintmax = wcstoumax(L"-1234567890123456789012345678901234567890"
1569                                  L"1234567890123456789012345678901234567890"
1570                                  L"1234567890123456789012345678901234567890"
1571                                  L"1234567890123456789012345678901234567890"
1572                                  L"1234567890123456789012345678901234567890"
1573                                  L"1234567890123456789012345678901234567890",
1574                                  &wendptr, 0
1575                                 )
1576              ) != UINTMAX_MAX || errno != ERANGE
1577            )    {
1578                 printf("*** wcstoumax failed -overflow test ***\n");
1579                 status = EXIT_FAILURE;
1580                 }
1581 #endif // NO_INTERNAL_WCHAR
1582         }
1583 #endif  /* defined(INTMAX_MAX) */
1584
1585         if ( status != 0 )
1586                 printf("sitest failed.\n");
1587
1588         return status;
1589 }
1590
1591 #endif