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>
|
2011-07-14 00:51:45 -04:00
|
|
|
#include "intparse.h"
|
2011-02-12 00:22:29 -05:00
|
|
|
|
|
|
|
uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base)
|
|
|
|
{
|
2011-07-14 00:51:45 -04:00
|
|
|
struct intparse ip = {0};
|
|
|
|
unsigned char tmp;
|
2011-02-12 00:22:29 -05:00
|
|
|
|
2011-07-14 00:51:45 -04:00
|
|
|
if (p) *p = (wchar_t *)s;
|
2011-02-12 00:22:29 -05:00
|
|
|
|
2011-07-14 00:51:45 -04:00
|
|
|
if (base && base-2U > 34) {
|
2011-02-12 00:22:29 -05:00
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; iswspace(*s); s++);
|
|
|
|
|
2011-07-14 00:51:45 -04:00
|
|
|
ip.base = base;
|
|
|
|
for (; *s<256 && (tmp=*s, __intparse(&ip, &tmp, 1)); s++);
|
2011-02-12 00:22:29 -05:00
|
|
|
|
2011-07-14 00:51:45 -04:00
|
|
|
if (p && ip.err != EINVAL)
|
2011-02-12 00:22:29 -05:00
|
|
|
*p = (wchar_t *)s;
|
2011-07-14 00:51:45 -04:00
|
|
|
|
|
|
|
if (ip.err) {
|
|
|
|
errno = ip.err;
|
|
|
|
if (ip.err = EINVAL) return 0;
|
|
|
|
return UINTMAX_MAX;
|
2011-02-12 00:22:29 -05:00
|
|
|
}
|
|
|
|
|
2011-07-14 00:51:45 -04:00
|
|
|
return ip.neg ? -ip.val : ip.val;
|
2011-02-12 00:22:29 -05:00
|
|
|
}
|