diff options
author | dzwdz | 2022-08-29 13:57:47 +0200 |
---|---|---|
committer | dzwdz | 2022-08-29 13:58:02 +0200 |
commit | 4ae57a7fb13e68c5e6f1c1246a867555dbd986db (patch) | |
tree | 3bee7f7eee21e9f2ed3b9f07dd1671a1c230cf66 /src/user/lib/string.c | |
parent | edb7fc07bf93e4a1883cccf45ad7a4b2cbf390d9 (diff) |
user/lua: implement the bare minimum for it to link and "run"
Diffstat (limited to 'src/user/lib/string.c')
-rw-r--r-- | src/user/lib/string.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/user/lib/string.c b/src/user/lib/string.c index 8424574..386cffa 100644 --- a/src/user/lib/string.c +++ b/src/user/lib/string.c @@ -47,6 +47,12 @@ long strtol(const char *restrict s, char **restrict end, int base) { return res * sign; } +#include <user/lib/panic.h> +double strtod(const char *restrict s, char **restrict end) { + (void)s; (void)end; + __libc_panic("unimplemented"); +} + char *strchr(const char *s, int c) { for (; *s; s++) { if (*s == c) return (char*)s; @@ -66,6 +72,13 @@ size_t strcspn(const char *s, const char *reject) { return l; } +char *strpbrk(const char *s1, const char *s2) { + for (; *s1; s1++) { + if (strchr(s2, *s1)) return (char*)s1; + } + return NULL; +} + char *strtok(char *restrict s, const char *restrict sep) { static char *state; return strtok_r(s, sep, &state); @@ -95,3 +108,28 @@ int strncmp(const char *s1, const char *s2, size_t n) { if (*s1 < *s2) return -1; else return 1; } + +int strcoll(const char *s1, const char *s2) { + return strcmp(s1, s2); +} + +// TODO implement strstr using Boyer-Moore +char *strstr(const char *s1, const char *s2) { + size_t l1 = strlen(s1), l2 = strlen(s2); + for (; l2 <= l1; s1++, l1--) { + if (memcmp(s1, s2, l2) == 0) return (char*)s1; + } + return NULL; +} + +char *strcpy(char *restrict s1, const char *restrict s2) { + char *ret = s1; + while (*s2) *s1++ = *s2++; + return ret; +} + +// TODO strerror mapping +char *strerror(int errnum) { + (void)errnum; + return "unknown error"; +} |