diff options
| author | Ada Christine <adachristine18@gmail.com> | 2024-02-11 23:48:04 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2024-02-11 23:48:04 +0000 |
| commit | 3f9278b48ff4bc0d2cf1604034b3bba548572f04 (patch) | |
| tree | dbdabed3ff580079d2e21045d2cbc5b274c2e418 /lib/string.c | |
| parent | 9fbfc6e951e565ef98c49c1dcfc4b6a39514f17d (diff) | |
kjarna initial impl
Diffstat (limited to 'lib/string.c')
| -rw-r--r-- | lib/string.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/lib/string.c b/lib/string.c index f6bc682..315fa1e 100644 --- a/lib/string.c +++ b/lib/string.c @@ -1,15 +1,46 @@ -#include <lib/kstring.h> +#include <libc/string.h> #include <stdbool.h> size_t strlen(const char *s) { size_t l = 0; - while (*s++) l++; + while (s != nullptr && *s++) l++; return l; } +size_t wcslen(const wchar_t *s) +{ + size_t l = 0; + + while (s != nullptr && *s++) l++; + + return l; +} + +size_t mbstowcs(wchar_t *dst, const char *src, size_t len) +{ + if (dst == nullptr || src == nullptr) + { + return -1; + } + + size_t i; + + for (i = 0; i < len; i++) + { + if ((dst[i] = src[i]) == 0) + { + break; + } + } + + dst[i] = L'\0'; + + return i; +} + static long long valueof(int c, int base) { long long result = 0; @@ -28,9 +59,7 @@ static long long valueof(int c, int base) } // check if value is an uppercase ASCII alphabetical character - else if ( - (c >= 'A' && c <= 'Z') || - (c >= 'a' && c <= 'z')) + else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { // mask in uppercase bit c |= 0x20; |
