diff options
-rw-r--r-- | Libraries/LibC/Makefile | 3 | ||||
-rw-r--r-- | Libraries/LibC/stdlib.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibC/stdlib.h | 2 | ||||
-rw-r--r-- | Libraries/LibC/wchar.cpp | 40 | ||||
-rw-r--r-- | Libraries/LibC/wchar.h | 5 |
5 files changed, 59 insertions, 1 deletions
diff --git a/Libraries/LibC/Makefile b/Libraries/LibC/Makefile index 7541f10136..fb115390e3 100644 --- a/Libraries/LibC/Makefile +++ b/Libraries/LibC/Makefile @@ -52,7 +52,8 @@ LIBC_OBJS = \ netdb.o \ sched.o \ dlfcn.o \ - libgen.o + libgen.o \ + wchar.o ASM_OBJS = setjmp.ao crti.ao crtn.ao diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index 342029ce1e..dcccaa27fd 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -385,6 +385,16 @@ size_t mbstowcs(wchar_t*, const char*, size_t) ASSERT_NOT_REACHED(); } +size_t mbtowc(wchar_t*, const char*, size_t) +{ + ASSERT_NOT_REACHED(); +} + +int wctomb(char*, wchar_t) +{ + ASSERT_NOT_REACHED(); +} + template<typename T, T min_value, T max_value> static T strtol_impl(const char* nptr, char** endptr, int base) { diff --git a/Libraries/LibC/stdlib.h b/Libraries/LibC/stdlib.h index 520717b394..d3ecc17b14 100644 --- a/Libraries/LibC/stdlib.h +++ b/Libraries/LibC/stdlib.h @@ -44,6 +44,8 @@ char* mktemp(char*); char* mkdtemp(char*); void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*)); size_t mbstowcs(wchar_t*, const char*, size_t); +size_t mbtowc(wchar_t*, const char*, size_t); +int wctomb(char*, wchar_t); #define RAND_MAX 32767 int rand(); diff --git a/Libraries/LibC/wchar.cpp b/Libraries/LibC/wchar.cpp new file mode 100644 index 0000000000..e1bc54a7c5 --- /dev/null +++ b/Libraries/LibC/wchar.cpp @@ -0,0 +1,40 @@ +#include <wchar.h> + +extern "C" { + +size_t wcslen(const wchar_t* str) +{ + size_t len = 0; + while (*(str++)) + ++len; + return len; +} + +wchar_t* wcscpy(wchar_t* dest, const wchar_t* src) +{ + wchar_t* originalDest = dest; + while ((*dest++ = *src++) != '\0') + ; + return originalDest; +} + +int wcscmp(const wchar_t* s1, const wchar_t* s2) +{ + while (*s1 == *s2++) + if (*s1++ == 0) + return 0; + return *(const wchar_t*)s1 - *(const wchar_t*)--s2; +} + +wchar_t* wcschr(const wchar_t* str, int c) +{ + wchar_t ch = c; + for (;; ++str) { + if (*str == ch) + return const_cast<wchar_t*>(str); + if (!*str) + return nullptr; + } +} + +} diff --git a/Libraries/LibC/wchar.h b/Libraries/LibC/wchar.h index d28d0d4c7d..0c69365e7f 100644 --- a/Libraries/LibC/wchar.h +++ b/Libraries/LibC/wchar.h @@ -9,4 +9,9 @@ __BEGIN_DECLS # define WEOF (0xffffffffu) #endif +size_t wcslen(const wchar_t*); +wchar_t* wcscpy(wchar_t*, const wchar_t*); +int wcscmp(const wchar_t*, const wchar_t*); +wchar_t* wcschr(const wchar_t*, int); + __END_DECLS |