7 uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base)
9 /* Large enough for largest value in binary */
10 char buf[sizeof(uintmax_t)*8+2];
11 int sign = 0, skipped=0;
13 if (!p) p = (wchar_t **)&s;
15 if (base && (unsigned)base-2 > 36-2) {
21 /* Initial whitespace */
22 for (; iswspace(*s); s++);
25 if (*s == '-') sign = *s++;
26 else if (*s == '+') s++;
28 /* Skip leading zeros but don't allow leading zeros before "0x". */
29 for (; s[0]=='0' && s[1]=='0'; s++) skipped=1;
30 if (skipped && (base==0 || base==16) && (s[1]|32)=='x') {
31 *p = (wchar_t *)(s+1);
35 /* Convert to normal char string so we can use strtoumax */
37 if (wcstombs(buf+!!sign, s, sizeof buf-1) == -1) return 0;
40 /* Compute final position */
42 if ((base==0 || base==16) && s[0]=='0' && (s[1]|32)=='x' && iswxdigit(s[2])) s+=2;
43 for(;*s&&((unsigned)*s-'0'<base||((unsigned)*s|32)-'a'<base-10);s++);
47 return strtoumax(buf, 0, base);