3 unsigned long int strtoul(const char *ptr
, char **endptr
, int base
)
5 int neg
= 0, overflow
= 0;
10 while(isspace(*nptr
)) ++nptr
;
12 if (*nptr
== '-') { neg
=1; nptr
++; }
13 else if (*nptr
== '+') ++nptr
;
15 if (base
==16 && nptr
[0]=='0') goto skip0x
;
17 register unsigned int b
=base
-2;
18 if (__unlikely(b
>34)) { errno
=EINVAL
; return 0; }
23 if ((nptr
[1]=='x'||nptr
[1]=='X') && isxdigit(nptr
[2])) {
30 while(__likely(*nptr
)) {
31 register unsigned char c
=*nptr
;
32 c
=(c
>='a'?c
-'a'+10:c
>='A'?c
-'A'+10:c
<='9'?c
-'0':0xff);
33 if (__unlikely(c
>=base
)) break; /* out of base */
35 register unsigned long x
=(v
&0xff)*base
+c
;
36 register unsigned long w
=(v
>>8)*base
+(x
>>8);
37 if (w
>(ULONG_MAX
>>8)) overflow
=1;
42 if (__unlikely(nptr
==orig
)) { /* no conversion done */
47 if (endptr
) *endptr
=(char *)nptr
;