libc/wchar: Add wcscpy() - scc - simple c99 compiler
HTML git clone git://git.simple-cc.org/scc
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 94d009f0d25f0426186fe0f209abc1f229c47d12
DIR parent c5af9fc33eda2506eebc629d07a09e637e3311f2
HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Mon, 24 Mar 2025 09:54:26 +0100
libc/wchar: Add wcscpy()
Diffstat:
M src/libc/objs/common-objs.mk | 1 +
A src/libc/wchar/wcscpy.c | 16 ++++++++++++++++
M tests/libc/execute/.gitignore | 1 +
A tests/libc/execute/0048-wcscpy.c | 32 +++++++++++++++++++++++++++++++
M tests/libc/execute/libc-tests.lst | 1 +
5 files changed, 51 insertions(+), 0 deletions(-)
---
DIR 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\
DIR 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;
+
+}
+
DIR 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
DIR 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
DIR 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