scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit aef615310c0729e97e4ad5a2e4206266660679a2
parent 09245abd272928c778c739e2402517a464b1a678
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Wed, 26 Mar 2025 14:14:28 +0100

libc/wchar: Add wcsxfrm()

Diffstat:
Msrc/libc/objs/common-objs.mk | 1+
Asrc/libc/wchar/wcsxfrm.c | 13+++++++++++++
Mtests/libc/execute/.gitignore | 1+
Atests/libc/execute/0060-wcsxfrm.c | 27+++++++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 1+
5 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk @@ -136,6 +136,7 @@ COMMON_OBJS =\ wchar/wcschr.$O\ wchar/wcsrchr.$O\ wchar/wcsstr.$O\ + wchar/wcsxfrm.$O\ wchar/wcsrtombs.$O\ wchar/wcwidth.$O\ wchar/wmemchr.$O\ diff --git a/src/libc/wchar/wcsxfrm.c b/src/libc/wchar/wcsxfrm.c @@ -0,0 +1,13 @@ +#include <wchar.h> + +#undef wcsxfrm + +size_t +wcsxfrm(wchar_t *dst, const wchar_t *src, size_t n) +{ + size_t len = wcslen(src); + + if (len < n) + wcscpy(dst, src); + return len; +} diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore @@ -56,4 +56,5 @@ 0057-wcschr 0058-wcsrchr 0059-wcsstr +0060-wcsxfrm test.log diff --git a/tests/libc/execute/0060-wcsxfrm.c b/tests/libc/execute/0060-wcsxfrm.c @@ -0,0 +1,27 @@ +#include <assert.h> +#include <stdio.h> +#include <wchar.h> + +/* +output: +testing +done +end: +*/ + +int +main() +{ + wchar_t buf[40]; + size_t n; + + puts("testing"); + + assert(wcsxfrm(buf, L"test", 40) == 4); + assert(wcsxfrm(buf, L"", 0) == 0); + assert(wcsxfrm(NULL, L"abc", 0) > 0); + + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst @@ -55,3 +55,4 @@ 0057-wcschr 0058-wcsrchr 0059-wcsstr +0060-wcsxfrm