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 - */
38 if ( c == '-' || c == '+' ) {
46 if ( n >= 2 && nptr[0] == '0' &&
47 (nptr[1] == 'x' || nptr[1] == 'X') ) {
51 } else if ( n >= 1 && nptr[0] == '0' ) {
58 } else if ( base == 16 ) {
59 if ( n >= 2 && nptr[0] == '0' &&
60 (nptr[1] == 'x' || nptr[1] == 'X') ) {
66 while ( n && (d = digitval(*nptr)) >= 0 && d < base ) {
73 *endptr = (char *)nptr;
75 return minus ? -v : v;