summaryrefslogtreecommitdiff
path: root/src/wchar/wcrtomb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/wchar/wcrtomb.c')
-rw-r--r--src/wchar/wcrtomb.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/wchar/wcrtomb.c b/src/wchar/wcrtomb.c
index 20cbe235..c73cdce8 100644
--- a/src/wchar/wcrtomb.c
+++ b/src/wchar/wcrtomb.c
@@ -1,18 +1,27 @@
#include <wchar.h>
#include <limits.h>
-#include "_safety.h"
+#include "_wchar.h"
+GCC_SSE_HACK
size_t wcrtomb(char * restrict s, wchar_t wc, mbstate_t * restrict ps)
{
+ static struct __mbstate_t internal = { 0 };
+ static mbstate_t ip = { &internal };
+
+ if (ps == NULL) {
+ ps = &ip;
+ }
+
SIGNAL_SAFE(0);
+ ASSERT_MBSTATE(ps, WTOMB, s, &wc);
/* TODO: overlap */
- char buf[MB_LEN_MAX+1];
if (s == NULL) {
- s = buf;
- wc = L'\0';
+ char buf[MB_LEN_MAX+1];
+ return wcrtomb(buf, L'\0', ps);
}
- (void)wc; (void)ps;
+
+ SET_MBSTATE(ps, WTOMB, s, &wc);
/* do stuff */
return 0;