commit 949d7de20391cbcb0a6ce10cf2080abb7914b6b5
parent 7aa86bd1b38fb9ddd568ed8c13f534a274f50fbb
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Tue, 25 Mar 2025 20:50:32 +0100
libc/wchar: Add wcscat()
Diffstat:
5 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk
@@ -131,6 +131,7 @@ COMMON_OBJS =\
 	wchar/wcscoll.$O\
 	wchar/wcsncmp.$O\
 	wchar/wcscpy.$O\
+	wchar/wcscat.$O\
 	wchar/wcsrtombs.$O\
 	wchar/wcwidth.$O\
 	wchar/wmemchr.$O\
diff --git a/src/libc/wchar/wcscat.c b/src/libc/wchar/wcscat.c
@@ -0,0 +1,16 @@
+#include <wchar.h>
+
+#undef wcscat
+
+wchar_t *
+wcscat(wchar_t *restrict s1, const wchar_t *restrict s2)
+{
+	wchar_t *p;
+
+	for (p = s1; *p; ++p)
+		;
+	while ((*p++ = *s2++) != 0)
+		;
+
+	return s1;
+}
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -51,4 +51,5 @@
 0051-wmemmove
 0053-wmemcmp
 0054-wcsncpy
+0055-wcscat
 test.log
diff --git a/tests/libc/execute/0055-wcscat.c b/tests/libc/execute/0055-wcscat.c
@@ -0,0 +1,36 @@
+#include <assert.h>
+#include <stdio.h>
+#include <wchar.h>
+
+/*
+output:
+testing
+ok
+end:
+*/
+
+int
+main(void)
+{
+	wchar_t *s, buf[40];
+
+	puts("testing");
+	wcscpy(buf, L"case1:");
+	s = wcscat(buf, L"ok");
+	assert(s == buf);
+	assert(!wcscmp(s, L"case1:ok"));
+
+	wcscpy(buf, L"");
+	s = wcscat(buf, L"ok");
+	assert(s == buf);
+	assert(!wcscmp(s, L"ok"));
+
+	wcscpy(buf, L"case1:");
+	wcscat(buf, L"");
+	assert(s == buf);
+	assert(!wcscmp(s, L"case1:"));
+
+	puts("ok");
+
+	return 0;
+}
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -50,3 +50,4 @@
 0052-wmemset
 0053-wmemcmp
 0054-wcsncpy
+0055-wcscat