5 /* _PDCLIB_strtox_main( const char * *, int, _PDCLIB_uintmax_t, _PDCLIB_uintmax_t, int )
7 This file is part of the Public Domain C Library (PDCLib).
8 Permission is granted to use, modify, and / or redistribute at will.
11 #define _PDCLIB_INT_H _PDCLIB_INT_H
12 #include <_PDCLIB_int.h>
17 _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, int base, _PDCLIB_uintmax_t error, _PDCLIB_uintmax_t limval, _PDCLIB_uintmax_t limdigit, char * sign )
19 _PDCLIB_uintmax_t rc = 0;
22 while ( ( x = memchr( _PDCLIB_digits, toupper(**p), base ) ) != NULL )
24 digit = x - _PDCLIB_digits;
25 if ( ( rc < limval ) || ( ( rc == limval ) && ( digit <= limdigit ) ) )
27 rc = rc * base + ( x - _PDCLIB_digits );
33 /* TODO: Only if endptr != NULL - but do we really want *another* parameter? */
34 while ( memchr( _PDCLIB_digits, **p, base ) != NULL ) ++(*p);
35 /* TODO: This is ugly, but keeps caller from negating the error value */
49 #include <_PDCLIB_test.h>
59 /* basic functionality */
62 TESTCASE( _PDCLIB_strtox_main( &p, 10, 999, 12, 3, &sign ) == 123 );
63 TESTCASE( errno == 0 );
64 TESTCASE( p == &test[3] );
65 /* proper functioning to smaller base */
67 TESTCASE( _PDCLIB_strtox_main( &p, 8, 999, 12, 3, &sign ) == 0123 );
68 TESTCASE( errno == 0 );
69 TESTCASE( p == &test[3] );
70 /* overflowing subject sequence must still return proper endptr */
72 TESTCASE( _PDCLIB_strtox_main( &p, 4, 999, 1, 2, &sign ) == 999 );
73 TESTCASE( errno == ERANGE );
74 TESTCASE( p == &test[3] );
75 TESTCASE( sign == '+' );
76 /* testing conversion failure */
80 TESTCASE( _PDCLIB_strtox_main( &p, 10, 999, 99, 8, &sign ) == 0 );
81 TESTCASE( p == NULL );