1 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
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 (iswspace(c
));
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
++)
50 c
-= iswupper(c
) ? L
'A' - 10 : L
'a' - 10;
55 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
71 *endptr
= any
? (wchar_t *)s
- 1 : (wchar_t *)nptr
;
76 unsigned long wcstoul(const wchar_t *cp
,wchar_t **endp
,int base
)
78 unsigned long result
= 0,value
;
85 if ((*cp
== L
'x') && iswxdigit(cp
[1])) {
91 while (iswxdigit(*cp
) && (value
= iswdigit(*cp
) ? *cp
-L
'0' : (iswlower(*cp
)
92 ? towupper(*cp
) : *cp
)-L
'A'+10) < base
) {
93 result
= result
*base
+ value
;
97 *endp
= (wchar_t *)cp
;