commit 94d009f0d25f0426186fe0f209abc1f229c47d12
parent c5af9fc33eda2506eebc629d07a09e637e3311f2
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Mon, 24 Mar 2025 09:54:26 +0100
libc/wchar: Add wcscpy()
Diffstat:
5 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
@@ -130,6 +130,7 @@ COMMON_OBJS =\
wchar/wcscmp.$O\
wchar/wcscoll.$O\
wchar/wcsncmp.$O\
+ wchar/wcscpy.$O\
wchar/wcsrtombs.$O\
wchar/wcwidth.$O\
wchar/putwc.$O\
diff --git a/src/libc/wchar/wcscpy.c b/src/libc/wchar/wcscpy.c
@@ -0,0 +1,16 @@
+#include <wchar.h>
+
+#undef wcscpy
+
+wchar_t *
+wcscpy(wchar_t * restrict s1, const wchar_t * restrict s2)
+{
+ wchar_t *ret = s1;
+
+ while ((*s1++ = *s2++) != '\0')
+ ;
+
+ return ret;
+
+}
+
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -44,4 +44,5 @@
0045-wcscmp
0046-wcsncmp
0047-wcscoll
+0048-wcscpy
test.log
diff --git a/tests/libc/execute/0048-wcscpy.c b/tests/libc/execute/0048-wcscpy.c
@@ -0,0 +1,31 @@
+#include <assert.h>
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+output:
+testing
+done
+end:
+*/
+
+int
+main()
+{
+ wchar_t test[]= {'t', 'e', 's', 't', 0};
+ wchar_t *s, buf[40];
+
+ puts("testing");
+
+ s = wcscpy(buf, test);
+ assert(s == buf);
+ assert(!wcscmp(s, test));
+
+ s = wcscpy(buf, "");
+ assert(s == buf);
+ assert(!wcscmp(s, ""));
+
+ puts("done");
+
+ return 0;
+}
+\ No newline at end of file
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -43,3 +43,4 @@
0045-wcscmp
0046-wcsncmp
0047-wcscoll
+0048-wcscpy