make configure attempt to catch broken floating point CFLAGS/defaults
[musl.git] / src / stdlib / strtol.c
blob730bf2d7bd6d7635aa0a189003fb8e8e3f394804
1 #include "stdio_impl.h"
2 #include "intscan.h"
3 #include "shgetc.h"
4 #include <inttypes.h>
5 #include <limits.h>
6 #include <ctype.h>
7 #include "libc.h"
9 static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim)
11 /* FIXME: use a helper function or macro to setup the FILE */
12 FILE f;
13 f.flags = 0;
14 f.buf = f.rpos = (void *)s;
15 if ((size_t)s > (size_t)-1/2)
16 f.rend = (void *)-1;
17 else
18 f.rend = (unsigned char *)s+(size_t)-1/2;
19 f.lock = -1;
20 shlim(&f, 0);
21 unsigned long long y = __intscan(&f, base, 1, lim);
22 if (p) {
23 size_t cnt = shcnt(&f);
24 *p = (char *)s + cnt;
26 return y;
29 unsigned long long strtoull(const char *restrict s, char **restrict p, int base)
31 return strtox(s, p, base, ULLONG_MAX);
34 long long strtoll(const char *restrict s, char **restrict p, int base)
36 return strtox(s, p, base, LLONG_MIN);
39 unsigned long strtoul(const char *restrict s, char **restrict p, int base)
41 return strtox(s, p, base, ULONG_MAX);
44 long strtol(const char *restrict s, char **restrict p, int base)
46 return strtox(s, p, base, 0UL+LONG_MIN);
49 intmax_t strtoimax(const char *restrict s, char **restrict p, int base)
51 return strtoll(s, p, base);
54 uintmax_t strtoumax(const char *restrict s, char **restrict p, int base)
56 return strtoull(s, p, base);
59 weak_alias(strtol, __strtol_internal);
60 weak_alias(strtoul, __strtoul_internal);
61 weak_alias(strtoll, __strtoll_internal);
62 weak_alias(strtoull, __strtoull_internal);
63 weak_alias(strtoimax, __strtoimax_internal);
64 weak_alias(strtoumax, __strtoumax_internal);