X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmultibyte%2Fwcsnrtombs.c;h=676932b5dcaa0d93da7fabded9c006dd57e19d90;hb=db505b794c697631f65e6b91ff106496debb86ac;hp=ee4a534ab0c5131991a9af15c612f63391cf8d27;hpb=2e1ae3b6b9331383ba5eaa7cb47373a8bea073d1;p=musl diff --git a/src/multibyte/wcsnrtombs.c b/src/multibyte/wcsnrtombs.c index ee4a534a..676932b5 100644 --- a/src/multibyte/wcsnrtombs.c +++ b/src/multibyte/wcsnrtombs.c @@ -1,9 +1,3 @@ -/* - * This code was written by Rich Felker in 2010; no copyright is claimed. - * This code is in the public domain. Attribution is appreciated but - * unnecessary. - */ - #include size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st) @@ -11,13 +5,14 @@ size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, s size_t l, cnt=0, n2; char *s, buf[256]; const wchar_t *ws = *wcs; + const wchar_t *tmp_ws; if (!dst) s = buf, n = sizeof buf; else s = dst; while ( ws && n && ( (n2=wn)>=n || n2>32 ) ) { if (n2>=n) n2=n; - wn -= n2; + tmp_ws = ws; l = wcsrtombs(s, &ws, n2, 0); if (!(l+1)) { cnt = l; @@ -28,6 +23,7 @@ size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, s s += l; n -= l; } + wn = ws ? wn - (ws - tmp_ws) : 0; cnt += l; } if (ws) while (n && wn) {