| OLD | NEW |
| 1 #include "stdio_impl.h" | 1 #include "stdio_impl.h" |
| 2 #include "intscan.h" | 2 #include "intscan.h" |
| 3 #include "shgetc.h" | 3 #include "shgetc.h" |
| 4 #include <inttypes.h> | 4 #include <inttypes.h> |
| 5 #include <limits.h> | 5 #include <limits.h> |
| 6 #include <ctype.h> | 6 #include <ctype.h> |
| 7 #include "libc.h" | 7 #include "libc.h" |
| 8 | 8 |
| 9 static unsigned long long strtox(const char *s, char **p, int base, unsigned lon
g long lim) | 9 static unsigned long long strtox(const char* s, |
| 10 { | 10 char** p, |
| 11 » /* FIXME: use a helper function or macro to setup the FILE */ | 11 int base, |
| 12 » FILE f; | 12 unsigned long long lim) { |
| 13 » f.flags = 0; | 13 /* FIXME: use a helper function or macro to setup the FILE */ |
| 14 » f.buf = f.rpos = (void *)s; | 14 FILE f; |
| 15 » if ((size_t)s > (size_t)-1/2) | 15 f.flags = 0; |
| 16 » » f.rend = (void *)-1; | 16 f.buf = f.rpos = (void*)s; |
| 17 » else | 17 if ((size_t)s > (size_t)-1 / 2) |
| 18 » » f.rend = (unsigned char *)s+(size_t)-1/2; | 18 f.rend = (void*)-1; |
| 19 » f.lock = -1; | 19 else |
| 20 » shlim(&f, 0); | 20 f.rend = (unsigned char*)s + (size_t)-1 / 2; |
| 21 » unsigned long long y = __intscan(&f, base, 1, lim); | 21 f.lock = -1; |
| 22 » if (p) { | 22 shlim(&f, 0); |
| 23 » » size_t cnt = shcnt(&f); | 23 unsigned long long y = __intscan(&f, base, 1, lim); |
| 24 » » *p = (char *)s + cnt; | 24 if (p) { |
| 25 » } | 25 size_t cnt = shcnt(&f); |
| 26 » return y; | 26 *p = (char*)s + cnt; |
| 27 } |
| 28 return y; |
| 27 } | 29 } |
| 28 | 30 |
| 29 unsigned long long strtoull(const char *restrict s, char **restrict p, int base) | 31 unsigned long long strtoull(const char* restrict s, |
| 30 { | 32 char** restrict p, |
| 31 » return strtox(s, p, base, ULLONG_MAX); | 33 int base) { |
| 34 return strtox(s, p, base, ULLONG_MAX); |
| 32 } | 35 } |
| 33 | 36 |
| 34 long long strtoll(const char *restrict s, char **restrict p, int base) | 37 long long strtoll(const char* restrict s, char** restrict p, int base) { |
| 35 { | 38 return strtox(s, p, base, LLONG_MIN); |
| 36 » return strtox(s, p, base, LLONG_MIN); | |
| 37 } | 39 } |
| 38 | 40 |
| 39 unsigned long strtoul(const char *restrict s, char **restrict p, int base) | 41 unsigned long strtoul(const char* restrict s, char** restrict p, int base) { |
| 40 { | 42 return strtox(s, p, base, ULONG_MAX); |
| 41 » return strtox(s, p, base, ULONG_MAX); | |
| 42 } | 43 } |
| 43 | 44 |
| 44 long strtol(const char *restrict s, char **restrict p, int base) | 45 long strtol(const char* restrict s, char** restrict p, int base) { |
| 45 { | 46 return strtox(s, p, base, 0UL + LONG_MIN); |
| 46 » return strtox(s, p, base, 0UL+LONG_MIN); | |
| 47 } | 47 } |
| 48 | 48 |
| 49 intmax_t strtoimax(const char *restrict s, char **restrict p, int base) | 49 intmax_t strtoimax(const char* restrict s, char** restrict p, int base) { |
| 50 { | 50 return strtoll(s, p, base); |
| 51 » return strtoll(s, p, base); | |
| 52 } | 51 } |
| 53 | 52 |
| 54 uintmax_t strtoumax(const char *restrict s, char **restrict p, int base) | 53 uintmax_t strtoumax(const char* restrict s, char** restrict p, int base) { |
| 55 { | 54 return strtoull(s, p, base); |
| 56 » return strtoull(s, p, base); | |
| 57 } | 55 } |
| 58 | 56 |
| 59 weak_alias(strtol, __strtol_internal); | 57 weak_alias(strtol, __strtol_internal); |
| 60 weak_alias(strtoul, __strtoul_internal); | 58 weak_alias(strtoul, __strtoul_internal); |
| 61 weak_alias(strtoll, __strtoll_internal); | 59 weak_alias(strtoll, __strtoll_internal); |
| 62 weak_alias(strtoull, __strtoull_internal); | 60 weak_alias(strtoull, __strtoull_internal); |
| 63 weak_alias(strtoimax, __strtoimax_internal); | 61 weak_alias(strtoimax, __strtoimax_internal); |
| 64 weak_alias(strtoumax, __strtoumax_internal); | 62 weak_alias(strtoumax, __strtoumax_internal); |
| OLD | NEW |