X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstdio%2Fungetwc.c;h=9edf366f90d5ce07d6c7ed3ff448981c66ddefd9;hb=59b64ff686cef2a87e9552658b2c8d2531f87176;hp=0a4cd7a1f2f01d94b35ec04b7353aa360b7429bf;hpb=7e816a6487932cbb3cb71d94b609e50e81f4e5bf;p=musl diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c index 0a4cd7a1..9edf366f 100644 --- a/src/stdio/ungetwc.c +++ b/src/stdio/ungetwc.c @@ -1,4 +1,5 @@ #include "stdio_impl.h" +#include "locale_impl.h" #include #include #include @@ -7,18 +8,19 @@ wint_t ungetwc(wint_t c, FILE *f) { unsigned char mbc[MB_LEN_MAX]; - int l=1; - - if (c == WEOF) return c; + int l; + locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; FLOCK(f); - f->mode |= f->mode+1; + if (f->mode <= 0) fwide(f, 1); + *ploc = f->locale; if (!f->rpos) __toread(f); - if (!f->rpos || f->rpos < f->buf - UNGET + l || - (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0)) { + if (!f->rpos || c == WEOF || (l = wcrtomb((void *)mbc, c, 0)) < 0 || + f->rpos < f->buf - UNGET + l) { FUNLOCK(f); + *ploc = loc; return WEOF; } @@ -28,5 +30,6 @@ wint_t ungetwc(wint_t c, FILE *f) f->flags &= ~F_EOF; FUNLOCK(f); + *ploc = loc; return c; }