scc

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

commit c675740de75457783b309d357f586a768cf31fed
parent 6f13ed360e15b5daa1df2c2de39dc93422db4255
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Thu, 20 Mar 2025 20:23:33 +0100

libc/stdlib: Use internal state in wctomb()

Wctomb() must behave as if the function wcrtomb() is not called (in
other words, it should not use the internal hidden state of wcrtomb())
and for that reason its own static mbstate_t variable.

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

diff --git a/src/libc/stdlib/wctomb.c b/src/libc/stdlib/wctomb.c @@ -6,5 +6,7 @@ int wctomb(char *s, wchar_t wc) { - return wcrtomb(s, wc, NULL); + static mbstate_t st; + + return wcrtomb(s, wc, &st); }