diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/lib/libc.symbols | 2 | ||||
-rw-r--r-- | system/lib/libc/musl/src/stdlib/atoi.c | 16 | ||||
-rw-r--r-- | system/lib/libc/musl/src/stdlib/atol.c | 17 | ||||
-rw-r--r-- | system/lib/libc/musl/src/stdlib/atoll.c | 17 | ||||
-rw-r--r-- | system/lib/libcextra.symbols | 1 |
5 files changed, 53 insertions, 0 deletions
diff --git a/system/lib/libc.symbols b/system/lib/libc.symbols index 53a27082..eb2053ce 100644 --- a/system/lib/libc.symbols +++ b/system/lib/libc.symbols @@ -50,6 +50,8 @@ T __towrite T __uflow T atof + T atoi + T atol W bulk_free W calloc W free diff --git a/system/lib/libc/musl/src/stdlib/atoi.c b/system/lib/libc/musl/src/stdlib/atoi.c new file mode 100644 index 00000000..9baca7b8 --- /dev/null +++ b/system/lib/libc/musl/src/stdlib/atoi.c @@ -0,0 +1,16 @@ +#include <stdlib.h> +#include <ctype.h> + +int atoi(const char *s) +{ + int n=0, neg=0; + while (isspace(*s)) s++; + switch (*s) { + case '-': neg=1; + case '+': s++; + } + /* Compute n as a negative number to avoid overflow on INT_MIN */ + while (isdigit(*s)) + n = 10*n - (*s++ - '0'); + return neg ? n : -n; +} diff --git a/system/lib/libc/musl/src/stdlib/atol.c b/system/lib/libc/musl/src/stdlib/atol.c new file mode 100644 index 00000000..140ea3ea --- /dev/null +++ b/system/lib/libc/musl/src/stdlib/atol.c @@ -0,0 +1,17 @@ +#include <stdlib.h> +#include <ctype.h> + +long atol(const char *s) +{ + long n=0; + int neg=0; + while (isspace(*s)) s++; + switch (*s) { + case '-': neg=1; + case '+': s++; + } + /* Compute n as a negative number to avoid overflow on LONG_MIN */ + while (isdigit(*s)) + n = 10*n - (*s++ - '0'); + return neg ? n : -n; +} diff --git a/system/lib/libc/musl/src/stdlib/atoll.c b/system/lib/libc/musl/src/stdlib/atoll.c new file mode 100644 index 00000000..b6930489 --- /dev/null +++ b/system/lib/libc/musl/src/stdlib/atoll.c @@ -0,0 +1,17 @@ +#include <stdlib.h> +#include <ctype.h> + +long long atoll(const char *s) +{ + long long n=0; + int neg=0; + while (isspace(*s)) s++; + switch (*s) { + case '-': neg=1; + case '+': s++; + } + /* Compute n as a negative number to avoid overflow on LLONG_MIN */ + while (isdigit(*s)) + n = 10*n - (*s++ - '0'); + return neg ? n : -n; +} diff --git a/system/lib/libcextra.symbols b/system/lib/libcextra.symbols index 096b261d..4018b3e2 100644 --- a/system/lib/libcextra.symbols +++ b/system/lib/libcextra.symbols @@ -22,6 +22,7 @@ T __wcscoll_l T __wcsxfrm_l W __wctype_l + T atoll T bsearch T btowc T ecvt |