fix incorrect overflow errors on strtoul, etc.
[musl] / src / stdlib / wcstol.c
1 #include <wchar.h>
2 #include <stdlib.h>
3 #include <inttypes.h>
4 #include <errno.h>
5 #include <limits.h>
6
7 long wcstol(const wchar_t *s, wchar_t **p, int base)
8 {
9         intmax_t x = wcstoimax(s, p, base);
10         if (x > LONG_MAX) {
11                 errno = ERANGE;
12                 return LONG_MAX;
13         } else if (x < LONG_MIN) {
14                 errno = ERANGE;
15                 return LONG_MIN;
16         }
17         return x;
18 }