From 9494356888f56a1ced112d081e88c9339340b416 Mon Sep 17 00:00:00 2001 From: Simon Choi <13610195+simc@users.noreply.github.com> Date: Sun, 30 Jul 2023 22:40:36 +0200 Subject: [PATCH] wasm32 --- libsqlite3-sys/build.rs | 53 ++++-- .../wasm32-unknown-unknown/include/assert.h | 1 + .../wasm32-unknown-unknown/include/ctype.h | 0 .../wasm32-unknown-unknown/include/math.h | 1 + .../wasm32-unknown-unknown/include/stdio.h | 1 + .../wasm32-unknown-unknown/include/stdlib.h | 9 + .../wasm32-unknown-unknown/include/string.h | 15 ++ .../include/sys/types.h | 0 .../wasm32-unknown-unknown/include/time.h | 0 .../libc/stdlib/qsort.c | 167 ++++++++++++++++++ .../libc/string/strcmp.c | 47 +++++ .../libc/string/strcspn.c | 61 +++++++ .../libc/string/strlen.c | 44 +++++ .../libc/string/strncmp.c | 48 +++++ .../libc/string/strrchr.c | 49 +++++ 15 files changed, 481 insertions(+), 15 deletions(-) create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/assert.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/ctype.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/math.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdio.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdlib.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/string.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/sys/types.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/time.h create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/stdlib/qsort.c create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcmp.c create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcspn.c create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strlen.c create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strncmp.c create mode 100644 libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strrchr.c diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index e3aefad..ae97ba8 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -115,22 +115,14 @@ mod build_bundled { .flag("-DSQLITE_CORE") .flag("-DSQLITE_DEFAULT_FOREIGN_KEYS=1") .flag("-DSQLITE_ENABLE_API_ARMOR") - .flag("-DSQLITE_ENABLE_COLUMN_METADATA") - .flag("-DSQLITE_ENABLE_DBSTAT_VTAB") - .flag("-DSQLITE_ENABLE_FTS3") - .flag("-DSQLITE_ENABLE_FTS3_PARENTHESIS") - .flag("-DSQLITE_ENABLE_FTS5") - .flag("-DSQLITE_ENABLE_JSON1") - .flag("-DSQLITE_ENABLE_LOAD_EXTENSION=1") - .flag("-DSQLITE_ENABLE_MEMORY_MANAGEMENT") - .flag("-DSQLITE_ENABLE_RTREE") - .flag("-DSQLITE_ENABLE_STAT2") - .flag("-DSQLITE_ENABLE_STAT4") - .flag("-DSQLITE_SOUNDEX") .flag("-DSQLITE_THREADSAFE=1") - .flag("-DSQLITE_USE_URI") - .flag("-DHAVE_USLEEP=1") .flag("-D_POSIX_THREAD_SAFE_FUNCTIONS") // cross compile with MinGW + .flag("-DSQLITE_DEFAULT_MEMSTATUS=0") + .flag("-DSQLITE_MAX_EXPR_DEPTH=0") + .flag("-DSQLITE_OMIT_DECLTYPE") + .flag("-DSQLITE_OMIT_DEPRECATED") + .flag("-DSQLITE_OMIT_PROGRESS_CALLBACK") + .flag("-DSQLITE_LIKE_DOESNT_MATCH_BLOBS") .warnings(false); if cfg!(feature = "bundled-sqlcipher") { @@ -234,7 +226,7 @@ mod build_bundled { if vs_has_nan { cfg.flag("-DHAVE_ISNAN"); } - } else { + } else if env::var("TARGET") != Ok("wasm32-unknown-unknown".to_string()) { cfg.flag("-DHAVE_ISNAN"); } if !win_target() { @@ -249,6 +241,37 @@ mod build_bundled { cfg.file("sqlite3/wasm32-wasi-vfs.c"); } } + if env::var("TARGET") == Ok("wasm32-unknown-unknown".to_string()) { + // Apple clang doesn't support wasm32, so use Homebrew clang by default. + if env::var("HOST") == Ok("x86_64-apple-darwin".to_string()) { + if env::var("CC").is_err() { + std::env::set_var("CC", "/usr/local/opt/llvm/bin/clang"); + } + if env::var("AR").is_err() { + std::env::set_var("AR", "/usr/local/opt/llvm/bin/llvm-ar"); + } + } else if env::var("HOST") == Ok("aarch64-apple-darwin".to_string()) { + if env::var("CC").is_err() { + std::env::set_var("CC", "/opt/homebrew/opt/llvm/bin/clang"); + } + if env::var("AR").is_err() { + std::env::set_var("AR", "/opt/homebrew/opt/llvm/bin/llvm-ar"); + } + } + + cfg.flag("-DSQLITE_OS_OTHER") + .flag("-DSQLITE_TEMP_STORE=3") + // https://github.com/rust-lang/rust/issues/74393 + .flag("-DLONGDOUBLE_TYPE=double") + .flag("-DSQLITE_OMIT_LOCALTIME"); + cfg.include("sqlite3/wasm32-unknown-unknown/include"); + cfg.file("sqlite3/wasm32-unknown-unknown/libc/stdlib/qsort.c"); + cfg.file("sqlite3/wasm32-unknown-unknown/libc/string/strcmp.c"); + cfg.file("sqlite3/wasm32-unknown-unknown/libc/string/strcspn.c"); + cfg.file("sqlite3/wasm32-unknown-unknown/libc/string/strlen.c"); + cfg.file("sqlite3/wasm32-unknown-unknown/libc/string/strncmp.c"); + cfg.file("sqlite3/wasm32-unknown-unknown/libc/string/strrchr.c"); + } if cfg!(feature = "unlock_notify") { cfg.flag("-DSQLITE_ENABLE_UNLOCK_NOTIFY"); } diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/assert.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/assert.h new file mode 100644 index 0000000..09eec1d --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/assert.h @@ -0,0 +1 @@ +#define assert(x) (void)0 \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/ctype.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/ctype.h new file mode 100644 index 0000000..e69de29 diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/math.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/math.h new file mode 100644 index 0000000..329fc63 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/math.h @@ -0,0 +1 @@ +double log(double x); \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdio.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdio.h new file mode 100644 index 0000000..3176281 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdio.h @@ -0,0 +1 @@ +#define FILENAME_MAX 4096 \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdlib.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdlib.h new file mode 100644 index 0000000..5daf8b4 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/stdlib.h @@ -0,0 +1,9 @@ +#include + +void *malloc(size_t size); +void free(void *ptr); +void *realloc(void *ptr, size_t size); + +void qsort(void *a, size_t n, size_t es, int (*cmp)(const void *, const void *)); + +#define DEF_STRONG(x) \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/string.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/string.h new file mode 100644 index 0000000..09cb263 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/string.h @@ -0,0 +1,15 @@ +#include + +int strcmp(const char *s1, const char *s2); +size_t strcspn(const char *s1, const char *s2); +size_t strlen(const char *str); +int strncmp(const char *s1, const char *s2, size_t n); +char *strrchr(const char *p, int ch); + +int memcmp(const void *str1, const void *str2, size_t n); +void *memcpy(void *dest, const void *src, size_t n); +void *memmove(void *str1, const void *str2, size_t n); +void *memset(void *str, int c, size_t n); + +#define DEF_STRONG(x) +#define __weak_alias(x, y) \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/sys/types.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/sys/types.h new file mode 100644 index 0000000..e69de29 diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/time.h b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/include/time.h new file mode 100644 index 0000000..e69de29 diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/stdlib/qsort.c b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/stdlib/qsort.c new file mode 100644 index 0000000..89c87cb --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/stdlib/qsort.c @@ -0,0 +1,167 @@ +/*$OpenBSD : qsort.c, v 1.14 2017 / 01 / 04 15 : 20 : 30 millert Exp $ * / +/*- + * Copyright (c) 1992, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +static __inline char *med3(char *, char *, char *, int (*)(const void *, const void *)); +static __inline void swapfunc(char *, char *, size_t, int); + +#define min(a, b) (a) < (b) ? a : b + +/* + * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". + */ +#define swapcode(TYPE, parmi, parmj, n) \ + { \ + size_t i = (n) / sizeof(TYPE); \ + TYPE *pi = (TYPE *)(parmi); \ + TYPE *pj = (TYPE *)(parmj); \ + do \ + { \ + TYPE t = *pi; \ + *pi++ = *pj; \ + *pj++ = t; \ + } while (--i > 0); \ + } + +#define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ + es % sizeof(long) \ + ? 2 \ + : es == sizeof(long) ? 0 \ + : 1; + +static __inline void +swapfunc(char *a, char *b, size_t n, int swaptype) +{ + if (swaptype <= 1) + swapcode(long, a, b, n) else swapcode(char, a, b, n) +} + +#define swap(a, b) \ + if (swaptype == 0) \ + { \ + long t = *(long *)(a); \ + *(long *)(a) = *(long *)(b); \ + *(long *)(b) = t; \ + } \ + else \ + swapfunc(a, b, es, swaptype) + +#define vecswap(a, b, n) \ + if ((n) > 0) \ + swapfunc(a, b, n, swaptype) + +static __inline char * +med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *)) +{ + return cmp(a, b) < 0 ? (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a)) + : (cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c)); +} + +void qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *)) +{ + char *pa, *pb, *pc, *pd, *pl, *pm, *pn; + int cmp_result, swaptype; + size_t d, r; + char *a = aa; + +loop: + SWAPINIT(a, es); + if (n < 7) + { + for (pm = a + es; pm < a + n * es; pm += es) + for (pl = pm; pl > a && cmp(pl - es, pl) > 0; + pl -= es) + swap(pl, pl - es); + return; + } + pm = a + (n / 2) * es; + if (n > 7) + { + pl = a; + pn = a + (n - 1) * es; + if (n > 40) + { + d = (n / 8) * es; + pl = med3(pl, pl + d, pl + 2 * d, cmp); + pm = med3(pm - d, pm, pm + d, cmp); + pn = med3(pn - 2 * d, pn - d, pn, cmp); + } + pm = med3(pl, pm, pn, cmp); + } + swap(a, pm); + pa = pb = a + es; + + pc = pd = a + (n - 1) * es; + for (;;) + { + while (pb <= pc && (cmp_result = cmp(pb, a)) <= 0) + { + if (cmp_result == 0) + { + swap(pa, pb); + pa += es; + } + pb += es; + } + while (pb <= pc && (cmp_result = cmp(pc, a)) >= 0) + { + if (cmp_result == 0) + { + swap(pc, pd); + pd -= es; + } + pc -= es; + } + if (pb > pc) + break; + swap(pb, pc); + pb += es; + pc -= es; + } + + pn = a + n * es; + r = min(pa - a, pb - pa); + vecswap(a, pb - r, r); + r = min(pd - pc, pn - pd - es); + vecswap(pb, pn - r, r); + if ((r = pb - pa) > es) + qsort(a, r / es, es, cmp); + if ((r = pd - pc) > es) + { + /* Iterate rather than recurse to save stack space */ + a = pn - r; + n = r / es; + goto loop; + } + /* qsort(pn - r, r / es, es, cmp);*/ +} +DEF_STRONG(qsort); \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcmp.c b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcmp.c new file mode 100644 index 0000000..5702581 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcmp.c @@ -0,0 +1,47 @@ +/* $OpenBSD: strcmp.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */ + +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/* + * Compare strings. + */ +int strcmp(const char *s1, const char *s2) +{ + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + return (*(unsigned char *)s1 - *(unsigned char *)--s2); +} +DEF_STRONG(strcmp); \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcspn.c b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcspn.c new file mode 100644 index 0000000..3e2d890 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strcspn.c @@ -0,0 +1,61 @@ +/* $OpenBSD: strcspn.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */ +/*- + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +/* + * Span the complement of string s2. + */ +size_t +strcspn(const char *s1, const char *s2) +{ + const char *p, *spanp; + char c, sc; + + /* + * Stop as soon as we find any character from s2. Note that there + * must be a NUL in s2; it suffices to stop when we find that, too. + */ + for (p = s1;;) + { + c = *p++; + spanp = s2; + do + { + if ((sc = *spanp++) == c) + return (p - 1 - s1); + } while (sc != 0); + } + /* NOTREACHED */ +} +DEF_STRONG(strcspn); \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strlen.c b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strlen.c new file mode 100644 index 0000000..ac49fd1 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strlen.c @@ -0,0 +1,44 @@ +/* $OpenBSD: strlen.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */ + +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +size_t +strlen(const char *str) +{ + const char *s; + + for (s = str; *s; ++s) + ; + return (s - str); +} + +DEF_STRONG(strlen); \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strncmp.c b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strncmp.c new file mode 100644 index 0000000..16fc971 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strncmp.c @@ -0,0 +1,48 @@ +/* $OpenBSD: strncmp.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +int strncmp(const char *s1, const char *s2, size_t n) +{ + + if (n == 0) + return (0); + do + { + if (*s1 != *s2++) + return (*(unsigned char *)s1 - *(unsigned char *)--s2); + if (*s1++ == 0) + break; + } while (--n != 0); + return (0); +} +DEF_STRONG(strncmp); \ No newline at end of file diff --git a/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strrchr.c b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strrchr.c new file mode 100644 index 0000000..2593287 --- /dev/null +++ b/libsqlite3-sys/sqlite3/wasm32-unknown-unknown/libc/string/strrchr.c @@ -0,0 +1,49 @@ +/* $OpenBSD: strrchr.c,v 1.4 2018/10/01 06:37:37 martijn Exp $ */ +/* + * Copyright (c) 1988 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include + +__weak_alias(rindex, strrchr); + +char * +strrchr(const char *p, int ch) +{ + char *save; + + for (save = NULL;; ++p) + { + if (*p == (char)ch) + save = (char *)p; + if (!*p) + return (save); + } + /* NOTREACHED */ +} +DEF_STRONG(strrchr); \ No newline at end of file