|
@@ -5,36 +5,36 @@
|
|
|
|
|
|
static wint_t __fgetwc_unlocked_internal(FILE *f)
|
|
static wint_t __fgetwc_unlocked_internal(FILE *f)
|
|
{
|
|
{
|
|
- mbstate_t st = { 0 };
|
|
|
|
wchar_t wc;
|
|
wchar_t wc;
|
|
int c;
|
|
int c;
|
|
- unsigned char b;
|
|
|
|
size_t l;
|
|
size_t l;
|
|
|
|
|
|
/* Convert character from buffer if possible */
|
|
/* Convert character from buffer if possible */
|
|
if (f->rpos < f->rend) {
|
|
if (f->rpos < f->rend) {
|
|
- l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st);
|
|
|
|
- if (l+2 >= 2) {
|
|
|
|
|
|
+ l = mbtowc(&wc, (void *)f->rpos, f->rend - f->rpos);
|
|
|
|
+ if (l+1 >= 1) {
|
|
f->rpos += l + !l; /* l==0 means 1 byte, null */
|
|
f->rpos += l + !l; /* l==0 means 1 byte, null */
|
|
return wc;
|
|
return wc;
|
|
}
|
|
}
|
|
- if (l == -1) {
|
|
|
|
- f->rpos++;
|
|
|
|
- return WEOF;
|
|
|
|
- }
|
|
|
|
- f->rpos = f->rend;
|
|
|
|
- } else l = -2;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
/* Convert character byte-by-byte */
|
|
/* Convert character byte-by-byte */
|
|
- while (l == -2) {
|
|
|
|
|
|
+ mbstate_t st = { 0 };
|
|
|
|
+ unsigned char b;
|
|
|
|
+ int first = 1;
|
|
|
|
+ do {
|
|
b = c = getc_unlocked(f);
|
|
b = c = getc_unlocked(f);
|
|
if (c < 0) {
|
|
if (c < 0) {
|
|
- if (!mbsinit(&st)) errno = EILSEQ;
|
|
|
|
|
|
+ if (!first) errno = EILSEQ;
|
|
return WEOF;
|
|
return WEOF;
|
|
}
|
|
}
|
|
l = mbrtowc(&wc, (void *)&b, 1, &st);
|
|
l = mbrtowc(&wc, (void *)&b, 1, &st);
|
|
- if (l == -1) return WEOF;
|
|
|
|
- }
|
|
|
|
|
|
+ if (l == -1) {
|
|
|
|
+ if (!first) ungetc(b, f);
|
|
|
|
+ return WEOF;
|
|
|
|
+ }
|
|
|
|
+ first = 0;
|
|
|
|
+ } while (l == -2);
|
|
|
|
|
|
return wc;
|
|
return wc;
|
|
}
|
|
}
|