scc

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

commit f82bc6684d7c33065ce616b79528e7a0e439d1df
parent 391c2dacb748852e77bfe811556b145ecdda684b
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Tue, 25 Mar 2025 19:03:27 +0100

libc/wchar: Add wmemcpy()

Diffstat:
Msrc/libc/objs/common-objs.mk | 1+
Asrc/libc/wchar/wmemcpy.c | 10++++++++++
Mtests/libc/execute/.gitignore | 1+
Atests/libc/execute/0050-wmemcpy.c | 24++++++++++++++++++++++++
Mtests/libc/execute/libc-tests.lst | 1+
5 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk @@ -134,5 +134,6 @@ COMMON_OBJS =\ wchar/wcsrtombs.$O\ wchar/wcwidth.$O\ wchar/wmemchr.$O\ + wchar/wmemcpy.$O\ wchar/putwc.$O\ wchar/_validutf8.$O\ diff --git a/src/libc/wchar/wmemcpy.c b/src/libc/wchar/wmemcpy.c @@ -0,0 +1,10 @@ +#include <string.h> +#include <wchar.h> + +#undef wmemcpy + +wchar_t * +wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) +{ + return memcpy(d, s, n * sizeof(wchar_t)); +} diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore @@ -46,4 +46,5 @@ 0047-wcscoll 0048-wcscpy 0049-wmemchr +0050-wmemcpy test.log diff --git a/tests/libc/execute/0050-wmemcpy.c b/tests/libc/execute/0050-wmemcpy.c @@ -0,0 +1,24 @@ +#include <assert.h> +#include <stdio.h> +#include <wchar.h> + +/* +output: +testing +done +end: +*/ + +int +main() +{ + wchar_t buf[40]; + wchar_t abc[] = {'a', 'b', 'c', '\0'}; + + puts("testing"); + assert(!wmemcmp(wmemcpy(buf, abc, 3), abc, 3)); + assert(wmemcpy(buf, abc, 0) == buf); + puts("done"); + + return 0; +} diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst @@ -45,3 +45,4 @@ 0047-wcscoll 0048-wcscpy 0049-wmemchr +0050-wmemcpy