scc

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

commit 66d454a379fe6f62be6ea422644651a5b8d510ae
parent 1908a6ea5f748db20b6b2e9f2eda55ae40d0bd75
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  9 Nov 2022 21:07:03 +0100

libc/stdlib: Add wcstombs()

Diffstat:
Msrc/libc/objs/common-objs.mk | 1+
Msrc/libc/stdlib/Makefile | 1+
Asrc/libc/stdlib/wcstombs.c | 12++++++++++++
3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/libc/objs/common-objs.mk b/src/libc/objs/common-objs.mk @@ -91,6 +91,7 @@ COMMON_OBJS =\ stdlib/strtoll.$O\ stdlib/strtoul.$O\ stdlib/strtoull.$O\ + stdlib/wcstombs.$O\ stdlib/wctomb.$O\ string/strcat.$O\ string/strchr.$O\ diff --git a/src/libc/stdlib/Makefile b/src/libc/stdlib/Makefile @@ -31,6 +31,7 @@ OBJS =\ strtoll.$O\ strtoul.$O\ strtoull.$O\ + wcstombs.$O\ wctomb.$O\ all: $(OBJS) diff --git a/src/libc/stdlib/wcstombs.c b/src/libc/stdlib/wcstombs.c @@ -0,0 +1,12 @@ +#include <stdlib.h> +#include <wchar.h> + +#undef wcstombs + +size_t +wcstombs(char *restrict dest, const wchar_t *restrict src, size_t n) +{ + mbstate_t p; + + return wcsrtombs(dest, (void *) &src, n, memset(&p, 0, sizeof(p))); +}