Files
musl/src/stdlib/wcstoumax.c

36 lines
611 B
C
Raw Normal View History

2011-02-12 00:22:29 -05:00
#include <wchar.h>
2011-02-14 19:33:11 -05:00
#include <wctype.h>
2011-02-12 00:22:29 -05:00
#include <stdlib.h>
#include <inttypes.h>
#include <errno.h>
#include "intparse.h"
2011-02-12 00:22:29 -05:00
uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base)
{
struct intparse ip = {0};
unsigned char tmp;
2011-02-12 00:22:29 -05:00
if (p) *p = (wchar_t *)s;
2011-02-12 00:22:29 -05:00
if (base && base-2U > 34) {
2011-02-12 00:22:29 -05:00
errno = EINVAL;
return 0;
}
for (; iswspace(*s); s++);
ip.base = base;
for (; *s<256 && (tmp=*s, __intparse(&ip, &tmp, 1)); s++);
2011-02-12 00:22:29 -05:00
if (p && ip.err != EINVAL)
2011-02-12 00:22:29 -05:00
*p = (wchar_t *)s;
if (ip.err) {
errno = ip.err;
if (ip.err = EINVAL) return 0;
return UINTMAX_MAX;
2011-02-12 00:22:29 -05:00
}
return ip.neg ? -ip.val : ip.val;
2011-02-12 00:22:29 -05:00
}