33 #include <sys/cdefs.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/ctype.h>
39 #include <sys/limits.h>
48 strtouq(
const char *nptr,
char **endptr,
int base)
53 u_quad_t qbase, cutoff;
70 if ((base == 0 || base == 16) &&
71 c ==
'0' && (*s ==
'x' || *s ==
'X')) {
77 base = c ==
'0' ? 8 : 10;
78 qbase = (unsigned)base;
79 cutoff = (u_quad_t)UQUAD_MAX / qbase;
80 cutlim = (u_quad_t)UQUAD_MAX % qbase;
81 for (acc = 0, any = 0;; c = *s++) {
87 c -= isupper(c) ?
'A' - 10 :
'a' - 10;
92 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
105 *endptr = __DECONST(
char *, any ? s - 1 : nptr);
u_quad_t strtouq(const char *nptr, char **endptr, int base)