diff --git a/sqlite3/libc/math.h b/sqlite3/libc/math.h index 8e8100d..ec2f12d 100644 --- a/sqlite3/libc/math.h +++ b/sqlite3/libc/math.h @@ -1,10 +1,10 @@ +#include_next // the system math.h + #ifndef _WASM_SIMD128_MATH_H #define _WASM_SIMD128_MATH_H #include -#include_next // the system math.h - #ifdef __cplusplus extern "C" { #endif diff --git a/sqlite3/libc/stdlib.h b/sqlite3/libc/stdlib.h index 7ac8177..36378c5 100644 --- a/sqlite3/libc/stdlib.h +++ b/sqlite3/libc/stdlib.h @@ -1,8 +1,8 @@ +#include_next // the system stdlib.h + #ifndef _WASM_SIMD128_STDLIB_H #define _WASM_SIMD128_STDLIB_H -#include_next // the system stdlib.h - #ifdef __cplusplus extern "C" { #endif diff --git a/sqlite3/libc/string.h b/sqlite3/libc/string.h index 494d6bb..67a3a83 100644 --- a/sqlite3/libc/string.h +++ b/sqlite3/libc/string.h @@ -1,3 +1,5 @@ +#include_next // the system string.h + #ifndef _WASM_SIMD128_STRING_H #define _WASM_SIMD128_STRING_H @@ -5,8 +7,6 @@ #include #include <__macro_PAGESIZE.h> -#include_next // the system string.h - #ifdef __cplusplus extern "C" { #endif @@ -657,6 +657,7 @@ char *strstr(const char *haystk, const char *needle) { // Simple wrappers already in musl: // - mempcpy // - strcat +// - strlcat // - strdup // - strndup // - strnlen @@ -666,7 +667,6 @@ char *strstr(const char *haystk, const char *needle) { __attribute__((weak)) void *memccpy(void *__restrict dest, const void *__restrict src, int c, size_t n) { - void *memchr(const void *v, int c, size_t n); const void *m = memchr(src, c, n); if (m != NULL) { n = (char *)m - (char *)src + 1; @@ -676,6 +676,17 @@ void *memccpy(void *__restrict dest, const void *__restrict src, int c, size_t n return (void *)m; } +__attribute__((weak)) +size_t strlcpy(char *__restrict dest, const char *__restrict src, size_t n) { + size_t slen = strlen(src); + if (n--) { + if (n > slen) n = slen; + memcpy(dest, src, n); + dest[n] = 0; + } + return slen; +} + __attribute__((weak)) char *strncat(char *__restrict dest, const char *__restrict src, size_t n) { size_t strnlen(const char *s, size_t n); diff --git a/sqlite3/libc/strings.h b/sqlite3/libc/strings.h index 80d82fa..0e00d58 100644 --- a/sqlite3/libc/strings.h +++ b/sqlite3/libc/strings.h @@ -1,3 +1,5 @@ +#include_next // the system strings.h + #ifndef _WASM_SIMD128_STRINGS_H #define _WASM_SIMD128_STRINGS_H @@ -7,8 +9,6 @@ #include #include <__macro_PAGESIZE.h> -#include_next // the system strings.h - #ifdef __cplusplus extern "C" { #endif @@ -20,7 +20,7 @@ int bcmp(const void *v1, const void *v2, size_t n) { return __memcmpeq(v1, v2, n); } -v128_t __tolower8x16(v128_t v) { +static v128_t __tolower8x16(v128_t v) { __i8x16 i; i = v + wasm_i8x16_splat(INT8_MAX - ('Z')); i = i > wasm_i8x16_splat(INT8_MAX - ('Z' - 'A' + 1)); diff --git a/sqlite3/strcasecmp.patch b/sqlite3/strcasecmp.patch new file mode 100644 index 0000000..d24d078 --- /dev/null +++ b/sqlite3/strcasecmp.patch @@ -0,0 +1,41 @@ +# Use strcasecmp and strncasecmp. +--- sqlite3.c.orig ++++ sqlite3.c +@@ -35685,35 +35685,15 @@ + return sqlite3StrICmp(zLeft, zRight); + } + SQLITE_PRIVATE int sqlite3StrICmp(const char *zLeft, const char *zRight){ +- unsigned char *a, *b; +- int c, x; +- a = (unsigned char *)zLeft; +- b = (unsigned char *)zRight; +- for(;;){ +- c = *a; +- x = *b; +- if( c==x ){ +- if( c==0 ) break; +- }else{ +- c = (int)UpperToLower[c] - (int)UpperToLower[x]; +- if( c ) break; +- } +- a++; +- b++; +- } +- return c; ++ return strcasecmp(zLeft, zRight); + } + SQLITE_API int sqlite3_strnicmp(const char *zLeft, const char *zRight, int N){ +- register unsigned char *a, *b; + if( zLeft==0 ){ + return zRight ? -1 : 0; + }else if( zRight==0 ){ + return 1; + } +- a = (unsigned char *)zLeft; +- b = (unsigned char *)zRight; +- while( N-- > 0 && *a!=0 && UpperToLower[*a]==UpperToLower[*b]){ a++; b++; } +- return N<0 ? 0 : UpperToLower[*a] - UpperToLower[*b]; ++ return strncasecmp(zLeft, zRight, N); + } + + /*