refactor passwd file access code
[musl] / src / multibyte / mbsrtowcs.c
index 75a493c..3c1343a 100644 (file)
@@ -4,11 +4,9 @@
  * unnecessary.
  */
 
-#include <stdlib.h>
-#include <inttypes.h>
+#include <stdint.h>
 #include <wchar.h>
 #include <errno.h>
-
 #include "internal.h"
 
 size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st)
@@ -54,9 +52,12 @@ resume0:
                wn--;
                c = 0;
        } else for (;;) {
-               if (!wn) return wn0;
+               if (!wn) {
+                       *src = (const void *)s;
+                       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++;