3 size_t mbsnrtowcs(wchar_t *restrict wcs
, const char **restrict src
, size_t n
, size_t wn
, mbstate_t *restrict st
)
6 wchar_t *ws
, wbuf
[256];
10 if (!wcs
) ws
= wbuf
, wn
= sizeof wbuf
/ sizeof *wbuf
;
13 /* making sure output buffer size is at most n/4 will ensure
14 * that mbsrtowcs never reads more than n input bytes. thus
15 * we can use mbsrtowcs as long as it's practical.. */
17 while ( s
&& wn
&& ( (n2
=n
/4)>=wn
|| n2
>32 ) ) {
20 l
= mbsrtowcs(ws
, &s
, n2
, st
);
30 n
= s
? n
- (s
- tmp_s
) : 0;
33 if (s
) while (wn
&& n
) {
34 l
= mbrtowc(ws
, s
, n
, st
);
44 /* have to roll back partial character */
49 /* safe - this loop runs fewer than sizeof(wbuf)/8 times */