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
strtox(const char *s, char **p, int base, unsigned long long lim)8 static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim)
9 {
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;
17 }
18 return y;
19 }
20
strtoull(const char *restrict s, char **restrict p, int base)21 unsigned long long strtoull(const char *restrict s, char **restrict p, int base)
22 {
23 return strtox(s, p, base, ULLONG_MAX);
24 }
25
strtoll(const char *restrict s, char **restrict p, int base)26 long long strtoll(const char *restrict s, char **restrict p, int base)
27 {
28 return strtox(s, p, base, LLONG_MIN);
29 }
30
31 #ifndef __LITEOS__
strtoul_weak(const char *restrict s, char **restrict p, int base)32 unsigned long strtoul_weak(const char *restrict s, char **restrict p, int base)
33 #else
34 unsigned long strtoul(const char *restrict s, char **restrict p, int base)
35 #endif
36 {
37 return strtox(s, p, base, ULONG_MAX);
38 }
39
strtol(const char *restrict s, char **restrict p, int base)40 long strtol(const char *restrict s, char **restrict p, int base)
41 {
42 return strtox(s, p, base, 0UL+LONG_MIN);
43 }
44
45 #ifndef __LITEOS__
strtoimax_weak(const char *restrict s, char **restrict p, int base)46 intmax_t strtoimax_weak(const char *restrict s, char **restrict p, int base)
47 #else
48 intmax_t strtoimax(const char *restrict s, char **restrict p, int base)
49 #endif
50 {
51 return strtoll(s, p, base);
52 }
53
54 #ifndef __LITEOS__
strtoumax_weak(const char *restrict s, char **restrict p, int base)55 uintmax_t strtoumax_weak(const char *restrict s, char **restrict p, int base)
56 #else
57 uintmax_t strtoumax(const char *restrict s, char **restrict p, int base)
58 #endif
59 {
60 return strtoull(s, p, base);
61 }
62
63 weak_alias(strtol, __strtol_internal);
64 #ifndef __LITEOS__
65 weak_alias(strtoul_weak, strtoul);
66 #endif
67 weak_alias(strtoul, __strtoul_internal);
68 weak_alias(strtoll, __strtoll_internal);
69 weak_alias(strtoull, __strtoull_internal);
70 #ifndef __LITEOS__
71 weak_alias(strtoimax_weak, strtoimax);
72 weak_alias(strtoumax_weak, strtoumax);
73 #endif
74 weak_alias(strtoimax, __strtoimax_internal);
75 weak_alias(strtoumax, __strtoumax_internal);
76