libc/stdlib: Use state in mbstowcs and wcstombs - scc - simple c99 compiler
HTML git clone git://git.simple-cc.org/scc
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit c5af9fc33eda2506eebc629d07a09e637e3311f2
DIR parent 32ebae08d603f27be737d19728d48f2a9859de50
HTML 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:
M src/libc/stdlib/mbstowcs.c | 4 +++-
M src/libc/stdlib/wcstombs.c | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
---
DIR 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);
}
DIR 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);
}