fix TCS* definitions in mips termios.h
[musl] / src / stdio / fgetwc.c
index 77b30fd..e455cfe 100644 (file)
@@ -1,6 +1,9 @@
 #include "stdio_impl.h"
+#include "locale_impl.h"
+#include <wchar.h>
+#include <errno.h>
 
-wint_t __fgetwc_unlocked(FILE *f)
+static wint_t __fgetwc_unlocked_internal(FILE *f)
 {
        mbstate_t st = { 0 };
        wchar_t wc;
@@ -8,8 +11,6 @@ wint_t __fgetwc_unlocked(FILE *f)
        unsigned char b;
        size_t l;
 
-       f->mode |= f->mode+1;
-
        /* Convert character from buffer if possible */
        if (f->rpos < f->rend) {
                l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st);
@@ -23,9 +24,9 @@ wint_t __fgetwc_unlocked(FILE *f)
                }
        } else l = -2;
 
-       /* Convert character byte-by-byte from __uflow */
+       /* Convert character byte-by-byte */
        while (l == -2) {
-               b = c = __uflow(f);
+               b = c = getc_unlocked(f);
                if (c < 0) {
                        if (!mbsinit(&st)) errno = EILSEQ;
                        return WEOF;
@@ -34,7 +35,16 @@ wint_t __fgetwc_unlocked(FILE *f)
                if (l == -1) return WEOF;
        }
 
-       FUNLOCK(f);
+       return wc;
+}
+
+wint_t __fgetwc_unlocked(FILE *f)
+{
+       locale_t *ploc = &CURRENT_LOCALE, loc = *ploc;
+       if (f->mode <= 0) fwide(f, 1);
+       *ploc = f->locale;
+       wchar_t wc = __fgetwc_unlocked_internal(f);
+       *ploc = loc;
        return wc;
 }