]> pd.if.org Git - pdclib/blobdiff - functions/stdlib/strtoull.c
Intermediate work, checked in for safekeeping as I pick up working on this again.
[pdclib] / functions / stdlib / strtoull.c
index 08b696a4921359cb92982f8f4aae9de7cc59aaaf..b4204e91bac79e1fb78e96159f70c0fb647ea1f1 100644 (file)
@@ -1,26 +1,25 @@
 /* $Id$ */
 
-/* Release $Name$ */
-
 /* strtoull( 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 long int strtoull( const char * s, char ** endptr, int base )
 {
     unsigned long long int rc;
     char sign = '+';
     const char * p = _PDCLIB_strtox_prelim( s, &sign, &base );
-    rc = _PDCLIB_strtox_main( &p, base, ULLONG_MAX, ULLONG_MAX / base, ULLONG_MAX % base, &sign );
+    if ( base < 2 || base > 36 ) return 0;
+    rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)ULLONG_MAX, (uintmax_t)( ULLONG_MAX / base ), (int)( ULLONG_MAX % base ), &sign );
     if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s;
     return ( sign == '+' ) ? rc : -rc;
 }
@@ -31,12 +30,11 @@ unsigned long long int strtoull( 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( strtoull( "123", NULL, 10 ) == 123 );