fix incorrect overflow errors on strtoul, etc.
[musl] / src / stdlib / strtoull.c
1 #include <stdlib.h>
2 #include <inttypes.h>
3 #include <errno.h>
4 #include <limits.h>
5
6 unsigned long long strtoull(const char *s, char **p, int base)
7 {
8         intmax_t x;
9         if (sizeof(intmax_t) == sizeof(long long))
10                 return strtoumax(s, p, base);
11         x = strtoimax(s, p, base);
12         if (-x > ULLONG_MAX || x > ULLONG_MAX) {
13                 errno = ERANGE;
14                 return ULLONG_MAX;
15         }
16         return x;
17 }