move msghdr and cmsghdr out of bits/socket.h
[musl.git] / src / stdlib / strtol.c
blobbfefea69d1c4f8cd8d4abb3dfa7c323f7d3c646f
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>
8 static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim)
10 FILE f;
11 sh_fromstring(&f, s);
12 shlim(&f, 0);
13 unsigned long long y = __intscan(&f, base, 1, lim);
14 if (p) {
15 size_t cnt = shcnt(&f);
16 *p = (char *)s + cnt;
18 return y;
21 unsigned long long strtoull(const char *restrict s, char **restrict p, int base)
23 return strtox(s, p, base, ULLONG_MAX);
26 long long strtoll(const char *restrict s, char **restrict p, int base)
28 return strtox(s, p, base, LLONG_MIN);
31 unsigned long strtoul(const char *restrict s, char **restrict p, int base)
33 return strtox(s, p, base, ULONG_MAX);
36 long strtol(const char *restrict s, char **restrict p, int base)
38 return strtox(s, p, base, 0UL+LONG_MIN);
41 intmax_t strtoimax(const char *restrict s, char **restrict p, int base)
43 return strtoll(s, p, base);
46 uintmax_t strtoumax(const char *restrict s, char **restrict p, int base)
48 return strtoull(s, p, base);
51 weak_alias(strtol, __strtol_internal);
52 weak_alias(strtoul, __strtoul_internal);
53 weak_alias(strtoll, __strtoll_internal);
54 weak_alias(strtoull, __strtoull_internal);
55 weak_alias(strtoimax, __strtoimax_internal);
56 weak_alias(strtoumax, __strtoumax_internal);