more header fixes, minor warning fix
[musl] / src / stdlib / wcstoimax.c
1 #include <wchar.h>
2 #include <wctype.h>
3 #include <inttypes.h>
4 #include <errno.h>
5
6 intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base)
7 {
8         int sign = 0;
9         uintmax_t x;
10
11         /* Initial whitespace */
12         for (; iswspace(*s); s++);
13
14         /* Optional sign */
15         if (*s == '-') sign = *s++;
16         else if (*s == '+') s++;
17
18         x = wcstoumax(s, p, base);
19         if (x > INTMAX_MAX) {
20                 if (!sign || -x != INTMAX_MIN)
21                         errno = ERANGE;
22                 return sign ? INTMAX_MIN : INTMAX_MAX;
23         }
24         return sign ? -x : x;
25 }