aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-04-07 17:39:39 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-04-07 17:39:39 -0700
commitd93fd8156ba2530d5ff12caaf9b0eaf557f60de5 (patch)
tree1f14dcda503ae7ad02be897b0c458abbf699a92a
parentd19741ee04ee2c87af48c22902afdc06c22f4aac (diff)
parenta04fd2a2c6110b5c7f65c1d993a582fb12e505e4 (diff)
Merge pull request #2256 from juj/more_musl1.14.1
More musl.
-rw-r--r--emscripten-version.txt2
-rw-r--r--src/library.js291
-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
-rw-r--r--tests/core/test_strndup.out2
-rw-r--r--tests/test_core.py3
-rw-r--r--tools/system_libs.py28
32 files changed, 817 insertions, 295 deletions
diff --git a/emscripten-version.txt b/emscripten-version.txt
index 29b950e7..3166fbaa 100644
--- a/emscripten-version.txt
+++ b/emscripten-version.txt
@@ -1,2 +1,2 @@
-1.14.0
+1.14.1
diff --git a/src/library.js b/src/library.js
index e0d8c5b7..6c2bfa36 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3038,34 +3038,6 @@ LibraryManager.library = {
Module['abort']();
},
- bsearch: function(key, base, num, size, compar) {
- function cmp(x, y) {
-#if ASM_JS
- return Module['dynCall_iii'](compar, x, y);
-#else
- return FUNCTION_TABLE[compar](x, y);
-#endif
- };
- var left = 0;
- var right = num;
- var mid, test, addr;
-
- while (left < right) {
- mid = (left + right) >>> 1;
- addr = base + (mid * size);
- test = cmp(key, addr);
- if (test < 0) {
- right = mid;
- } else if (test > 0) {
- left = mid + 1;
- } else {
- return addr;
- }
- }
-
- return 0;
- },
-
realloc__deps: ['malloc', 'memcpy', 'free'],
realloc: function(ptr, size) {
// Very simple, inefficient implementation - if you use a real malloc, best to use
@@ -3269,41 +3241,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;
- // forward calls to the JavaScript sort method
- // first, sort the items logically
- var keys = [];
- for (var i = 0; i < num; i++) keys.push(i);
- keys.sort(function(a, b) {
-#if ASM_JS
- return Module['dynCall_iii'](cmp, base+a*size, base+b*size);
-#else
- return FUNCTION_TABLE[cmp](base+a*size, base+b*size);
-#endif
- });
- // apply the sort
- var temp = _malloc(num*size);
- _memcpy(temp, base, num*size);
- for (var i = 0; i < num; i++) {
- if (keys[i] == i) continue; // already in place
- _memcpy(base+i*size, temp+keys[i]*size, size);
- }
- _free(temp);
- },
-
environ: 'allocate(1, "i32*", ALLOC_STATIC)',
__environ__deps: ['environ'],
__environ: '_environ',
@@ -3507,8 +3444,6 @@ LibraryManager.library = {
// string.h
// ==========================================================================
- // FIXME: memcpy, memmove and memset should all return their destination pointers.
-
memcpy__inline: function(dest, src, num, align) {
var ret = '';
#if ASSERTIONS
@@ -3590,13 +3525,6 @@ LibraryManager.library = {
llvm_memmove_p0i8_p0i8_i32: 'memmove',
llvm_memmove_p0i8_p0i8_i64: 'memmove',
- bcopy__deps: ['memmove'],
- bcopy: function(src, dest, num) {
- // void bcopy(const void *s1, void *s2, size_t n);
- // http://pubs.opengroup.org/onlinepubs/009695399/functions/bcopy.html
- _memmove(dest, src, num);
- },
-
memset__inline: function(ptr, value, num, align) {
return makeSetValues(ptr, 0, value, 'null', num, align);
},
@@ -3651,38 +3579,6 @@ LibraryManager.library = {
return (curr - ptr)|0;
},
- strspn: function(pstr, pset) {
- var str = pstr, set, strcurr, setcurr;
- while (1) {
- strcurr = {{{ makeGetValue('str', '0', 'i8') }}};
- if (!strcurr) return str - pstr;
- set = pset;
- while (1) {
- setcurr = {{{ makeGetValue('set', '0', 'i8') }}};
- if (!setcurr || setcurr == strcurr) break;
- set++;
- }
- if (!setcurr) return str - pstr;
- str++;
- }
- },
-
- strcspn: function(pstr, pset) {
- var str = pstr, set, strcurr, setcurr;
- while (1) {
- strcurr = {{{ makeGetValue('str', '0', 'i8') }}};
- if (!strcurr) return str - pstr;
- set = pset;
- while (1) {
- setcurr = {{{ makeGetValue('set', '0', 'i8') }}};
- if (!setcurr || setcurr == strcurr) break;
- set++;
- }
- if (setcurr) return str - pstr;
- str++;
- }
- },
-
strcpy__asm: true,
strcpy__sig: 'iii',
strcpy: function(pdest, psrc) {
@@ -3695,15 +3591,6 @@ LibraryManager.library = {
return pdest|0;
},
- stpcpy: function(pdest, psrc) {
- var i = 0;
- do {
- {{{ makeCopyValues('pdest+i', 'psrc+i', 1, 'i8', null, 1) }}};
- i ++;
- } while ({{{ makeGetValue('psrc', 'i-1', 'i8') }}} != 0);
- return pdest + i - 1;
- },
-
strncpy__asm: true,
strncpy__sig: 'iiii',
strncpy: function(pdest, psrc, num) {
@@ -3755,184 +3642,6 @@ LibraryManager.library = {
return pdest|0;
},
- strncat__deps: ['strlen'],
- strncat: function(pdest, psrc, num) {
- var len = _strlen(pdest);
- var i = 0;
- while(1) {
- {{{ makeCopyValues('pdest+len+i', 'psrc+i', 1, 'i8', null, 1) }}};
- if ({{{ makeGetValue('pdest', 'len+i', 'i8') }}} == 0) break;
- i ++;
- if (i == num) {
- {{{ makeSetValue('pdest', 'len+i', 0, 'i8') }}};
- break;
- }
- }
- return pdest;
- },
-
- memchr: function(ptr, chr, num) {
- chr = unSign(chr);
- for (var i = 0; i < num; i++) {
- if ({{{ makeGetValue('ptr', 0, 'i8') }}} == chr) return ptr;
- ptr++;
- }
- return 0;
- },
-
- strnlen: function(ptr, num) {
- num = num >>> 0;
- for (var i = 0; i < num; i++) {
- if ({{{ makeGetValue('ptr', 0, 'i8') }}} == 0) return i;
- ptr++;
- }
- return num;
- },
-
- strstr: function(ptr1, ptr2) {
- var check = 0, start;
- do {
- if (!check) {
- start = ptr1;
- check = ptr2;
- }
- var curr1 = {{{ makeGetValue('ptr1++', 0, 'i8') }}};
- var curr2 = {{{ makeGetValue('check++', 0, 'i8') }}};
- if (curr2 == 0) return start;
- if (curr2 != curr1) {
- // rewind to one character after start, to find ez in eeez
- ptr1 = start + 1;
- check = 0;
- }
- } while (curr1);
- return 0;
- },
-
- strchr: function(ptr, chr) {
- ptr--;
- do {
- ptr++;
- var val = {{{ makeGetValue('ptr', 0, 'i8') }}};
- if (val == chr) return ptr;
- } while (val);
- return 0;
- },
- index: 'strchr',
-
- strrchr__deps: ['strlen'],
- strrchr: function(ptr, chr) {
- var ptr2 = ptr + _strlen(ptr);
- do {
- if ({{{ makeGetValue('ptr2', 0, 'i8') }}} == chr) return ptr2;
- ptr2--;
- } while (ptr2 >= ptr);
- return 0;
- },
- rindex: 'strrchr',
-
- strdup__deps: ['strlen', 'malloc'],
- strdup: function(ptr) {
- var len = _strlen(ptr);
- var newStr = _malloc(len + 1);
- {{{ makeCopyValues('newStr', 'ptr', 'len', 'null', null, 1) }}};
- {{{ makeSetValue('newStr', 'len', '0', 'i8') }}};
- return newStr;
- },
-
- strndup__deps: ['strdup', 'strlen', 'malloc'],
- strndup: function(ptr, size) {
- var len = _strlen(ptr);
-
- if (size >= len) {
- return _strdup(ptr);
- }
-
- if (size < 0) {
- size = 0;
- }
-
- var newStr = _malloc(size + 1);
- {{{ makeCopyValues('newStr', 'ptr', 'size', 'null', null, 1) }}};
- {{{ makeSetValue('newStr', 'size', '0', 'i8') }}};
- return newStr;
- },
-
- strpbrk: function(ptr1, ptr2) {
- var curr;
- var searchSet = {};
- while (1) {
- var curr = {{{ makeGetValue('ptr2++', 0, 'i8') }}};
- if (!curr) break;
- searchSet[curr] = 1;
- }
- while (1) {
- curr = {{{ makeGetValue('ptr1', 0, 'i8') }}};
- if (!curr) break;
- if (curr in searchSet) return ptr1;
- ptr1++;
- }
- return 0;
- },
-
- __strtok_state: 0,
- strtok__deps: ['__strtok_state', 'strtok_r'],
- strtok__postset: '___strtok_state = Runtime.staticAlloc(4);',
- strtok: function(s, delim) {
- return _strtok_r(s, delim, ___strtok_state);
- },
-
- // Translated from newlib; for the original source and licensing, see library_strtok_r.c
- strtok_r: function(s, delim, lasts) {
- var skip_leading_delim = 1;
- var spanp;
- var c, sc;
- var tok;
-
-
- if (s == 0 && (s = getValue(lasts, 'i8*')) == 0) {
- return 0;
- }
-
- cont: while (1) {
- c = getValue(s++, 'i8');
- for (spanp = delim; (sc = getValue(spanp++, 'i8')) != 0;) {
- if (c == sc) {
- if (skip_leading_delim) {
- continue cont;
- } else {
- setValue(lasts, s, 'i8*');
- setValue(s - 1, 0, 'i8');
- return s - 1;
- }
- }
- }
- break;
- }
-
- if (c == 0) {
- setValue(lasts, 0, 'i8*');
- return 0;
- }
- tok = s - 1;
-
- for (;;) {
- c = getValue(s++, 'i8');
- spanp = delim;
- do {
- if ((sc = getValue(spanp++, 'i8')) == c) {
- if (c == 0) {
- s = 0;
- } else {
- setValue(s - 1, 0, 'i8');
- }
- setValue(lasts, s, 'i8*');
- return tok;
- }
- } while (sc != 0);
- }
- abort('strtok_r error!');
- },
-
strerror_r__deps: ['$ERRNO_CODES', '$ERRNO_MESSAGES', '__setErrNo'],
strerror_r: function(errnum, strerrbuf, buflen) {
if (errnum in ERRNO_MESSAGES) {
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>
+