]> pd.if.org Git - pdclib/blobdiff - functions/stdlib/strtoul.c
Merged branch stdio_rewrite back into trunk.
[pdclib] / functions / stdlib / strtoul.c
index e38dbd678f36b95b736949467a3a244fe2385ae0..7bd8488feaae1cc80932d2b71ec98c232f27f205 100644 (file)
@@ -1,26 +1,25 @@
 /* $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.
 */
 
-#include <_PDCLIB_int.h>
 #include <limits.h>
-#include <stddef.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 = (unsigned long int)_PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)ULONG_MAX, (uintmax_t)( ULONG_MAX / base ), (int)( ULONG_MAX % base ), &sign );
     if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s;
     return ( sign == '+' ) ? rc : -rc;
 }
@@ -31,12 +30,11 @@ unsigned long int strtoul( const char * s, char ** endptr, int base )
 #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 );