summaryrefslogtreecommitdiff
path: root/src/multibyte/mbsrtowcs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/multibyte/mbsrtowcs.c')
-rw-r--r--src/multibyte/mbsrtowcs.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/multibyte/mbsrtowcs.c b/src/multibyte/mbsrtowcs.c
index 3c1343ae..e23083d2 100644
--- a/src/multibyte/mbsrtowcs.c
+++ b/src/multibyte/mbsrtowcs.c
@@ -7,6 +7,8 @@
#include <stdint.h>
#include <wchar.h>
#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
#include "internal.h"
size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st)
@@ -24,6 +26,23 @@ size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbs
}
}
+ if (MB_CUR_MAX==1) {
+ if (!ws) return strlen((const char *)s);
+ for (;;) {
+ if (!wn) {
+ *src = (const void *)s;
+ return wn0;
+ }
+ if (!*s) break;
+ c = *s++;
+ *ws++ = CODEUNIT(c);
+ wn--;
+ }
+ *ws = 0;
+ *src = 0;
+ return wn0-wn;
+ }
+
if (!ws) for (;;) {
if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) {
while (!(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) {