scc

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

commit c5af9fc33eda2506eebc629d07a09e637e3311f2
parent 32ebae08d603f27be737d19728d48f2a9859de50
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Sat, 22 Mar 2025 10:32:25 +0100

libc/stdlib: Use state in mbstowcs and wcstombs

These functions should behave as if mbrstowcs() and wcsrtombs() were not
called, and for that reason they need their own internal  state  instead
of using the state from them.

Diffstat:
Msrc/libc/stdlib/mbstowcs.c | 4+++-
Msrc/libc/stdlib/wcstombs.c | 4+++-
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/libc/stdlib/mbstowcs.c b/src/libc/stdlib/mbstowcs.c @@ -7,5 +7,7 @@ size_t mbstowcs(wchar_t *restrict dest, const char *restrict src, size_t n) { - return mbsrtowcs(dest, (void *) &src, n, NULL); + static mbstate_t st; + + return mbsrtowcs(dest, (void *) &src, n, &st); } diff --git a/src/libc/stdlib/wcstombs.c b/src/libc/stdlib/wcstombs.c @@ -6,5 +6,7 @@ size_t wcstombs(char *restrict dest, const wchar_t *restrict src, size_t n) { - return wcsrtombs(dest, (void *) &src, n, NULL); + static mbstate_t st; + + return wcsrtombs(dest, (void *) &src, n, &st); }