aboutsummaryrefslogtreecommitdiff
path: root/system/lib
diff options
context:
space:
mode:
Diffstat (limited to 'system/lib')
-rw-r--r--system/lib/compiler-rt/int_endianness.h2
-rw-r--r--system/lib/dlmalloc.c2
-rw-r--r--system/lib/embind/bind.cpp79
-rw-r--r--system/lib/libc.symbols2
-rw-r--r--system/lib/libc/musl/arch/js/atomic.h103
-rw-r--r--system/lib/libc/musl/src/stdlib/atoi.c16
-rw-r--r--system/lib/libc/musl/src/stdlib/atol.c17
-rw-r--r--system/lib/libc/musl/src/stdlib/atoll.c17
-rw-r--r--system/lib/libc/musl/src/stdlib/bsearch.c20
-rw-r--r--system/lib/libc/musl/src/stdlib/qsort.c215
-rw-r--r--system/lib/libc/musl/src/string/bcmp.c7
-rw-r--r--system/lib/libc/musl/src/string/bcopy.c7
-rw-r--r--system/lib/libc/musl/src/string/bzero.c7
-rw-r--r--system/lib/libc/musl/src/string/index.c7
-rw-r--r--system/lib/libc/musl/src/string/memchr.c24
-rw-r--r--system/lib/libc/musl/src/string/rindex.c7
-rw-r--r--system/lib/libc/musl/src/string/stpcpy.c29
-rw-r--r--system/lib/libc/musl/src/string/strchr.c9
-rw-r--r--system/lib/libc/musl/src/string/strcspn.c19
-rw-r--r--system/lib/libc/musl/src/string/strdup.c13
-rw-r--r--system/lib/libc/musl/src/string/strncat.c10
-rw-r--r--system/lib/libc/musl/src/string/strndup.c12
-rw-r--r--system/lib/libc/musl/src/string/strnlen.c7
-rw-r--r--system/lib/libc/musl/src/string/strpbrk.c7
-rw-r--r--system/lib/libc/musl/src/string/strrchr.c8
-rw-r--r--system/lib/libc/musl/src/string/strspn.c20
-rw-r--r--system/lib/libc/musl/src/string/strstr.c156
-rw-r--r--system/lib/libc/musl/src/string/strtok.c13
-rw-r--r--system/lib/libc/musl/src/string/strtok_r.c12
-rw-r--r--system/lib/libcextra.symbols22
30 files changed, 838 insertions, 31 deletions
diff --git a/system/lib/compiler-rt/int_endianness.h b/system/lib/compiler-rt/int_endianness.h
index 17905355..fa294c49 100644
--- a/system/lib/compiler-rt/int_endianness.h
+++ b/system/lib/compiler-rt/int_endianness.h
@@ -100,7 +100,7 @@
#endif /* Windows */
-#if defined(EMSCRIPTEN)
+#if defined(__EMSCRIPTEN__)
#define _YUGA_LITTLE_ENDIAN 1
#define _YUGA_BIG_ENDIAN 0
diff --git a/system/lib/dlmalloc.c b/system/lib/dlmalloc.c
index ce2c25f1..04e9e47b 100644
--- a/system/lib/dlmalloc.c
+++ b/system/lib/dlmalloc.c
@@ -1,6 +1,6 @@
/* XXX Emscripten XXX */
-#if EMSCRIPTEN
+#if __EMSCRIPTEN__
#define DLMALLOC_EXPORT __attribute__((__weak__, __visibility__("default")))
/* mmap uses malloc, so malloc can't use mmap */
#define HAVE_MMAP 0
diff --git a/system/lib/embind/bind.cpp b/system/lib/embind/bind.cpp
index 12264dfd..37918050 100644
--- a/system/lib/embind/bind.cpp
+++ b/system/lib/embind/bind.cpp
@@ -8,31 +8,52 @@
#include <algorithm>
#include <emscripten/emscripten.h>
#include <climits>
+#include <limits>
using namespace emscripten;
extern "C" {
const char* __attribute__((used)) __getTypeName(const std::type_info* ti) {
+ if (has_unbound_type_names) {
#ifdef USE_CXA_DEMANGLE
- int stat;
- char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat);
- if (stat == 0 && demangled) {
- return demangled;
- }
+ int stat;
+ char* demangled = abi::__cxa_demangle(ti->name(), NULL, NULL, &stat);
+ if (stat == 0 && demangled) {
+ return demangled;
+ }
- switch (stat) {
- case -1:
- return strdup("<allocation failure>");
- case -2:
- return strdup("<invalid C++ symbol>");
- case -3:
- return strdup("<invalid argument>");
- default:
- return strdup("<unknown error>");
- }
+ switch (stat) {
+ case -1:
+ return strdup("<allocation failure>");
+ case -2:
+ return strdup("<invalid C++ symbol>");
+ case -3:
+ return strdup("<invalid argument>");
+ default:
+ return strdup("<unknown error>");
+ }
#else
- return strdup(ti->name());
+ return strdup(ti->name());
#endif
+ } else {
+ char str[80];
+ sprintf(str, "%p", ti);
+ return strdup(str);
+ }
+ }
+}
+
+namespace {
+ template<typename T>
+ static void register_integer(const char* name) {
+ using namespace internal;
+ _embind_register_integer(TypeID<T>::get(), name, sizeof(T), std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
+ }
+
+ template<typename T>
+ static void register_float(const char* name) {
+ using namespace internal;
+ _embind_register_float(TypeID<T>::get(), name, sizeof(T));
}
}
@@ -41,20 +62,20 @@ EMSCRIPTEN_BINDINGS(native_and_builtin_types) {
_embind_register_void(TypeID<void>::get(), "void");
- _embind_register_bool(TypeID<bool>::get(), "bool", true, false);
-
- _embind_register_integer(TypeID<char>::get(), "char", CHAR_MIN, CHAR_MAX);
- _embind_register_integer(TypeID<signed char>::get(), "signed char", SCHAR_MIN, SCHAR_MAX);
- _embind_register_integer(TypeID<unsigned char>::get(), "unsigned char", 0, UCHAR_MAX);
- _embind_register_integer(TypeID<signed short>::get(), "short", SHRT_MIN, SHRT_MAX);
- _embind_register_integer(TypeID<unsigned short>::get(), "unsigned short", 0, USHRT_MAX);
- _embind_register_integer(TypeID<signed int>::get(), "int", INT_MIN, INT_MAX);
- _embind_register_integer(TypeID<unsigned int>::get(), "unsigned int", 0, UINT_MAX);
- _embind_register_integer(TypeID<signed long>::get(), "long", LONG_MIN, LONG_MAX);
- _embind_register_integer(TypeID<unsigned long>::get(), "unsigned long", 0, ULONG_MAX);
+ _embind_register_bool(TypeID<bool>::get(), "bool", sizeof(bool), true, false);
+
+ register_integer<char>("char");
+ register_integer<signed char>("signed char");
+ register_integer<unsigned char>("unsigned char");
+ register_integer<signed short>("short");
+ register_integer<unsigned short>("unsigned short");
+ register_integer<signed int>("int");
+ register_integer<unsigned int>("unsigned int");
+ register_integer<signed long>("long");
+ register_integer<unsigned long>("unsigned long");
- _embind_register_float(TypeID<float>::get(), "float");
- _embind_register_float(TypeID<double>::get(), "double");
+ register_float<float>("float");
+ register_float<double>("double");
_embind_register_std_string(TypeID<std::string>::get(), "std::string");
_embind_register_std_wstring(TypeID<std::wstring>::get(), sizeof(wchar_t), "std::wstring");
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/arch/js/atomic.h b/system/lib/libc/musl/arch/js/atomic.h
new file mode 100644
index 00000000..07d5d4b6
--- /dev/null
+++ b/system/lib/libc/musl/arch/js/atomic.h
@@ -0,0 +1,103 @@
+#ifndef _INTERNAL_ATOMIC_H
+#define _INTERNAL_ATOMIC_H
+
+#include <stdint.h>
+
+static inline int a_ctz_l(unsigned long x)
+{
+ if (x == 0)
+ return 32;
+ int nTrailingZeros = 0;
+ while(!(x&1))
+ {
+ ++nTrailingZeros;
+ x >>= 1;
+ }
+ return nTrailingZeros;
+}
+
+static inline int a_ctz_64(uint64_t x)
+{
+ uint32_t lo = (uint32_t)x;
+ if (lo == 0)
+ return a_ctz_l((unsigned long)(x >> 32)) + 32;
+ else
+ return a_ctz_l((unsigned long)lo);
+}
+
+static inline void a_and_64(volatile uint64_t *p, uint64_t v)
+{
+ *p &= v;
+}
+
+static inline void a_or_64(volatile uint64_t *p, uint64_t v)
+{
+ *p |= v;
+}
+
+static inline void a_store_l(volatile void *p, long x)
+{
+ *(long*)p = x;
+}
+
+static inline void a_or_l(volatile void *p, long v)
+{
+ *(long*)p |= v;
+}
+
+static inline void *a_cas_p(volatile void *p, void *t, void *s)
+{
+ if (*(long*)p == t)
+ *(long*)p = s;
+ return t;
+}
+
+static inline long a_cas_l(volatile void *p, long t, long s)
+{
+ if (*(long*)p == t)
+ *(long*)p = s;
+ return t;
+}
+
+static inline int a_cas(volatile int *p, int t, int s)
+{
+ if (*p == t)
+ *p = s;
+ return t;
+}
+
+static inline void a_or(volatile void *p, int v)
+{
+ *(int*)p |= v;
+}
+
+static inline void a_and(volatile void *p, int v)
+{
+ *(int*)p &= v;
+}
+
+static inline void a_inc(volatile int *x)
+{
+ ++*x;
+}
+
+static inline void a_dec(volatile int *x)
+{
+ --*x;
+}
+
+static inline void a_store(volatile int *p, int x)
+{
+ *p = x;
+}
+
+static inline void a_spin()
+{
+}
+
+static inline void a_crash()
+{
+}
+
+
+#endif
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/libc/musl/src/stdlib/bsearch.c b/system/lib/libc/musl/src/stdlib/bsearch.c
new file mode 100644
index 00000000..61d89367
--- /dev/null
+++ b/system/lib/libc/musl/src/stdlib/bsearch.c
@@ -0,0 +1,20 @@
+#include <stdlib.h>
+
+void *bsearch(const void *key, const void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *))
+{
+ void *try;
+ int sign;
+ while (nel > 0) {
+ try = (char *)base + width*(nel/2);
+ sign = cmp(key, try);
+ if (!sign) return try;
+ else if (nel == 1) break;
+ else if (sign < 0)
+ nel /= 2;
+ else {
+ base = try;
+ nel -= nel/2;
+ }
+ }
+ return NULL;
+}
diff --git a/system/lib/libc/musl/src/stdlib/qsort.c b/system/lib/libc/musl/src/stdlib/qsort.c
new file mode 100644
index 00000000..434d9350
--- /dev/null
+++ b/system/lib/libc/musl/src/stdlib/qsort.c
@@ -0,0 +1,215 @@
+/* Copyright (C) 2011 by Valentin Ochs
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+/* Minor changes by Rich Felker for integration in musl, 2011-04-27. */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "atomic.h"
+#define ntz(x) a_ctz_l((x))
+
+typedef int (*cmpfun)(const void *, const void *);
+
+static inline int pntz(size_t p[2]) {
+ int r = ntz(p[0] - 1);
+ if(r != 0 || (r = 8*sizeof(size_t) + ntz(p[1])) != 8*sizeof(size_t)) {
+ return r;
+ }
+ return 0;
+}
+
+static void cycle(size_t width, unsigned char* ar[], int n)
+{
+ unsigned char tmp[256];
+ size_t l;
+ int i;
+
+ if(n < 2) {
+ return;
+ }
+
+ ar[n] = tmp;
+ while(width) {
+ l = sizeof(tmp) < width ? sizeof(tmp) : width;
+ memcpy(ar[n], ar[0], l);
+ for(i = 0; i < n; i++) {
+ memcpy(ar[i], ar[i + 1], l);
+ ar[i] += l;
+ }
+ width -= l;
+ }
+}
+
+/* shl() and shr() need n > 0 */
+static inline void shl(size_t p[2], int n)
+{
+ if(n >= 8 * sizeof(size_t)) {
+ n -= 8 * sizeof(size_t);
+ p[1] = p[0];
+ p[0] = 0;
+ }
+ p[1] <<= n;
+ p[1] |= p[0] >> (sizeof(size_t) * 8 - n);
+ p[0] <<= n;
+}
+
+static inline void shr(size_t p[2], int n)
+{
+ if(n >= 8 * sizeof(size_t)) {
+ n -= 8 * sizeof(size_t);
+ p[0] = p[1];
+ p[1] = 0;
+ }
+ p[0] >>= n;
+ p[0] |= p[1] << (sizeof(size_t) * 8 - n);
+ p[1] >>= n;
+}
+
+static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[])
+{
+ unsigned char *rt, *lf;
+ unsigned char *ar[14 * sizeof(size_t) + 1];
+ int i = 1;
+
+ ar[0] = head;
+ while(pshift > 1) {
+ rt = head - width;
+ lf = head - width - lp[pshift - 2];
+
+ if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) {
+ break;
+ }
+ if((*cmp)(lf, rt) >= 0) {
+ ar[i++] = lf;
+ head = lf;
+ pshift -= 1;
+ } else {
+ ar[i++] = rt;
+ head = rt;
+ pshift -= 2;
+ }
+ }
+ cycle(width, ar, i);
+}
+
+static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[])
+{
+ unsigned char *stepson,
+ *rt, *lf;
+ size_t p[2];
+ unsigned char *ar[14 * sizeof(size_t) + 1];
+ int i = 1;
+ int trail;
+
+ p[0] = pp[0];
+ p[1] = pp[1];
+
+ ar[0] = head;
+ while(p[0] != 1 || p[1] != 0) {
+ stepson = head - lp[pshift];
+ if((*cmp)(stepson, ar[0]) <= 0) {
+ break;
+ }
+ if(!trusty && pshift > 1) {
+ rt = head - width;
+ lf = head - width - lp[pshift - 2];
+ if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) {
+ break;
+ }
+ }
+
+ ar[i++] = stepson;
+ head = stepson;
+ trail = pntz(p);
+ shr(p, trail);
+ pshift += trail;
+ trusty = 0;
+ }
+ if(!trusty) {
+ cycle(width, ar, i);
+ sift(head, width, cmp, pshift, lp);
+ }
+}
+
+void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
+{
+ size_t lp[12*sizeof(size_t)];
+ size_t i, size = width * nel;
+ unsigned char *head, *high;
+ size_t p[2] = {1, 0};
+ int pshift = 1;
+ int trail;
+
+ if (!size) return;
+
+ head = base;
+ high = head + size - width;
+
+ /* Precompute Leonardo numbers, scaled by element width */
+ for(lp[0]=lp[1]=width, i=2; (lp[i]=lp[i-2]+lp[i-1]+width) < size; i++);
+
+ while(head < high) {
+ if((p[0] & 3) == 3) {
+ sift(head, width, cmp, pshift, lp);
+ shr(p, 2);
+ pshift += 2;
+ } else {
+ if(lp[pshift - 1] >= high - head) {
+ trinkle(head, width, cmp, p, pshift, 0, lp);
+ } else {
+ sift(head, width, cmp, pshift, lp);
+ }
+
+ if(pshift == 1) {
+ shl(p, 1);
+ pshift = 0;
+ } else {
+ shl(p, pshift - 1);
+ pshift = 1;
+ }
+ }
+
+ p[0] |= 1;
+ head += width;
+ }
+
+ trinkle(head, width, cmp, p, pshift, 0, lp);
+
+ while(pshift != 1 || p[0] != 1 || p[1] != 0) {
+ if(pshift <= 1) {
+ trail = pntz(p);
+ shr(p, trail);
+ pshift += trail;
+ } else {
+ shl(p, 2);
+ pshift -= 2;
+ p[0] ^= 7;
+ shr(p, 1);
+ trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp);
+ shl(p, 1);
+ p[0] |= 1;
+ trinkle(head - width, width, cmp, p, pshift, 1, lp);
+ }
+ head -= width;
+ }
+}
diff --git a/system/lib/libc/musl/src/string/bcmp.c b/system/lib/libc/musl/src/string/bcmp.c
new file mode 100644
index 00000000..5d6a388b
--- /dev/null
+++ b/system/lib/libc/musl/src/string/bcmp.c
@@ -0,0 +1,7 @@
+#include <string.h>
+#include <strings.h>
+
+int bcmp(const void *s1, const void *s2, size_t n)
+{
+ return memcmp(s1, s2, n);
+}
diff --git a/system/lib/libc/musl/src/string/bcopy.c b/system/lib/libc/musl/src/string/bcopy.c
new file mode 100644
index 00000000..e76272fc
--- /dev/null
+++ b/system/lib/libc/musl/src/string/bcopy.c
@@ -0,0 +1,7 @@
+#include <string.h>
+#include <strings.h>
+
+void bcopy(const void *s1, void *s2, size_t n)
+{
+ memmove(s2, s1, n);
+}
diff --git a/system/lib/libc/musl/src/string/bzero.c b/system/lib/libc/musl/src/string/bzero.c
new file mode 100644
index 00000000..0f98b4a5
--- /dev/null
+++ b/system/lib/libc/musl/src/string/bzero.c
@@ -0,0 +1,7 @@
+#include <string.h>
+#include <strings.h>
+
+void bzero(void *s, size_t n)
+{
+ memset(s, 0, n);
+}
diff --git a/system/lib/libc/musl/src/string/index.c b/system/lib/libc/musl/src/string/index.c
new file mode 100644
index 00000000..dd611251
--- /dev/null
+++ b/system/lib/libc/musl/src/string/index.c
@@ -0,0 +1,7 @@
+#include <string.h>
+#include <strings.h>
+
+char *index(const char *s, int c)
+{
+ return strchr(s, c);
+}
diff --git a/system/lib/libc/musl/src/string/memchr.c b/system/lib/libc/musl/src/string/memchr.c
new file mode 100644
index 00000000..a0472f78
--- /dev/null
+++ b/system/lib/libc/musl/src/string/memchr.c
@@ -0,0 +1,24 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <limits.h>
+
+#define SS (sizeof(size_t))
+#define ALIGN (sizeof(size_t)-1)
+#define ONES ((size_t)-1/UCHAR_MAX)
+#define HIGHS (ONES * (UCHAR_MAX/2+1))
+#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
+
+void *memchr(const void *src, int c, size_t n)
+{
+ const unsigned char *s = src;
+ c = (unsigned char)c;
+ for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
+ if (n && *s != c) {
+ const size_t *w;
+ size_t k = ONES * c;
+ for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
+ for (s = (const void *)w; n && *s != c; s++, n--);
+ }
+ return n ? (void *)s : 0;
+}
diff --git a/system/lib/libc/musl/src/string/rindex.c b/system/lib/libc/musl/src/string/rindex.c
new file mode 100644
index 00000000..17df2bf2
--- /dev/null
+++ b/system/lib/libc/musl/src/string/rindex.c
@@ -0,0 +1,7 @@
+#include <string.h>
+#include <strings.h>
+
+char *rindex(const char *s, int c)
+{
+ return strrchr(s, c);
+}
diff --git a/system/lib/libc/musl/src/string/stpcpy.c b/system/lib/libc/musl/src/string/stpcpy.c
new file mode 100644
index 00000000..feb9eb81
--- /dev/null
+++ b/system/lib/libc/musl/src/string/stpcpy.c
@@ -0,0 +1,29 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <limits.h>
+#include "libc.h"
+
+#define ALIGN (sizeof(size_t))
+#define ONES ((size_t)-1/UCHAR_MAX)
+#define HIGHS (ONES * (UCHAR_MAX/2+1))
+#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
+
+char *__stpcpy(char *restrict d, const char *restrict s)
+{
+ size_t *wd;
+ const size_t *ws;
+
+ if ((uintptr_t)s % ALIGN == (uintptr_t)d % ALIGN) {
+ for (; (uintptr_t)s % ALIGN; s++, d++)
+ if (!(*d=*s)) return d;
+ wd=(void *)d; ws=(const void *)s;
+ for (; !HASZERO(*ws); *wd++ = *ws++);
+ d=(void *)wd; s=(const void *)ws;
+ }
+ for (; (*d=*s); s++, d++);
+
+ return d;
+}
+
+weak_alias(__stpcpy, stpcpy);
diff --git a/system/lib/libc/musl/src/string/strchr.c b/system/lib/libc/musl/src/string/strchr.c
new file mode 100644
index 00000000..bfae8f9f
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strchr.c
@@ -0,0 +1,9 @@
+#include <string.h>
+
+char *__strchrnul(const char *, int);
+
+char *strchr(const char *s, int c)
+{
+ char *r = __strchrnul(s, c);
+ return *(unsigned char *)r == (unsigned char)c ? r : 0;
+}
diff --git a/system/lib/libc/musl/src/string/strcspn.c b/system/lib/libc/musl/src/string/strcspn.c
new file mode 100644
index 00000000..cfdba114
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strcspn.c
@@ -0,0 +1,19 @@
+#include <string.h>
+
+#define BITOP(a,b,op) \
+ ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
+
+char *__strchrnul(const char *, int);
+
+size_t strcspn(const char *s, const char *c)
+{
+ const char *a = s;
+ size_t byteset[32/sizeof(size_t)];
+
+ if (!c[0] || !c[1]) return __strchrnul(s, *c)-a;
+
+ memset(byteset, 0, sizeof byteset);
+ for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
+ for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++);
+ return s-a;
+}
diff --git a/system/lib/libc/musl/src/string/strdup.c b/system/lib/libc/musl/src/string/strdup.c
new file mode 100644
index 00000000..dd5f80c1
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strdup.c
@@ -0,0 +1,13 @@
+#include <stdlib.h>
+#include <string.h>
+#include "libc.h"
+
+char *__strdup(const char *s)
+{
+ size_t l = strlen(s);
+ char *d = malloc(l+1);
+ if (!d) return NULL;
+ return memcpy(d, s, l+1);
+}
+
+weak_alias(__strdup, strdup);
diff --git a/system/lib/libc/musl/src/string/strncat.c b/system/lib/libc/musl/src/string/strncat.c
new file mode 100644
index 00000000..01ca2a23
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strncat.c
@@ -0,0 +1,10 @@
+#include <string.h>
+
+char *strncat(char *restrict d, const char *restrict s, size_t n)
+{
+ char *a = d;
+ d += strlen(d);
+ while (n && *s) n--, *d++ = *s++;
+ *d++ = 0;
+ return a;
+}
diff --git a/system/lib/libc/musl/src/string/strndup.c b/system/lib/libc/musl/src/string/strndup.c
new file mode 100644
index 00000000..617d27ba
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strndup.c
@@ -0,0 +1,12 @@
+#include <stdlib.h>
+#include <string.h>
+
+char *strndup(const char *s, size_t n)
+{
+ size_t l = strnlen(s, n);
+ char *d = malloc(l+1);
+ if (!d) return NULL;
+ memcpy(d, s, l);
+ d[l] = 0;
+ return d;
+}
diff --git a/system/lib/libc/musl/src/string/strnlen.c b/system/lib/libc/musl/src/string/strnlen.c
new file mode 100644
index 00000000..6442eb79
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strnlen.c
@@ -0,0 +1,7 @@
+#include <string.h>
+
+size_t strnlen(const char *s, size_t n)
+{
+ const char *p = memchr(s, 0, n);
+ return p ? p-s : n;
+}
diff --git a/system/lib/libc/musl/src/string/strpbrk.c b/system/lib/libc/musl/src/string/strpbrk.c
new file mode 100644
index 00000000..55947c64
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strpbrk.c
@@ -0,0 +1,7 @@
+#include <string.h>
+
+char *strpbrk(const char *s, const char *b)
+{
+ s += strcspn(s, b);
+ return *s ? (char *)s : 0;
+}
diff --git a/system/lib/libc/musl/src/string/strrchr.c b/system/lib/libc/musl/src/string/strrchr.c
new file mode 100644
index 00000000..635fb3c1
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strrchr.c
@@ -0,0 +1,8 @@
+#include <string.h>
+
+void *__memrchr(const void *, int, size_t);
+
+char *strrchr(const char *s, int c)
+{
+ return __memrchr(s, c, strlen(s) + 1);
+}
diff --git a/system/lib/libc/musl/src/string/strspn.c b/system/lib/libc/musl/src/string/strspn.c
new file mode 100644
index 00000000..9543dad0
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strspn.c
@@ -0,0 +1,20 @@
+#include <string.h>
+
+#define BITOP(a,b,op) \
+ ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
+
+size_t strspn(const char *s, const char *c)
+{
+ const char *a = s;
+ size_t byteset[32/sizeof(size_t)] = { 0 };
+
+ if (!c[0]) return 0;
+ if (!c[1]) {
+ for (; *s == *c; s++);
+ return s-a;
+ }
+
+ for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
+ for (; *s && BITOP(byteset, *(unsigned char *)s, &); s++);
+ return s-a;
+}
diff --git a/system/lib/libc/musl/src/string/strstr.c b/system/lib/libc/musl/src/string/strstr.c
new file mode 100644
index 00000000..06491748
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strstr.c
@@ -0,0 +1,156 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+static char *twobyte_strstr(const unsigned char *h, const unsigned ch