4 * The strntoumax() function and associated
11 static inline int digitval(int ch)
13 if ( ch >= '0' && ch <= '9' ) {
15 } else if ( ch >= 'A' && ch <= 'Z' ) {
17 } else if ( ch >= 'a' && ch <= 'z' ) {
24 uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
30 while ( n && isspace((unsigned char)*nptr) ) {
35 /* Single optional + or - */
36 if ( n && *nptr == '-' ) {
40 } else if ( n && *nptr == '+' ) {
45 if ( n >= 2 && nptr[0] == '0' &&
46 (nptr[1] == 'x' || nptr[1] == 'X') ) {
50 } else if ( n >= 1 && nptr[0] == '0' ) {
57 } else if ( base == 16 ) {
58 if ( n >= 2 && nptr[0] == '0' &&
59 (nptr[1] == 'x' || nptr[1] == 'X') ) {
65 while ( n && (d = digitval(*nptr)) >= 0 && d < base ) {
72 *endptr = (char *)nptr;
74 return minus ? -v : v;