X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdlib%2Fstrtoll.c;h=80a8d176f524e2d06efa96a13c86205bd00d05dc;hb=d9dcf16664c81809258992e1653ecb68c8079974;hp=2f7a2697d75823ab1054bbb55392ca860118af60;hpb=a7fcb7c1fec94e1992098fb892bc8fb7d607ae5e;p=pdclib.old diff --git a/functions/stdlib/strtoll.c b/functions/stdlib/strtoll.c index 2f7a269..80a8d17 100644 --- a/functions/stdlib/strtoll.c +++ b/functions/stdlib/strtoll.c @@ -1,32 +1,32 @@ /* $Id$ */ -/* Release $Name$ */ - /* strtoll( 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 #include #ifndef REGTEST +#include + long long int strtoll( const char * s, char ** endptr, int base ) { long long int rc; char sign = '+'; const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); + if ( base < 2 || base > 36 ) return 0; if ( sign == '+' ) { - rc = _PDCLIB_strtox_main( &p, base, LLONG_MAX, LLONG_MAX / base, LLONG_MAX % base, &sign ); + rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LLONG_MAX, (uintmax_t)( LLONG_MAX / base ), (uintmax_t)( LLONG_MAX % base ), &sign ); } else { /* FIXME: This breaks on some machines that round negatives wrongly */ - rc = _PDCLIB_strtox_main( &p, base, LLONG_MIN, LLONG_MIN / -base, -( LLONG_MIN % base ), &sign ); + rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LLONG_MIN, (uintmax_t)( LLONG_MIN / -base ), (uintmax_t)( -( LLONG_MIN % base ) ), &sign ); } if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s; return ( sign == '+' ) ? rc : -rc; @@ -36,14 +36,19 @@ long long int strtoll( const char * s, char ** endptr, int base ) #ifdef TEST #include <_PDCLIB_test.h> + +#ifndef _PDCLIB_INT_H +#define _PDCLIB_INT_H +#include <_PDCLIB_int.h> +#endif + #include -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( strtoll( "123", NULL, 10 ) == 123 );