scc

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

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

libc/stdlib: Add internal mbstate in mbstowcs()

mbstowcs() is supposed to be thread safe and not dependant of the
state in mbsrtocws().

Diffstat:
Msrc/libc/stdlib/mbstowcs.c | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/libc/stdlib/mbstowcs.c b/src/libc/stdlib/mbstowcs.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <string.h> #include <wchar.h> #undef mbstowcs @@ -6,5 +7,7 @@ size_t mbstowcs(wchar_t *restrict dest, const char *restrict src, size_t n) { - return mbsrtowcs(dest, (void *) &src, n, NULL); + mbstate_t p; + + return mbsrtowcs(dest, (void *) &src, n, memset(&p, 0, sizeof(p))); }