/* $Id$ */
-/* Release $Name$ */
-
/* strtoul( const char *, char * *, int )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
-#define _PDCLIB_INT_H _PDCLIB_INT_H
-#include <_PDCLIB_int.h>
#include <limits.h>
#include <stdlib.h>
#ifndef REGTEST
+#include <stdint.h>
+
unsigned long int strtoul( const char * s, char ** endptr, int base )
{
unsigned long int rc;
char sign = '+';
const char * p = _PDCLIB_strtox_prelim( s, &sign, &base );
- rc = _PDCLIB_strtox_main( &p, base, ULONG_MAX, ULONG_MAX / base, ULONG_MAX % base, &sign );
+ if ( base < 2 || base > 36 ) return 0;
+ rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)ULONG_MAX, (uintmax_t)( ULONG_MAX / base ), (uintmax_t)( ULONG_MAX % base ), &sign );
if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s;
return ( sign == '+' ) ? rc : -rc;
}
#include <_PDCLIB_test.h>
#include <errno.h>
-int main()
+int main( void )
{
char * endptr;
/* this, to base 36, overflows even a 256 bit integer */
char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_";
- BEGIN_TESTS;
errno = 0;
/* basic functionality */
TESTCASE( strtoul( "123", NULL, 10 ) == 123 );