X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fungetwc.c;h=9edf366f90d5ce07d6c7ed3ff448981c66ddefd9;hb=8d404733e1314ef633aa09a90865e94fe711b4ca;hp=394f92ac9cba89474f74c00137a13cd53210e4b8;hpb=312eea2ea4f4363fb01b73660c08bfcf43dd3bb4;p=musl diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c index 394f92ac..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,16 +8,19 @@ wint_t ungetwc(wint_t c, FILE *f) { unsigned char mbc[MB_LEN_MAX]; - int l=1; + 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 || c == WEOF || - (!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; } @@ -26,5 +30,6 @@ wint_t ungetwc(wint_t c, FILE *f) f->flags &= ~F_EOF; FUNLOCK(f); + *ploc = loc; return c; }