]> pd.if.org Git - pdclib/blobdiff - functions/stdlib/strtol.c
Intermediate work, checked in for safekeeping as I pick up working on this again.
[pdclib] / functions / stdlib / strtol.c
index 4a3b5a68f8c56e89fffddf53d961a1be03582759..04c8617541c0650b4bfb3a42b6b3b3ecb154a3c4 100644 (file)
@@ -21,12 +21,12 @@ long int strtol( const char * s, char ** endptr, int base )
     if ( base < 2 || base > 36 ) return 0;
     if ( 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, (unsigned)base, (uintmax_t)LONG_MAX, (uintmax_t)( LONG_MAX / base ), (int)( LONG_MAX % base ), &sign );
     }
     else
     {
         /* FIXME: This breaks on some machines that round negatives wrongly */
-        rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LONG_MIN, (uintmax_t)( LONG_MIN / -base ), (uintmax_t)( -( LONG_MIN % base ) ), &sign );
+        rc = _PDCLIB_strtox_main( &p, (unsigned)base, (uintmax_t)LONG_MIN, (uintmax_t)( LONG_MIN / -base ), (int)( -( LONG_MIN % base ) ), &sign );
     }
     if ( endptr != NULL ) *endptr = ( p != NULL ) ? (char *) p : (char *) s;
     return ( sign == '+' ) ? rc : -rc;
@@ -92,7 +92,7 @@ int main( void )
     TESTCASE( strtol( "0x80000000", NULL, 0 ) == LONG_MAX );
     TESTCASE( errno == ERANGE );
     errno = 0;
-    TESTCASE( strtol( "-0x7FFFFFFF", NULL, 0 ) == 0x80000001 );
+    TESTCASE( strtol( "-0x7FFFFFFF", NULL, 0 ) == (long)0x80000001 );
     TESTCASE( errno == 0 );
     TESTCASE( strtol( "-0x80000000", NULL, 0 ) == LONG_MIN );
     TESTCASE( errno == 0 );