/* strtol( const char *, char * *, int )
This file is part of the Public Domain C Library (PDCLib).
/* strtol( const char *, char * *, int )
This file is part of the Public Domain C Library (PDCLib).
long int strtol( const char * s, char ** endptr, int base )
{
long int rc;
char sign = '+';
const char * p = _PDCLIB_strtox_prelim( s, &sign, &base );
long int strtol( const char * s, char ** endptr, int base )
{
long int rc;
char sign = '+';
const char * p = _PDCLIB_strtox_prelim( s, &sign, &base );
- rc = _PDCLIB_strtox_main( &p, base, LONG_MAX, LONG_MAX / base, LONG_MAX % base, &sign );
+ rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LONG_MAX, (uintmax_t)( LONG_MAX / base ), (uintmax_t)( LONG_MAX % base ), &sign );
- rc = _PDCLIB_strtox_main( &p, base, LONG_MIN, LONG_MIN / -base, -( LONG_MIN % base ), &sign );
+ rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LONG_MIN, (uintmax_t)( LONG_MIN / -base ), (uintmax_t)( -( LONG_MIN % base ) ), &sign );
}
if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s;
return ( sign == '+' ) ? rc : -rc;
}
if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s;
return ( sign == '+' ) ? rc : -rc;
{
char * endptr;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
{
char * endptr;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
errno = 0;
/* basic functionality */
TESTCASE( strtol( "123", NULL, 10 ) == 123 );
errno = 0;
/* basic functionality */
TESTCASE( strtol( "123", NULL, 10 ) == 123 );