diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-05-20 16:01:13 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-05-20 16:01:13 -0700 |
commit | ca9cf0d99e3fe7eb13d34bc36281afe326ffebfa (patch) | |
tree | 1491f5d4fbf3d630e3af61f82b3eeff346118ed5 /system | |
parent | 447f96296b661b1a0ab6f1fd0a0dad495d97c823 (diff) | |
parent | 492b230a84c5cd39585d6c06edeb2bca7709abaa (diff) |
Merge pull request #2369 from juj/musl_charfuncs
Musl charfuncs
Diffstat (limited to 'system')
37 files changed, 333 insertions, 1 deletions
diff --git a/system/lib/libc.symbols b/system/lib/libc.symbols index eb2053ce..d889d509 100644 --- a/system/lib/libc.symbols +++ b/system/lib/libc.symbols @@ -40,6 +40,7 @@ W _Znwj W _ZnwjRKSt9nothrow_t T __floatscan + T __intscan T __overflow T __shgetc T __shlim @@ -57,6 +58,9 @@ W free W independent_calloc W independent_comalloc + T isdigit + T isspace + T isupper W mallinfo W malloc W malloc_footprint @@ -77,6 +81,12 @@ T memcmp T memcpy T strtod + T strtoull + T strtoll + T strtoul + T strtol + T strtoimax + T strtoumax T strcoll T __strcoll_l W strcoll_l @@ -89,4 +99,5 @@ T strtof_l T strtold T strtold_l + T tolower W valloc diff --git a/system/lib/libc/musl/src/compat/readme.txt b/system/lib/libc/musl/src/compat/readme.txt new file mode 100644 index 00000000..c96c6136 --- /dev/null +++ b/system/lib/libc/musl/src/compat/readme.txt @@ -0,0 +1,2 @@ +Files in this directory are not strictly standard musl libc, but implemented here for compatibility for Emscripten purposes. + diff --git a/system/lib/libc/musl/src/compat/strlwr.c b/system/lib/libc/musl/src/compat/strlwr.c new file mode 100644 index 00000000..90d6c106 --- /dev/null +++ b/system/lib/libc/musl/src/compat/strlwr.c @@ -0,0 +1,10 @@ +#include <ctype.h> + +void strlwr(char *str) +{ + while(*str) + { + *str = tolower(*str); + ++str; + } +} diff --git a/system/lib/libc/musl/src/compat/strtol_l.c b/system/lib/libc/musl/src/compat/strtol_l.c new file mode 100644 index 00000000..58b46186 --- /dev/null +++ b/system/lib/libc/musl/src/compat/strtol_l.c @@ -0,0 +1,22 @@ +#include <stdlib.h> +#include <ctype.h> + +unsigned long long strtoull_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtoull(s, p, base); +} + +long long strtoll_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtoll(s, p, base); +} + +unsigned long strtoul_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtoul(s, p, base); +} + +long strtol_l(const char *restrict s, char **restrict p, int base, locale_t loc) +{ + return strtol(s, p, base); +} diff --git a/system/lib/libc/musl/src/compat/strupr.c b/system/lib/libc/musl/src/compat/strupr.c new file mode 100644 index 00000000..2b1d97bb --- /dev/null +++ b/system/lib/libc/musl/src/compat/strupr.c @@ -0,0 +1,10 @@ +#include <ctype.h> + +void strupr(char *str) +{ + while(*str) + { + *str = toupper(*str); + ++str; + } +} diff --git a/system/lib/libc/musl/src/ctype/isalnum.c b/system/lib/libc/musl/src/ctype/isalnum.c new file mode 100644 index 00000000..e3d2cf0b --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isalnum.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isalnum(int c) +{ + return isalpha(c) || isdigit(c); +} diff --git a/system/lib/libc/musl/src/ctype/isalpha.c b/system/lib/libc/musl/src/ctype/isalpha.c new file mode 100644 index 00000000..53e115c2 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isalpha.c @@ -0,0 +1,7 @@ +#include <ctype.h> +#undef isalpha + +int isalpha(int c) +{ + return ((unsigned)c|32)-'a' < 26; +} diff --git a/system/lib/libc/musl/src/ctype/isascii.c b/system/lib/libc/musl/src/ctype/isascii.c new file mode 100644 index 00000000..3af0a10d --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isascii.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isascii(int c) +{ + return !(c&~0x7f); +} diff --git a/system/lib/libc/musl/src/ctype/isblank.c b/system/lib/libc/musl/src/ctype/isblank.c new file mode 100644 index 00000000..957400b2 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isblank.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isblank(int c) +{ + return (c == ' ' || c == '\t'); +} diff --git a/system/lib/libc/musl/src/ctype/iscntrl.c b/system/lib/libc/musl/src/ctype/iscntrl.c new file mode 100644 index 00000000..92ed7f0e --- /dev/null +++ b/system/lib/libc/musl/src/ctype/iscntrl.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int iscntrl(int c) +{ + return (unsigned)c < 0x20 || c == 0x7f; +} diff --git a/system/lib/libc/musl/src/ctype/isdigit.c b/system/lib/libc/musl/src/ctype/isdigit.c new file mode 100644 index 00000000..0bc82a6d --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isdigit.c @@ -0,0 +1,7 @@ +#include <ctype.h> +#undef isdigit + +int isdigit(int c) +{ + return (unsigned)c-'0' < 10; +} diff --git a/system/lib/libc/musl/src/ctype/isgraph.c b/system/lib/libc/musl/src/ctype/isgraph.c new file mode 100644 index 00000000..98979d1e --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isgraph.c @@ -0,0 +1,4 @@ +int isgraph(int c) +{ + return (unsigned)c-0x21 < 0x5e; +} diff --git a/system/lib/libc/musl/src/ctype/islower.c b/system/lib/libc/musl/src/ctype/islower.c new file mode 100644 index 00000000..d72fb212 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/islower.c @@ -0,0 +1,7 @@ +#include <ctype.h> +#undef islower + +int islower(int c) +{ + return (unsigned)c-'a' < 26; +} diff --git a/system/lib/libc/musl/src/ctype/isprint.c b/system/lib/libc/musl/src/ctype/isprint.c new file mode 100644 index 00000000..504e66ed --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isprint.c @@ -0,0 +1,4 @@ +int isprint(int c) +{ + return (unsigned)c-0x20 < 0x5f; +} diff --git a/system/lib/libc/musl/src/ctype/ispunct.c b/system/lib/libc/musl/src/ctype/ispunct.c new file mode 100644 index 00000000..fc455352 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/ispunct.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int ispunct(int c) +{ + return isgraph(c) && !isalnum(c); +} diff --git a/system/lib/libc/musl/src/ctype/isspace.c b/system/lib/libc/musl/src/ctype/isspace.c new file mode 100644 index 00000000..8e535aa1 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isspace.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isspace(int c) +{ + return c == ' ' || (unsigned)c-'\t' < 5; +} diff --git a/system/lib/libc/musl/src/ctype/isupper.c b/system/lib/libc/musl/src/ctype/isupper.c new file mode 100644 index 00000000..f09d88c5 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isupper.c @@ -0,0 +1,7 @@ +#include <ctype.h> +#undef isupper + +int isupper(int c) +{ + return (unsigned)c-'A' < 26; +} diff --git a/system/lib/libc/musl/src/ctype/isxdigit.c b/system/lib/libc/musl/src/ctype/isxdigit.c new file mode 100644 index 00000000..ae68a3dc --- /dev/null +++ b/system/lib/libc/musl/src/ctype/isxdigit.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isxdigit(int c) +{ + return isdigit(c) || ((unsigned)c|32)-'a' < 6; +} diff --git a/system/lib/libc/musl/src/ctype/toascii.c b/system/lib/libc/musl/src/ctype/toascii.c new file mode 100644 index 00000000..f0e48e8e --- /dev/null +++ b/system/lib/libc/musl/src/ctype/toascii.c @@ -0,0 +1,7 @@ +#include <ctype.h> + +/* nonsense function that should NEVER be used! */ +int toascii(int c) +{ + return c & 0x7f; +} diff --git a/system/lib/libc/musl/src/ctype/tolower.c b/system/lib/libc/musl/src/ctype/tolower.c new file mode 100644 index 00000000..b56f3c50 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/tolower.c @@ -0,0 +1,7 @@ +#include <ctype.h> + +int tolower(int c) +{ + if (isupper(c)) return c | 32; + return c; +} diff --git a/system/lib/libc/musl/src/ctype/toupper.c b/system/lib/libc/musl/src/ctype/toupper.c new file mode 100644 index 00000000..1799f030 --- /dev/null +++ b/system/lib/libc/musl/src/ctype/toupper.c @@ -0,0 +1,7 @@ +#include <ctype.h> + +int toupper(int c) +{ + if (islower(c)) return c & 0x5f; + return c; +} diff --git a/system/lib/libc/musl/src/locale/isalnum_l.c b/system/lib/libc/musl/src/locale/isalnum_l.c new file mode 100644 index 00000000..b8a6eef3 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isalnum_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isalnum_l(int c, locale_t l) +{ + return isalnum(c); +} diff --git a/system/lib/libc/musl/src/locale/isalpha_l.c b/system/lib/libc/musl/src/locale/isalpha_l.c new file mode 100644 index 00000000..2e1205c6 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isalpha_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isalpha_l(int c, locale_t l) +{ + return isalpha(c); +} diff --git a/system/lib/libc/musl/src/locale/isblank_l.c b/system/lib/libc/musl/src/locale/isblank_l.c new file mode 100644 index 00000000..27479aa1 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isblank_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isblank_l(int c, locale_t l) +{ + return isblank(c); +} diff --git a/system/lib/libc/musl/src/locale/iscntrl_l.c b/system/lib/libc/musl/src/locale/iscntrl_l.c new file mode 100644 index 00000000..ca596fa9 --- /dev/null +++ b/system/lib/libc/musl/src/locale/iscntrl_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int iscntrl_l(int c, locale_t l) +{ + return iscntrl(c); +} diff --git a/system/lib/libc/musl/src/locale/isdigit_l.c b/system/lib/libc/musl/src/locale/isdigit_l.c new file mode 100644 index 00000000..c8ae7bd3 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isdigit_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isdigit_l(int c, locale_t l) +{ + return isdigit(c); +} diff --git a/system/lib/libc/musl/src/locale/isgraph_l.c b/system/lib/libc/musl/src/locale/isgraph_l.c new file mode 100644 index 00000000..713a86e6 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isgraph_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isgraph_l(int c, locale_t l) +{ + return isgraph(c); +} diff --git a/system/lib/libc/musl/src/locale/islower_l.c b/system/lib/libc/musl/src/locale/islower_l.c new file mode 100644 index 00000000..25ec97a1 --- /dev/null +++ b/system/lib/libc/musl/src/locale/islower_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int islower_l(int c, locale_t l) +{ + return islower(c); +} diff --git a/system/lib/libc/musl/src/locale/isprint_l.c b/system/lib/libc/musl/src/locale/isprint_l.c new file mode 100644 index 00000000..79ef3514 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isprint_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isprint_l(int c, locale_t l) +{ + return isprint(c); +} diff --git a/system/lib/libc/musl/src/locale/ispunct_l.c b/system/lib/libc/musl/src/locale/ispunct_l.c new file mode 100644 index 00000000..1c0bd046 --- /dev/null +++ b/system/lib/libc/musl/src/locale/ispunct_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int ispunct_l(int c, locale_t l) +{ + return ispunct(c); +} diff --git a/system/lib/libc/musl/src/locale/isspace_l.c b/system/lib/libc/musl/src/locale/isspace_l.c new file mode 100644 index 00000000..e1a0efed --- /dev/null +++ b/system/lib/libc/musl/src/locale/isspace_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isspace_l(int c, locale_t l) +{ + return isspace(c); +} diff --git a/system/lib/libc/musl/src/locale/isupper_l.c b/system/lib/libc/musl/src/locale/isupper_l.c new file mode 100644 index 00000000..11ba7036 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isupper_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isupper_l(int c, locale_t l) +{ + return isupper(c); +} diff --git a/system/lib/libc/musl/src/locale/isxdigit_l.c b/system/lib/libc/musl/src/locale/isxdigit_l.c new file mode 100644 index 00000000..68649d09 --- /dev/null +++ b/system/lib/libc/musl/src/locale/isxdigit_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int isxdigit_l(int c, locale_t l) +{ + return isxdigit(c); +} diff --git a/system/lib/libc/musl/src/locale/tolower_l.c b/system/lib/libc/musl/src/locale/tolower_l.c new file mode 100644 index 00000000..ba277919 --- /dev/null +++ b/system/lib/libc/musl/src/locale/tolower_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int tolower_l(int c, locale_t l) +{ + return tolower(c); +} diff --git a/system/lib/libc/musl/src/locale/toupper_l.c b/system/lib/libc/musl/src/locale/toupper_l.c new file mode 100644 index 00000000..73f2f39b --- /dev/null +++ b/system/lib/libc/musl/src/locale/toupper_l.c @@ -0,0 +1,6 @@ +#include <ctype.h> + +int toupper_l(int c, locale_t l) +{ + return toupper(c); +} diff --git a/system/lib/libc/musl/src/stdlib/strtol.c b/system/lib/libc/musl/src/stdlib/strtol.c new file mode 100644 index 00000000..730bf2d7 --- /dev/null +++ b/system/lib/libc/musl/src/stdlib/strtol.c @@ -0,0 +1,64 @@ +#include "stdio_impl.h" +#include "intscan.h" +#include "shgetc.h" +#include <inttypes.h> +#include <limits.h> +#include <ctype.h> +#include "libc.h" + +static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim) +{ + /* FIXME: use a helper function or macro to setup the FILE */ + FILE f; + f.flags = 0; + f.buf = f.rpos = (void *)s; + if ((size_t)s > (size_t)-1/2) + f.rend = (void *)-1; + else + f.rend = (unsigned char *)s+(size_t)-1/2; + f.lock = -1; + shlim(&f, 0); + unsigned long long y = __intscan(&f, base, 1, lim); + if (p) { + size_t cnt = shcnt(&f); + *p = (char *)s + cnt; + } + return y; +} + +unsigned long long strtoull(const char *restrict s, char **restrict p, int base) +{ + return strtox(s, p, base, ULLONG_MAX); +} + +long long strtoll(const char *restrict s, char **restrict p, int base) +{ + return strtox(s, p, base, LLONG_MIN); +} + +unsigned long strtoul(const char *restrict s, char **restrict p, int base) +{ + return strtox(s, p, base, ULONG_MAX); +} + +long strtol(const char *restrict s, char **restrict p, int base) +{ + return strtox(s, p, base, 0UL+LONG_MIN); +} + +intmax_t strtoimax(const char *restrict s, char **restrict p, int base) +{ + return strtoll(s, p, base); +} + +uintmax_t strtoumax(const char *restrict s, char **restrict p, int base) +{ + return strtoull(s, p, base); +} + +weak_alias(strtol, __strtol_internal); +weak_alias(strtoul, __strtoul_internal); +weak_alias(strtoll, __strtoll_internal); +weak_alias(strtoull, __strtoull_internal); +weak_alias(strtoimax, __strtoimax_internal); +weak_alias(strtoumax, __strtoumax_internal); diff --git a/system/lib/libcextra.symbols b/system/lib/libcextra.symbols index 64ba670a..17e524e6 100644 --- a/system/lib/libcextra.symbols +++ b/system/lib/libcextra.symbols @@ -1,7 +1,6 @@ T __cos T __cosdf T __fputwc_unlocked - T __intscan W __iswctype_l T __lgamma_r T __lgammaf_r @@ -46,6 +45,27 @@ T ilogbf T ilogbl T index + T isascii + T islower + T islower_l + T isupper_l + T isalpha + T isalpha_l + T isblank_l + T isdigit_l + T isxdigit + T isxdigit_l + T isalnum + T isalnum_l + T ispunct + T ispunct_l + T isspace_l + T iscntrl + T iscntrl_l + T isprint + T isprint_l + T isgraph + T isgraph_l T iswalnum T iswalnum_l T iswalpha @@ -122,6 +142,7 @@ T strfmon_l T strlcat T strlcpy + T strlwr T strncasecmp_l T strncat T strndup @@ -133,6 +154,11 @@ T strstr T strtok T strtok_r + T strtoull_l + T strtoll_l + T strtoul_l + T strtol_l + T strupr T strverscmp T strxfrm W strxfrm_l @@ -140,6 +166,10 @@ T tgamma T tgammaf T tgammal + T toascii + T toupper + T toupper_l + T tolower_l T towctrans T towctrans_l T towlower |