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' && (nptr
[1] == 'x' || nptr
[1] == 'X')) {
49 } else if (n
>= 1 && nptr
[0] == '0') {
56 } else if (base
== 16) {
57 if (n
>= 2 && nptr
[0] == '0' && (nptr
[1] == 'x' || nptr
[1] == 'X')) {
63 while (n
&& (d
= digitval(*nptr
)) >= 0 && d
< base
) {
70 *endptr
= (char *)nptr
;
72 return minus
? -v
: v
;