1 #include "stdio_impl.h"
2 #include "locale_impl.h"
6 static wint_t __fgetwc_unlocked_internal(FILE *f)
14 /* Convert character from buffer if possible */
15 if (f->rpos < f->rend) {
16 l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st);
18 f->rpos += l + !l; /* l==0 means 1 byte, null */
28 /* Convert character byte-by-byte */
30 b = c = getc_unlocked(f);
32 if (!mbsinit(&st)) errno = EILSEQ;
35 l = mbrtowc(&wc, (void *)&b, 1, &st);
36 if (l == -1) return WEOF;
42 wint_t __fgetwc_unlocked(FILE *f)
44 locale_t *ploc = &CURRENT_LOCALE, loc = *ploc;
45 if (f->mode <= 0) fwide(f, 1);
47 wchar_t wc = __fgetwc_unlocked_internal(f);
52 wint_t fgetwc(FILE *f)
56 c = __fgetwc_unlocked(f);
61 weak_alias(__fgetwc_unlocked, fgetwc_unlocked);
62 weak_alias(__fgetwc_unlocked, getwc_unlocked);