- for ( ddp = div_data; ddp->denom != 0; ++ddp )
- if ( (result = imaxdiv(ddp->numer, ddp->denom)).quot
- != ddp->exp_quot || result.rem != ddp->exp_rem
- ) {
-// printf("*** imaxdiv(%"PRIdMAX",%"PRIdMAX
-// ") failed; should be: (%"PRIdMAX",%"PRIdMAX
-// "), was: (%"PRIdMAX",%"PRIdMAX") ***\n",
-// ddp->numer, ddp->denom, ddp->exp_quot,
-// ddp->exp_rem, result.quot, result.rem
-// );
- printf("err:imaxdiv(%"PRIdMAX",%"PRIdMAX
- ") = (%"PRIdMAX",%"PRIdMAX
- "), is: (%"PRIdMAX",%"PRIdMAX")\n",
- ddp->numer, ddp->denom, ddp->exp_quot,
- ddp->exp_rem, result.quot, result.rem
- );
- status = EXIT_FAILURE;
- }
-#endif
- }
-
- {
- char *endptr;
- wchar_t *wendptr;
- static char saved[64]; /* holds copy of input string */
- static wchar_t wnptr[64]; /* holds wide copy of test string */
- static int warned; /* "warned for null endptr" flag */
- register int i;
- static struct
- {
- char * nptr;
- int base;
- intmax_t exp_val;
- int exp_len;
- } str_data[] =
- {
- { "", 0, 0, 0, },
- { "", 2, 0, 0, },
- { "", 8, 0, 0, },
- { "", 9, 0, 0, },
- { "", 10, 0, 0, },
- { "", 16, 0, 0, },
- { "", 36, 0, 0, },
- { "0", 0, 0, 1, },
- { "0", 2, 0, 1, },
- { "0", 8, 0, 1, },
- { "0", 9, 0, 1, },
- { "0", 10, 0, 1, },
- { "0", 16, 0, 1, },
- { "0", 36, 0, 1, },
- { "+0", 0, 0, 2, },
- { "+0", 2, 0, 2, },
- { "+0", 8, 0, 2, },
- { "+0", 9, 0, 2, },
- { "+0", 10, 0, 2, },
- { "+0", 16, 0, 2, },
- { "+0", 36, 0, 2, },
- { "-0", 0, 0, 2, },
- { "-0", 2, 0, 2, },
- { "-0", 8, 0, 2, },
- { "-0", 9, 0, 2, },
- { "-0", 10, 0, 2, },
- { "-0", 16, 0, 2, },
- { "-0", 36, 0, 2, },
- { "Inf", 0, 0, 0, },
- { "Inf", 2, 0, 0, },
- { "Inf", 8, 0, 0, },
- { "Inf", 9, 0, 0, },
- { "Inf", 10, 0, 0, },
- { "Inf", 16, 0, 0, },
- { "Inf", 36, 24171, 3, },
- { "+Inf", 0, 0, 0, },
- { "+Inf", 2, 0, 0, },
- { "+Inf", 8, 0, 0, },
- { "+Inf", 9, 0, 0, },
- { "+Inf", 10, 0, 0, },
- { "+Inf", 16, 0, 0, },
- { "+Inf", 36, 24171, 4, },
- { "-Inf", 0, 0, 0, },
- { "-Inf", 2, 0, 0, },
- { "-Inf", 8, 0, 0, },
- { "-Inf", 9, 0, 0, },
- { "-Inf", 10, 0, 0, },
- { "-Inf", 16, 0, 0, },
- { "-Inf", 36, -24171, 4, },
- { "inf", 0, 0, 0, },
- { "inf", 2, 0, 0, },
- { "inf", 8, 0, 0, },
- { "inf", 9, 0, 0, },
- { "inf", 10, 0, 0, },
- { "inf", 16, 0, 0, },
- { "inf", 36, 24171, 3, },
- { "+inf", 0, 0, 0, },
- { "+inf", 2, 0, 0, },
- { "+inf", 8, 0, 0, },
- { "+inf", 9, 0, 0, },
- { "+inf", 10, 0, 0, },
- { "+inf", 16, 0, 0, },
- { "+inf", 36, 24171, 4, },
- { "-inf", 0, 0, 0, },
- { "-inf", 2, 0, 0, },
- { "-inf", 8, 0, 0, },
- { "-inf", 9, 0, 0, },
- { "-inf", 10, 0, 0, },
- { "-inf", 16, 0, 0, },
- { "-inf", 36, -24171, 4, },
- { "119b8Z", 0, 119, 3, },
- { "119bZ", 0, 119, 3, },
- { "-0119bZ", 0, -9, 4, },
- { " \t\n 0X119bZ", 0, 4507, 10, },
- { " \t\n +0X119bZ", 0, 4507, 11, },
- { " \t\n -0x119bZ", 0, -4507, 11, },
- { " \t\n 119bZ", 0, 119, 7, },
- { "+119bZ", 0, 119, 4, },
- { "+0X119bz", 0, 4507, 7, },
- { "119b8Z", 2, 3, 2, },
- { "119bZ", 2, 3, 2, },
- { "-0119bZ", 2, -3, 4, },
- { " \t\n 0X119bZ", 2, 0, 5, },
- { " \t\n +0X119bZ", 2, 0, 6, },
- { " \t\n -0x119bZ", 2, 0, 6, },
- { " \t\n 119bZ", 2, 3, 6, },
- { "+119bZ", 2, 3, 3, },
- { "+0X119bz", 2, 0, 2, },
- { "119b8Z", 8, 9, 2, },
- { "119bZ", 8, 9, 2, },
- { "-0119bZ", 8, -9, 4, },
- { " \t\n 0X119bZ", 8, 0, 5, },
- { " \t\n +0X119bZ", 8, 0, 6, },
- { " \t\n -0x119bZ", 8, 0, 6, },
- { " \t\n 119bZ", 8, 9, 6, },
- { "+119bZ", 8, 9, 3, },
- { "+0X119bz", 8, 0, 2, },
- { "119b8Z", 9, 10, 2, },
- { "119bZ", 9, 10, 2, },
- { "-0119bZ", 9, -10, 4, },
- { " \t\n 0X119bZ", 9, 0, 5, },
- { " \t\n +0X119bZ", 9, 0, 6, },
- { " \t\n -0x119bZ", 9, 0, 6, },
- { " \t\n 119bZ", 9, 10, 6, },
- { "+119bZ", 9, 10, 3, },
- { "+0X119bz", 9, 0, 2, },
- { "119b8Z", 10, 119, 3, },
- { "119bZ", 10, 119, 3, },
- { "-0119bZ", 10, -119, 5, },
- { " \t\n 0X119bZ", 10, 0, 5, },
- { " \t\n +0X119bZ", 10, 0, 6, },
- { " \t\n -0x119bZ", 10, 0, 6, },
- { " \t\n 119bZ", 10, 119, 7, },
- { "+119bZ", 10, 119, 4, },
- { "+0X119bz", 10, 0, 2, },
- { "119b8Z", 16, 72120, 5, },
- { "119bZ", 16, 4507, 4, },
- { "-0119bZ", 16, -4507, 6, },
- { " \t\n 0X119bZ", 16, 4507, 10, },
- { " \t\n +0X119bZ", 16, 4507, 11, },
- { " \t\n -0x119bZ", 16, -4507, 11, },
- { " \t\n 119bZ", 16, 4507,8, },
- { "+119bZ", 16, 4507, 5, },
- { "+0X119bz", 16, 4507, 7, },
- { "119b8Z", 36, 62580275, 6, },
- { "119bZ", 36, 1738367, 5, },
- { "-0119bZ", 36, -1738367, 7, },
- { " \t\n 0X119bZ", 36, 1997122175, 11, },
- { " \t\n +0X119bZ", 36, 1997122175, 12, },
- { " \t\n -0x119bZ", 36, -1997122175, 12, },
- { " \t\n 119bZ", 36, 1738367, 9, },
- { "+119bZ", 36, 1738367, 6, },
- { "+0X119bz", 36, 1997122175, 8, },
- /* There should be a much larger battery of such tests. */
- { "127", 0, 127, 3, },
- { "-127", 0, -127, 4, },
- { "128", 0, 128, 3, },
- { "-128", 0, -127-1, 4, },
- { "255", 0, 255, 3, },
- { "-255", 0, -255, 4, },
- { "256", 0, 256, 3, },
- { "-256", 0, -255-1, 4, },
- { "32767", 0, 32767, 5, },
- { "-32767", 0, -32767, 6, },
- { "32768", 0, 32768, 5, },
- { "-32768", 0, -32767-1, 6, },
- { "65535", 0, 65535, 5, },
- { "-65535", 0, -65536+1, 6, },
- { "65536", 0, 65536, 5, },
- { "-65536", 0, -65536, 6, },
- { "2147483647", 0, 2147483647, 10, },
- { "-2147483647", 0, -2147483647, 11, },
- { "2147483648", 0, 2147483648, 10, },
- { "-2147483648", 0, -2147483647-1, 11, },
- { "4294967295", 0, 4294967295, 10, },
- { "-4294967295", 0, -4294967296+1, 11, },
- { "4294967296", 0, 4294967296, 10, },
- { "-4294967296", 0, -4294967296, 11, },
- { "9223372036854775807", 0, 9223372036854775807, 19, },
- { "-9223372036854775807", 0, -9223372036854775807, 20, },
- { "1234567890123456789", 0, 1234567890123456789, 19, },
- { "-1234567890123456789", 0, -1234567890123456789, 20, },
- { "1", 0, 1, 1, },
- { "-1", 0, -1, 2, },
- { "2", 0, 2, 1, },
- { "-2", 0, -2, 2, },
- { "10", 0, 10, 2, },
- { "-10", 0, -10, 3, },
- { "16", 0, 16, 2, },
- { "-16", 0, -16, 3, },
- /* Other test cases can be added here. */
- { NULL, 0, 0, 0 }, /* terminates the list */
- }, *sdp;
-
- for ( sdp = str_data; sdp->nptr != NULL ; ++sdp )
- {
- /*
- 7.8.2.3 The strtoimax and strtoumax functions
- */
-
- strcpy(saved, sdp->nptr);
-
- errno = 0; /* shouldn't be changed */
-
- if ( (intmax = strtoimax(sdp->nptr, &endptr, sdp->base))
- != sdp->exp_val
- ) {
- int save = errno;
-
- printf("*** strtoimax(%s,,%d) failed; should be: %"
- PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
- sdp->base, sdp->exp_val, intmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
- else if ( endptr != sdp->nptr + sdp->exp_len )
- {
- int save = errno;
-
- printf("*** strtoimax(%s,,%d) returned wrong endptr"
- " ***\n", sdp->nptr, sdp->base
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- printf("*** strtoimax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( strcmp(sdp->nptr, saved) != 0 )
- {
- printf("*** strtoimax modified its input ***\n");
- status = EXIT_FAILURE;
- strcpy(saved, sdp->nptr);
- }
-
- if ( sdp->exp_val >= 0 ) /* else some sign extension */
- {
- errno = 0; /* shouldn't be changed */
-
- if ( (uintmax = strtoumax(sdp->nptr, &endptr, sdp->base
- )
- ) != sdp->exp_val
- ) {
- int save = errno;
-
- printf("*** strtoumax(%s,,%d) failed; "
- "should be: %"PRIuMAX", was: %"PRIuMAX
- " ***\n", sdp->nptr, sdp->base,
- sdp->exp_val, uintmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
- else if ( endptr != sdp->nptr + sdp->exp_len )
- {
- int save = errno;
-
- printf("*** strtoumax(%s,,%d) returned wrong "
- "endptr ***\n", sdp->nptr, sdp->base
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- printf("*** strtoumax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( strcmp(sdp->nptr, saved) != 0 )
- {
- printf("*** strtoumax"
- " modified its input ***\n"
- );
- status = EXIT_FAILURE;
- strcpy(saved, sdp->nptr);
- }
- }
-
- /* tests for null endptr */
-
-#define WARN() if (!warned) warned = 1, printf("*** Using null endptr: ***\n")
-
- warned = 0;
- errno = 0; /* shouldn't be changed */
-
- if ( (intmax = strtoimax(sdp->nptr, (char **)NULL, sdp->base))
- != sdp->exp_val
- ) {
- int save = errno;
-
- WARN();
- printf("*** strtoimax(%s,NULL,%d) failed; "
- "should be: %"PRIdMAX", was: %"PRIdMAX" ***\n",
- sdp->nptr, sdp->base, sdp->exp_val, intmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- WARN();
- printf("*** strtoimax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( strcmp(sdp->nptr, saved) != 0 )
- {
- WARN();
- printf("*** strtoimax modified its input ***\n");
- status = EXIT_FAILURE;
- strcpy(saved, sdp->nptr);
- }
-
- if ( sdp->exp_val >= 0 ) /* else some sign extension */
- {
- errno = 0; /* shouldn't be changed */
-
- if ( (uintmax = strtoumax(sdp->nptr, (char **)NULL,
- sdp->base
- )
- ) != sdp->exp_val
- ) {
- int save = errno;
-
- WARN();
- printf("*** strtoumax(%s,NULL,%d) failed; "
- "should be: %"PRIuMAX", was: %"PRIuMAX
- " ***\n", sdp->nptr, sdp->base,
- sdp->exp_val, uintmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- WARN();
- printf("*** strtoumax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( strcmp(sdp->nptr, saved) != 0 )
- {
- WARN();
- printf("*** strtoumax"
- " modified its input ***\n"
- );
- status = EXIT_FAILURE;
- strcpy(saved, sdp->nptr);
- }
- }
-
- /*
- 7.8.2.4 The wcstoimax and wcstoumax functions
- */
-
- for ( i = 0; i < 64; ++i )
- if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
- break;
-
- errno = 0; /* shouldn't be changed */
-
- if ( (intmax = wcstoimax(wnptr, &wendptr, sdp->base))
- != sdp->exp_val
- ) {
- int save = errno;
-
- printf("*** wcstoimax(%s,,%d) failed; should be: %"
- PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
- sdp->base, sdp->exp_val, intmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
- else if ( wendptr != wnptr + sdp->exp_len )
- {
- int save = errno;
-
- printf("*** wcstoimax(%s,,%d) returned wrong endptr"
- " ***\n", sdp->nptr, sdp->base
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- printf("*** wcstoimax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- for ( i = 0; i < 64; ++i )
- if ( wnptr[i] != sdp->nptr[i] )
- {
- printf("*** wcstoimax modified its input ***\n"
- );
- status = EXIT_FAILURE;
-
- for ( ; i < 64; ++i )
- if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
- break;
-
- break;
- }
- else if ( wnptr[i] == '\0' )
- break;
-
- if ( sdp->exp_val >= 0 ) /* else some sign extension */
- {
- errno = 0; /* shouldn't be changed */
-
- if ( (uintmax = wcstoumax(wnptr, &wendptr, sdp->base)
- ) != sdp->exp_val
- ) {
- int save = errno;
-
- printf("*** wcstoumax(%s,,%d) failed; "
- "should be: %"PRIuMAX", was: %"PRIuMAX
- " ***\n", sdp->nptr, sdp->base,
- sdp->exp_val, uintmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
- else if ( wendptr != wnptr + sdp->exp_len )
- {
- int save = errno;
-
- printf("*** wcstoumax(%s,,%d) returned wrong "
- "endptr ***\n", sdp->nptr, sdp->base
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- printf("*** wcstoumax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- for ( i = 0; i < 64; ++i )
- if ( wnptr[i] != sdp->nptr[i] )
- {
- printf("*** wcstoumax"
- " modified its input ***\n"
- );
- status = EXIT_FAILURE;
-
- for ( ; i < 64; ++i )
- if ( (wnptr[i] = sdp->nptr[i])
- == '\0'
- )
- break;
-
- break;
- }
- else if ( wnptr[i] == '\0' )
- break;
- }
-
- /* tests for null endptr */
-
- warned = 0;
- errno = 0; /* shouldn't be changed */
-
- if ( (intmax = wcstoimax(wnptr, (wchar_t **)NULL, sdp->base))
- != sdp->exp_val
- ) {
- int save = errno;
-
- WARN();
- printf("*** wcstoimax(%s,NULL,%d) failed; should be: %"
- PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
- sdp->base, sdp->exp_val, intmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- WARN();
- printf("*** wcstoimax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- for ( i = 0; i < 64; ++i )
- if ( wnptr[i] != sdp->nptr[i] )
- {
- WARN();
- printf("*** wcstoimax modified its input ***\n"
- );
- status = EXIT_FAILURE;
-
- for ( ; i < 64; ++i )
- if ( (wnptr[i] = sdp->nptr[i])
- == '\0'
- )
- break;
-
- break;
- }
- else if ( wnptr[i] == '\0' )
- break;
-
- if ( sdp->exp_val >= 0 ) /* else some sign extension */
- {
- errno = 0; /* shouldn't be changed */
-
- if ( (uintmax = wcstoumax(wnptr, (wchar_t **)NULL,
- sdp->base
- )
- ) != sdp->exp_val
- ) {
- int save = errno;
-
- WARN();
- printf("*** wcstoumax(%s,NULL,%d) failed; "
- "should be: %"PRIuMAX", was: %"PRIuMAX
- " ***\n", sdp->nptr, sdp->base,
- sdp->exp_val, uintmax
- );
- status = EXIT_FAILURE;
- errno = save;
- }
-
- if ( errno != 0 )
- {
- WARN();
- printf("*** wcstoumax modified errno ***\n");
- status = EXIT_FAILURE;
- }
-
- for ( i = 0; i < 64; ++i )
- if ( wnptr[i] != sdp->nptr[i] )
- {
- WARN();
- printf("*** wcstoumax"
- " modified its input ***\n"
- );
- status = EXIT_FAILURE;
-
- for ( ; i < 64; ++i )
- if ( (wnptr[i] = sdp->nptr[i])
- == '\0'
- )
- break;
-
- break;
- }
- else if ( wnptr[i] == '\0' )
- break;
- }
- }
-
- /*
- 7.8.2.3 The strtoimax and strtoumax functions (continued)
- */
-
- if ( (intmax = strtoimax("1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890",
- &endptr, 0
- )
- ) != INTMAX_MAX || errno != ERANGE
- ) {
- printf("*** strtoimax failed overflow test ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( (intmax = strtoimax("+1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890",
- &endptr, 0
- )
- ) != INTMAX_MAX || errno != ERANGE
- ) {
- printf("*** strtoimax failed +overflow test ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( (intmax = strtoimax("-1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890",
- &endptr, 0
- )
- ) != INTMAX_MIN || errno != ERANGE
- ) {
- printf("*** strtoimax failed -overflow test ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( (uintmax = strtoumax("1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890",
- &endptr, 0
- )
- ) != UINTMAX_MAX || errno != ERANGE
- ) {
- printf("*** strtoumax failed overflow test ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( (uintmax = strtoumax("+1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890",
- &endptr, 0
- )
- ) != UINTMAX_MAX || errno != ERANGE
- ) {
- printf("*** strtoumax failed +overflow test ***\n");
- status = EXIT_FAILURE;
- }
-
- if ( (uintmax = strtoumax("-1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890"
- "1234567890123456789012345678901234567890",
- &endptr, 0
- )
- ) != UINTMAX_MAX || errno != ERANGE
- ) {
- printf("*** strtoumax failed -overflow test ***\n");
- status = EXIT_FAILURE;
- }
-
- /*
- 7.8.2.4 The wcstoimax and wcstoumax functions (continued)
- */
+ for ( ddp = div_data; ddp->denom != 0; ++ddp )
+ if ( (result = imaxdiv(ddp->numer, ddp->denom)).quot
+ != ddp->exp_quot || result.rem != ddp->exp_rem
+ ) {
+// printf("*** imaxdiv(%"PRIdMAX",%"PRIdMAX
+// ") failed; should be: (%"PRIdMAX",%"PRIdMAX
+// "), was: (%"PRIdMAX",%"PRIdMAX") ***\n",
+// ddp->numer, ddp->denom, ddp->exp_quot,
+// ddp->exp_rem, result.quot, result.rem
+// );
+ printf("err:imaxdiv(%"PRIdMAX",%"PRIdMAX
+ ") = (%"PRIdMAX",%"PRIdMAX
+ "), is: (%"PRIdMAX",%"PRIdMAX")\n",
+ ddp->numer, ddp->denom, ddp->exp_quot,
+ ddp->exp_rem, result.quot, result.rem
+ );
+ status = EXIT_FAILURE;
+ }
+#endif
+ }
+
+ {
+ char *endptr;
+ wchar_t *wendptr;
+ static char saved[64]; /* holds copy of input string */
+ static wchar_t wnptr[64]; /* holds wide copy of test string */
+ static int warned; /* "warned for null endptr" flag */
+ register int i;
+ static struct
+ {
+ char * nptr;
+ int base;
+ intmax_t exp_val;
+ int exp_len;
+ } str_data[] =
+ {
+ { "", 0, 0, 0, },
+ { "", 2, 0, 0, },
+ { "", 8, 0, 0, },
+ { "", 9, 0, 0, },
+ { "", 10, 0, 0, },
+ { "", 16, 0, 0, },
+ { "", 36, 0, 0, },
+ { "0", 0, 0, 1, },
+ { "0", 2, 0, 1, },
+ { "0", 8, 0, 1, },
+ { "0", 9, 0, 1, },
+ { "0", 10, 0, 1, },
+ { "0", 16, 0, 1, },
+ { "0", 36, 0, 1, },
+ { "+0", 0, 0, 2, },
+ { "+0", 2, 0, 2, },
+ { "+0", 8, 0, 2, },
+ { "+0", 9, 0, 2, },
+ { "+0", 10, 0, 2, },
+ { "+0", 16, 0, 2, },
+ { "+0", 36, 0, 2, },
+ { "-0", 0, 0, 2, },
+ { "-0", 2, 0, 2, },
+ { "-0", 8, 0, 2, },
+ { "-0", 9, 0, 2, },
+ { "-0", 10, 0, 2, },
+ { "-0", 16, 0, 2, },
+ { "-0", 36, 0, 2, },
+ { "Inf", 0, 0, 0, },
+ { "Inf", 2, 0, 0, },
+ { "Inf", 8, 0, 0, },
+ { "Inf", 9, 0, 0, },
+ { "Inf", 10, 0, 0, },
+ { "Inf", 16, 0, 0, },
+ { "Inf", 36, 24171, 3, },
+ { "+Inf", 0, 0, 0, },
+ { "+Inf", 2, 0, 0, },
+ { "+Inf", 8, 0, 0, },
+ { "+Inf", 9, 0, 0, },
+ { "+Inf", 10, 0, 0, },
+ { "+Inf", 16, 0, 0, },
+ { "+Inf", 36, 24171, 4, },
+ { "-Inf", 0, 0, 0, },
+ { "-Inf", 2, 0, 0, },
+ { "-Inf", 8, 0, 0, },
+ { "-Inf", 9, 0, 0, },
+ { "-Inf", 10, 0, 0, },
+ { "-Inf", 16, 0, 0, },
+ { "-Inf", 36, -24171, 4, },
+ { "inf", 0, 0, 0, },
+ { "inf", 2, 0, 0, },
+ { "inf", 8, 0, 0, },
+ { "inf", 9, 0, 0, },
+ { "inf", 10, 0, 0, },
+ { "inf", 16, 0, 0, },
+ { "inf", 36, 24171, 3, },
+ { "+inf", 0, 0, 0, },
+ { "+inf", 2, 0, 0, },
+ { "+inf", 8, 0, 0, },
+ { "+inf", 9, 0, 0, },
+ { "+inf", 10, 0, 0, },
+ { "+inf", 16, 0, 0, },
+ { "+inf", 36, 24171, 4, },
+ { "-inf", 0, 0, 0, },
+ { "-inf", 2, 0, 0, },
+ { "-inf", 8, 0, 0, },
+ { "-inf", 9, 0, 0, },
+ { "-inf", 10, 0, 0, },
+ { "-inf", 16, 0, 0, },
+ { "-inf", 36, -24171, 4, },
+ { "119b8Z", 0, 119, 3, },
+ { "119bZ", 0, 119, 3, },
+ { "-0119bZ", 0, -9, 4, },
+ { " \t\n 0X119bZ", 0, 4507, 10, },
+ { " \t\n +0X119bZ", 0, 4507, 11, },
+ { " \t\n -0x119bZ", 0, -4507, 11, },
+ { " \t\n 119bZ", 0, 119, 7, },
+ { "+119bZ", 0, 119, 4, },
+ { "+0X119bz", 0, 4507, 7, },
+ { "119b8Z", 2, 3, 2, },
+ { "119bZ", 2, 3, 2, },
+ { "-0119bZ", 2, -3, 4, },
+ { " \t\n 0X119bZ", 2, 0, 5, },
+ { " \t\n +0X119bZ", 2, 0, 6, },
+ { " \t\n -0x119bZ", 2, 0, 6, },
+ { " \t\n 119bZ", 2, 3, 6, },
+ { "+119bZ", 2, 3, 3, },
+ { "+0X119bz", 2, 0, 2, },
+ { "119b8Z", 8, 9, 2, },
+ { "119bZ", 8, 9, 2, },
+ { "-0119bZ", 8, -9, 4, },
+ { " \t\n 0X119bZ", 8, 0, 5, },
+ { " \t\n +0X119bZ", 8, 0, 6, },
+ { " \t\n -0x119bZ", 8, 0, 6, },
+ { " \t\n 119bZ", 8, 9, 6, },
+ { "+119bZ", 8, 9, 3, },
+ { "+0X119bz", 8, 0, 2, },
+ { "119b8Z", 9, 10, 2, },
+ { "119bZ", 9, 10, 2, },
+ { "-0119bZ", 9, -10, 4, },
+ { " \t\n 0X119bZ", 9, 0, 5, },
+ { " \t\n +0X119bZ", 9, 0, 6, },
+ { " \t\n -0x119bZ", 9, 0, 6, },
+ { " \t\n 119bZ", 9, 10, 6, },
+ { "+119bZ", 9, 10, 3, },
+ { "+0X119bz", 9, 0, 2, },
+ { "119b8Z", 10, 119, 3, },
+ { "119bZ", 10, 119, 3, },
+ { "-0119bZ", 10, -119, 5, },
+ { " \t\n 0X119bZ", 10, 0, 5, },
+ { " \t\n +0X119bZ", 10, 0, 6, },
+ { " \t\n -0x119bZ", 10, 0, 6, },
+ { " \t\n 119bZ", 10, 119, 7, },
+ { "+119bZ", 10, 119, 4, },
+ { "+0X119bz", 10, 0, 2, },
+ { "119b8Z", 16, 72120, 5, },
+ { "119bZ", 16, 4507, 4, },
+ { "-0119bZ", 16, -4507, 6, },
+ { " \t\n 0X119bZ", 16, 4507, 10, },
+ { " \t\n +0X119bZ", 16, 4507, 11, },
+ { " \t\n -0x119bZ", 16, -4507, 11, },
+ { " \t\n 119bZ", 16, 4507,8, },
+ { "+119bZ", 16, 4507, 5, },
+ { "+0X119bz", 16, 4507, 7, },
+ { "119b8Z", 36, 62580275, 6, },
+ { "119bZ", 36, 1738367, 5, },
+ { "-0119bZ", 36, -1738367, 7, },
+ { " \t\n 0X119bZ", 36, 1997122175, 11, },
+ { " \t\n +0X119bZ", 36, 1997122175, 12, },
+ { " \t\n -0x119bZ", 36, -1997122175, 12, },
+ { " \t\n 119bZ", 36, 1738367, 9, },
+ { "+119bZ", 36, 1738367, 6, },
+ { "+0X119bz", 36, 1997122175, 8, },
+ /* There should be a much larger battery of such tests. */
+ { "127", 0, 127, 3, },
+ { "-127", 0, -127, 4, },
+ { "128", 0, 128, 3, },
+ { "-128", 0, -127-1, 4, },
+ { "255", 0, 255, 3, },
+ { "-255", 0, -255, 4, },
+ { "256", 0, 256, 3, },
+ { "-256", 0, -255-1, 4, },
+ { "32767", 0, 32767, 5, },
+ { "-32767", 0, -32767, 6, },
+ { "32768", 0, 32768, 5, },
+ { "-32768", 0, -32767-1, 6, },
+ { "65535", 0, 65535, 5, },
+ { "-65535", 0, -65536+1, 6, },
+ { "65536", 0, 65536, 5, },
+ { "-65536", 0, -65536, 6, },
+ { "2147483647", 0, 2147483647, 10, },
+ { "-2147483647", 0, -2147483647, 11, },
+ { "2147483648", 0, 2147483648, 10, },
+ { "-2147483648", 0, -2147483647-1, 11, },
+ { "4294967295", 0, 4294967295, 10, },
+ { "-4294967295", 0, -4294967296+1, 11, },
+ { "4294967296", 0, 4294967296, 10, },
+ { "-4294967296", 0, -4294967296, 11, },
+ { "9223372036854775807", 0, 9223372036854775807, 19, },
+ { "-9223372036854775807", 0, -9223372036854775807, 20, },
+ { "1234567890123456789", 0, 1234567890123456789, 19, },
+ { "-1234567890123456789", 0, -1234567890123456789, 20, },
+ { "1", 0, 1, 1, },
+ { "-1", 0, -1, 2, },
+ { "2", 0, 2, 1, },
+ { "-2", 0, -2, 2, },
+ { "10", 0, 10, 2, },
+ { "-10", 0, -10, 3, },
+ { "16", 0, 16, 2, },
+ { "-16", 0, -16, 3, },
+ /* Other test cases can be added here. */
+ { NULL, 0, 0, 0 }, /* terminates the list */
+ }, *sdp;
+
+ for ( sdp = str_data; sdp->nptr != NULL ; ++sdp )
+ {
+ /*
+ 7.8.2.3 The strtoimax and strtoumax functions
+ */
+
+ strcpy(saved, sdp->nptr);
+
+ errno = 0; /* shouldn't be changed */
+
+ if ( (intmax = strtoimax(sdp->nptr, &endptr, sdp->base))
+ != sdp->exp_val
+ ) {
+ int save = errno;
+
+ printf("*** strtoimax(%s,,%d) failed; should be: %"
+ PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
+ sdp->base, sdp->exp_val, intmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+ else if ( endptr != sdp->nptr + sdp->exp_len )
+ {
+ int save = errno;
+
+ printf("*** strtoimax(%s,,%d) returned wrong endptr"
+ " ***\n", sdp->nptr, sdp->base
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ printf("*** strtoimax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( strcmp(sdp->nptr, saved) != 0 )
+ {
+ printf("*** strtoimax modified its input ***\n");
+ status = EXIT_FAILURE;
+ strcpy(saved, sdp->nptr);
+ }
+
+ if ( sdp->exp_val >= 0 ) /* else some sign extension */
+ {
+ errno = 0; /* shouldn't be changed */
+
+ if ( (uintmax = strtoumax(sdp->nptr, &endptr, sdp->base
+ )
+ ) != sdp->exp_val
+ ) {
+ int save = errno;
+
+ printf("*** strtoumax(%s,,%d) failed; "
+ "should be: %"PRIuMAX", was: %"PRIuMAX
+ " ***\n", sdp->nptr, sdp->base,
+ sdp->exp_val, uintmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+ else if ( endptr != sdp->nptr + sdp->exp_len )
+ {
+ int save = errno;
+
+ printf("*** strtoumax(%s,,%d) returned wrong "
+ "endptr ***\n", sdp->nptr, sdp->base
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ printf("*** strtoumax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( strcmp(sdp->nptr, saved) != 0 )
+ {
+ printf("*** strtoumax"
+ " modified its input ***\n"
+ );
+ status = EXIT_FAILURE;
+ strcpy(saved, sdp->nptr);
+ }
+ }
+
+ /* tests for null endptr */
+
+#define WARN() if (!warned) warned = 1, printf("*** Using null endptr: ***\n")
+
+ warned = 0;
+ errno = 0; /* shouldn't be changed */
+
+ if ( (intmax = strtoimax(sdp->nptr, (char **)NULL, sdp->base))
+ != sdp->exp_val
+ ) {
+ int save = errno;
+
+ WARN();
+ printf("*** strtoimax(%s,NULL,%d) failed; "
+ "should be: %"PRIdMAX", was: %"PRIdMAX" ***\n",
+ sdp->nptr, sdp->base, sdp->exp_val, intmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ WARN();
+ printf("*** strtoimax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( strcmp(sdp->nptr, saved) != 0 )
+ {
+ WARN();
+ printf("*** strtoimax modified its input ***\n");
+ status = EXIT_FAILURE;
+ strcpy(saved, sdp->nptr);
+ }
+
+ if ( sdp->exp_val >= 0 ) /* else some sign extension */
+ {
+ errno = 0; /* shouldn't be changed */
+
+ if ( (uintmax = strtoumax(sdp->nptr, (char **)NULL,
+ sdp->base
+ )
+ ) != sdp->exp_val
+ ) {
+ int save = errno;
+
+ WARN();
+ printf("*** strtoumax(%s,NULL,%d) failed; "
+ "should be: %"PRIuMAX", was: %"PRIuMAX
+ " ***\n", sdp->nptr, sdp->base,
+ sdp->exp_val, uintmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ WARN();
+ printf("*** strtoumax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( strcmp(sdp->nptr, saved) != 0 )
+ {
+ WARN();
+ printf("*** strtoumax"
+ " modified its input ***\n"
+ );
+ status = EXIT_FAILURE;
+ strcpy(saved, sdp->nptr);
+ }
+ }
+
+ /*
+ 7.8.2.4 The wcstoimax and wcstoumax functions
+ */
+
+ for ( i = 0; i < 64; ++i )
+ if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
+ break;
+
+ errno = 0; /* shouldn't be changed */
+
+ if ( (intmax = wcstoimax(wnptr, &wendptr, sdp->base))
+ != sdp->exp_val
+ ) {
+ int save = errno;
+
+ printf("*** wcstoimax(%s,,%d) failed; should be: %"
+ PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
+ sdp->base, sdp->exp_val, intmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+ else if ( wendptr != wnptr + sdp->exp_len )
+ {
+ int save = errno;
+
+ printf("*** wcstoimax(%s,,%d) returned wrong endptr"
+ " ***\n", sdp->nptr, sdp->base
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ printf("*** wcstoimax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ for ( i = 0; i < 64; ++i )
+ if ( wnptr[i] != sdp->nptr[i] )
+ {
+ printf("*** wcstoimax modified its input ***\n"
+ );
+ status = EXIT_FAILURE;
+
+ for ( ; i < 64; ++i )
+ if ( (wnptr[i] = sdp->nptr[i]) == '\0' )
+ break;
+
+ break;
+ }
+ else if ( wnptr[i] == '\0' )
+ break;
+
+ if ( sdp->exp_val >= 0 ) /* else some sign extension */
+ {
+ errno = 0; /* shouldn't be changed */
+
+ if ( (uintmax = wcstoumax(wnptr, &wendptr, sdp->base)
+ ) != sdp->exp_val
+ ) {
+ int save = errno;
+
+ printf("*** wcstoumax(%s,,%d) failed; "
+ "should be: %"PRIuMAX", was: %"PRIuMAX
+ " ***\n", sdp->nptr, sdp->base,
+ sdp->exp_val, uintmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+ else if ( wendptr != wnptr + sdp->exp_len )
+ {
+ int save = errno;
+
+ printf("*** wcstoumax(%s,,%d) returned wrong "
+ "endptr ***\n", sdp->nptr, sdp->base
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ printf("*** wcstoumax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ for ( i = 0; i < 64; ++i )
+ if ( wnptr[i] != sdp->nptr[i] )
+ {
+ printf("*** wcstoumax"
+ " modified its input ***\n"
+ );
+ status = EXIT_FAILURE;
+
+ for ( ; i < 64; ++i )
+ if ( (wnptr[i] = sdp->nptr[i])
+ == '\0'
+ )
+ break;
+
+ break;
+ }
+ else if ( wnptr[i] == '\0' )
+ break;
+ }
+
+ /* tests for null endptr */
+
+ warned = 0;
+ errno = 0; /* shouldn't be changed */
+
+ if ( (intmax = wcstoimax(wnptr, (wchar_t **)NULL, sdp->base))
+ != sdp->exp_val
+ ) {
+ int save = errno;
+
+ WARN();
+ printf("*** wcstoimax(%s,NULL,%d) failed; should be: %"
+ PRIdMAX", was: %"PRIdMAX" ***\n", sdp->nptr,
+ sdp->base, sdp->exp_val, intmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ WARN();
+ printf("*** wcstoimax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ for ( i = 0; i < 64; ++i )
+ if ( wnptr[i] != sdp->nptr[i] )
+ {
+ WARN();
+ printf("*** wcstoimax modified its input ***\n"
+ );
+ status = EXIT_FAILURE;
+
+ for ( ; i < 64; ++i )
+ if ( (wnptr[i] = sdp->nptr[i])
+ == '\0'
+ )
+ break;
+
+ break;
+ }
+ else if ( wnptr[i] == '\0' )
+ break;
+
+ if ( sdp->exp_val >= 0 ) /* else some sign extension */
+ {
+ errno = 0; /* shouldn't be changed */
+
+ if ( (uintmax = wcstoumax(wnptr, (wchar_t **)NULL,
+ sdp->base
+ )
+ ) != sdp->exp_val
+ ) {
+ int save = errno;
+
+ WARN();
+ printf("*** wcstoumax(%s,NULL,%d) failed; "
+ "should be: %"PRIuMAX", was: %"PRIuMAX
+ " ***\n", sdp->nptr, sdp->base,
+ sdp->exp_val, uintmax
+ );
+ status = EXIT_FAILURE;
+ errno = save;
+ }
+
+ if ( errno != 0 )
+ {
+ WARN();
+ printf("*** wcstoumax modified errno ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ for ( i = 0; i < 64; ++i )
+ if ( wnptr[i] != sdp->nptr[i] )
+ {
+ WARN();
+ printf("*** wcstoumax"
+ " modified its input ***\n"
+ );
+ status = EXIT_FAILURE;
+
+ for ( ; i < 64; ++i )
+ if ( (wnptr[i] = sdp->nptr[i])
+ == '\0'
+ )
+ break;
+
+ break;
+ }
+ else if ( wnptr[i] == '\0' )
+ break;
+ }
+ }
+
+ /*
+ 7.8.2.3 The strtoimax and strtoumax functions (continued)
+ */
+
+ if ( (intmax = strtoimax("1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890",
+ &endptr, 0
+ )
+ ) != INTMAX_MAX || errno != ERANGE
+ ) {
+ printf("*** strtoimax failed overflow test ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( (intmax = strtoimax("+1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890",
+ &endptr, 0
+ )
+ ) != INTMAX_MAX || errno != ERANGE
+ ) {
+ printf("*** strtoimax failed +overflow test ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( (intmax = strtoimax("-1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890",
+ &endptr, 0
+ )
+ ) != INTMAX_MIN || errno != ERANGE
+ ) {
+ printf("*** strtoimax failed -overflow test ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( (uintmax = strtoumax("1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890",
+ &endptr, 0
+ )
+ ) != UINTMAX_MAX || errno != ERANGE
+ ) {
+ printf("*** strtoumax failed overflow test ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( (uintmax = strtoumax("+1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890",
+ &endptr, 0
+ )
+ ) != UINTMAX_MAX || errno != ERANGE
+ ) {
+ printf("*** strtoumax failed +overflow test ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ if ( (uintmax = strtoumax("-1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890"
+ "1234567890123456789012345678901234567890",
+ &endptr, 0
+ )
+ ) != UINTMAX_MAX || errno != ERANGE
+ ) {
+ printf("*** strtoumax failed -overflow test ***\n");
+ status = EXIT_FAILURE;
+ }
+
+ /*
+ 7.8.2.4 The wcstoimax and wcstoumax functions (continued)
+ */