diff options
-rw-r--r-- | src/library.js | 11 | ||||
-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 | ||||
-rw-r--r-- | tools/system_libs.py | 3 |
7 files changed, 56 insertions, 11 deletions
diff --git a/src/library.js b/src/library.js index 2ff395c4..ebfac476 100644 --- a/src/library.js +++ b/src/library.js @@ -3238,17 +3238,6 @@ LibraryManager.library = { return _strtoull(str, endptr, base); // no locale support yet }, - atoi__deps: ['strtol'], - atoi: function(ptr) { - return _strtol(ptr, null, 10); - }, - atol: 'atoi', - - atoll__deps: ['strtoll'], - atoll: function(ptr) { - return _strtoll(ptr, null, 10); - }, - qsort__deps: ['malloc', 'memcpy', 'free'], qsort: function(base, num, size, cmp) { if (num == 0 || size == 0) return; 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 diff --git a/tools/system_libs.py b/tools/system_libs.py index d37872a4..b75aecd9 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -71,6 +71,8 @@ def calculate(temp_files, in_temp, stdout, stderr): ]], ['stdlib', [ 'atof.c', + 'atoi.c', + 'atol.c', 'strtod.c', ]], ['string', [ @@ -221,6 +223,7 @@ def calculate(temp_files, in_temp, stdout, stderr): 'fputws.c', ]], ['stdlib', [ + 'atoll.c', 'bsearch.c', 'ecvt.c', 'fcvt.c', |