v->cnt += n;
for (; n; n--, s++) switch (v->state) {
case 0:
+ v->err = EINVAL;
v->state++;
if (*s=='+' || *s=='-') {
v->neg = *s=='-';
case 2:
v->state++;
if ((!b || b==16) && (*s|32) == 'x') {
+ v->err = 0;
v->base = b = 16;
continue;
}
case 3:
firstdigit:
if (digits[*s] >= b) {
- v->err = EINVAL;
- return 0;
+ n++;
+ goto finished;
}
seconddigit:
+ v->err = 0;
v->state++;
case 4:
if (b==10) {
if (n && digits[*s]<b) {
v->err = ERANGE;
v->val = UINTMAX_MAX;
-
n--; s++;
+ for (; n && digits[*s]<b; n--, s++);
}
- for (; n && digits[*s]<b; n--, s++);
if (!n) return 1;
+ goto finished;
}
return 1;
finished:
if (ip.err) {
errno = ip.err;
- if (ip.err = EINVAL) return 0;
+ if (ip.err == EINVAL) return 0;
return ip.neg ? INTMAX_MIN : INTMAX_MAX;
}
if (ip.err) {
errno = ip.err;
- if (ip.err = EINVAL) return 0;
+ if (ip.err == EINVAL) return 0;
return UINTMAX_MAX;
}
intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base)
{
+ const wchar_t *s1 = s;
struct intparse ip = {0};
if (p) *p = (wchar_t *)s;
for (; __intparse(&ip, (char[]){(*s&-(*s<128U))}, 1); s++);
if (p && ip.err != EINVAL)
- *p = (wchar_t *)s;
+ *p = (wchar_t *)s1 + ip.cnt;
if (ip.err) {
errno = ip.err;
- if (ip.err = EINVAL) return 0;
+ if (ip.err == EINVAL) return 0;
return ip.neg ? INTMAX_MIN : INTMAX_MAX;
}
uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base)
{
+ const wchar_t *s1 = s;
struct intparse ip = {0};
if (p) *p = (wchar_t *)s;
for (; __intparse(&ip, (char[]){(*s&-(*s<128U))}, 1); s++);
if (p && ip.err != EINVAL)
- *p = (wchar_t *)s;
+ *p = (wchar_t *)s1 + ip.cnt;
if (ip.err) {
errno = ip.err;
- if (ip.err = EINVAL) return 0;
+ if (ip.err == EINVAL) return 0;
return UINTMAX_MAX;
}