X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmultibyte%2Fwcsnrtombs.c;h=ee4a534ab0c5131991a9af15c612f63391cf8d27;hb=e8cbe0bad4284906230a53af4c91ad2b9713d03b;hp=666f6f3f20f5928bc158b319c1c635a31645dae0;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/multibyte/wcsnrtombs.c b/src/multibyte/wcsnrtombs.c index 666f6f3f..ee4a534a 100644 --- a/src/multibyte/wcsnrtombs.c +++ b/src/multibyte/wcsnrtombs.c @@ -4,14 +4,9 @@ * unnecessary. */ -#include -#include #include -#include -#include "internal.h" - -size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, mbstate_t *st) +size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st) { size_t l, cnt=0, n2; char *s, buf[256]; @@ -20,7 +15,7 @@ size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, mbstate_t if (!dst) s = buf, n = sizeof buf; else s = dst; - while ( n && ( (n2=wn)>=n || n2>32 ) ) { + while ( ws && n && ( (n2=wn)>=n || n2>32 ) ) { if (n2>=n) n2=n; wn -= n2; l = wcsrtombs(s, &ws, n2, 0); @@ -35,16 +30,17 @@ size_t wcsnrtombs(char *dst, const wchar_t **wcs, size_t wn, size_t n, mbstate_t } cnt += l; } - while (n && wn) { + if (ws) while (n && wn) { l = wcrtomb(s, *ws, 0); - if (!(l+1)) { - cnt = l; + if ((l+1)<=1) { + if (!l) ws = 0; + else cnt = l; break; } ws++; wn--; /* safe - this loop runs fewer than sizeof(buf) times */ s+=l; n-=l; - cnt++; + cnt += l; } if (dst) *wcs = ws; return cnt;