scc

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

commit 7dcb0d9d9eee6306f01cf4788b8eef1fa9baa9c7
parent d7543e2d9e5bc064ac6f1b2469511aae17f0ad52
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Tue, 25 Mar 2025 19:49:46 +0100

libc/wchar: Add wmemset()

Diffstat:
Msrc/libc/objs/common-objs.mk | 1+
Asrc/libc/wchar/wmemset.c | 13+++++++++++++
Mtests/libc/execute/.gitignore | 1+
Atests/libc/execute/0052-wmemset.c | 30++++++++++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 1+
5 files changed, 46 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/wmemchr.$O\ wchar/wmemcpy.$O\ wchar/wmemmove.$O\ + wchar/wmemset.$O\ wchar/wmemcmp.$O\ wchar/putwc.$O\ wchar/_validutf8.$O\ diff --git a/src/libc/wchar/wmemset.c b/src/libc/wchar/wmemset.c @@ -0,0 +1,13 @@ +#include <wchar.h> + +#undef wmemset + +wchar_t * +wmemset(wchar_t *d, wchar_t wc, size_t n) +{ + wchar_t *ret = d; + + while (n-- > 0) + *d++ = wc; + return ret; +} diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore @@ -47,6 +47,7 @@ 0048-wcscpy 0049-wmemchr 0050-wmemcpy +0052-wmemset 0051-wmemmove 0053-wmemcmp test.log diff --git a/tests/libc/execute/0052-wmemset.c b/tests/libc/execute/0052-wmemset.c @@ -0,0 +1,30 @@ +#include <assert.h> +#include <stdio.h> +#include <wchar.h> + +/* +output: +testing +done +end: +*/ + +int +main() +{ + wchar_t *p, buf[40]; + + puts("testing"); + + wmemset(buf, 2, 40); + for (p = buf; p < &buf[40]; ++p) + assert(*p == 2); + + wmemset(buf, 0, 0); + for (p = buf; p < &buf[40]; ++p) + assert(*p == 2); + + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst @@ -47,4 +47,5 @@ 0049-wmemchr 0050-wmemcpy 0051-wmemmove +0052-wmemset 0053-wmemcmp