4775585eb5f69535bb64f234584ef1ce769ccbc2
5 * Convert a unicode string to an unsigned long integer.
7 * Ignores `locale' stuff. Assumes that the upper and lower case
8 * alphabets and digits are each contiguous.
13 wcstoul(const wchar_t *nptr
, wchar_t **endptr
, int base
)
15 const wchar_t *s
= nptr
;
19 int neg
= 0, any
, cutlim
;
22 * See strtol for comments as to the logic used.
26 } while (iswctype(c
, _SPACE
));
34 if ((base
== 0 || base
== 16) &&
35 c
== L
'0' && (*s
== L
'x' || *s
== L
'X'))
42 base
= c
== L
'0' ? 8 : 10;
43 cutoff
= (unsigned long)ULONG_MAX
/ (unsigned long)base
;
44 cutlim
= (unsigned long)ULONG_MAX
% (unsigned long)base
;
45 for (acc
= 0, any
= 0;; c
= *s
++)
47 if (iswctype(c
, _DIGIT
))
49 else if (iswctype(c
, _ALPHA
))
50 c
-= iswctype(c
, _UPPER
) ? L
'A' - 10 : L
'a' - 10;
55 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
70 *endptr
= any
? (wchar_t *)((size_t)(s
- 1)) : (wchar_t *)((size_t)nptr
);