diff --git a/libs/libc/include/wchar.h b/libs/libc/include/wchar.h index fb2033da..a206751e 100644 --- a/libs/libc/include/wchar.h +++ b/libs/libc/include/wchar.h @@ -1,11 +1,24 @@ #ifndef _WCHAR_H #define _WCHAR_H +#include #include -#ifndef __WINT_TYPE__ -#define __WINT_TYPE__ unsigned int +typedef unsigned int wint_t; + +#ifdef __cplusplus +extern "C" +{ +#endif + + /* Return the length of a wide-character string. */ + size_t wcslen(const wchar_t* str); + + /* Concatenates the wide-character string src into dest. */ + __lc_is_deprecated wchar_t* wcscat(wchar_t* dest, const wchar_t* src); + +#ifdef __cplusplus +} #endif -typedef __WINT_TYPE__ wint_t; #endif \ No newline at end of file diff --git a/libs/libc/src/wchar.cpp b/libs/libc/src/wchar.cpp new file mode 100644 index 00000000..50d32df9 --- /dev/null +++ b/libs/libc/src/wchar.cpp @@ -0,0 +1,24 @@ +#include + +extern "C" +{ + size_t wcslen(const wchar_t* str) + { + const wchar_t* i = str; + for (; *i; ++i) + ; + return (i - str); + } + + wchar_t* wcscat(wchar_t* dest, const wchar_t* src) + { + size_t dest_len = wcslen(dest); + size_t i; + + for (i = 0; *(src + i); i++) *(dest + dest_len + i) = *(src + i); + + *(dest + dest_len + i) = L'\0'; + + return dest; + } +} \ No newline at end of file diff --git a/tests/libc/Makefile b/tests/libc/Makefile index db92eeec..698044bc 100644 --- a/tests/libc/Makefile +++ b/tests/libc/Makefile @@ -4,7 +4,7 @@ DESTDIR := $(LUNA_ROOT)/initrd/bin build: @mkdir -p $(TESTDIR)/bin $(LUNA_ROOT)/tools/sync-libc.sh - $(CC) $(TESTDIR)/string.c $(TESTDIR)/stdlib.c $(TESTDIR)/Test.c -I$(LUNA_ROOT)/tests -o $(TESTDIR)/bin/test-libc -Wall -Wextra -Wno-deprecated-declarations -Wno-stringop-overread -Werror + $(CC) $(TESTDIR)/string.c $(TESTDIR)/stdlib.c $(TESTDIR)/wchar.c $(TESTDIR)/Test.c -I$(LUNA_ROOT)/tests -o $(TESTDIR)/bin/test-libc -Wall -Wextra -Wno-deprecated-declarations -Wno-stringop-overread -Werror install: $(LUNA_ROOT)/tools/clean.sh diff --git a/tests/libc/Test.c b/tests/libc/Test.c index cba4b5bc..afc9b17d 100644 --- a/tests/libc/Test.c +++ b/tests/libc/Test.c @@ -30,6 +30,9 @@ DEFINE_TEST(mktemp); DEFINE_TEST(qsort); DEFINE_TEST(bsearch); +// wchar.h +DEFINE_TEST(wcslen); + int main() { START_TEST_CASE(string.h); @@ -61,4 +64,7 @@ int main() RUN_TEST(mktemp); RUN_TEST(qsort); RUN_TEST(bsearch); + + START_TEST_CASE(wchar.h); + RUN_TEST(wcslen); } \ No newline at end of file diff --git a/tests/libc/wchar.c b/tests/libc/wchar.c new file mode 100644 index 00000000..bec6dc7e --- /dev/null +++ b/tests/libc/wchar.c @@ -0,0 +1,21 @@ +#include "Test.h" +#include + +DEFINE_TEST(wcslen) +{ + START_TEST(wcslen); + + const wchar_t* str = L"Hello, World!"; + + size_t len = wcslen(str); + + EXPECT_EQ(len, 13); + + wchar_t null[] = {L'\0'}; + + len = wcslen(null); + + EXPECT_EQ(len, 0); + + TEST_SUCCESS(); +} \ No newline at end of file