X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmultibyte%2Fmbsrtowcs.c;h=e23083d223fc4c5528d46730b7c12a936888ef64;hb=4cd8b4725907651f329e2f96d428c4e3521643f8;hp=b9bbc33daf54c7071c2a527c9eb725d5a912f30d;hpb=4ca442157e381690202c3bcc102627d137fd0466;p=musl diff --git a/src/multibyte/mbsrtowcs.c b/src/multibyte/mbsrtowcs.c index b9bbc33d..e23083d2 100644 --- a/src/multibyte/mbsrtowcs.c +++ b/src/multibyte/mbsrtowcs.c @@ -4,11 +4,11 @@ * unnecessary. */ -#include -#include +#include #include #include - +#include +#include #include "internal.h" size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st) @@ -26,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)) { @@ -59,7 +76,7 @@ resume0: return wn0; } if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) { - while (wn>=4 && !(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) { + while (wn>=5 && !(( *(uint32_t*)s | *(uint32_t*)s-0x01010101) & 0x80808080)) { *ws++ = *s++; *ws++ = *s++; *ws++ = *s++;