X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fstdio%2Fungetwc.c;h=8cc85a6bfd2a00b615ecccdc96fbfc519e4b77f5;hp=6871d0344a037314727235a99d49262fd77a4fbb;hb=HEAD;hpb=9ae8d5fc71a4b61ec826d58f03f7b543755fb1d4 diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c index 6871d034..8cc85a6b 100644 --- a/src/stdio/ungetwc.c +++ b/src/stdio/ungetwc.c @@ -1,4 +1,8 @@ #include "stdio_impl.h" +#include +#include +#include +#include wint_t ungetwc(wint_t c, FILE *f) { @@ -15,29 +19,14 @@ wint_t ungetwc(wint_t c, FILE *f) f->mode |= f->mode+1; - /* Fail if unreadable or writing and unable to flush */ - if ((f->flags & (F_ERR|F_NORD)) || (f->wpos && __oflow(f))) { + if ((!f->rend && __toread(f)) || f->rpos < f->buf - UNGET + l) { FUNLOCK(f); return EOF; } - /* Clear write mode */ - f->wpos = f->wstop = f->wend = 0; - - /* Put the file in read mode */ - if (!f->rpos) f->rpos = f->rend = f->buf; - - /* If unget buffer is nonempty, fail. */ - if (f->rpos < f->buf) { - FUNLOCK(f); - return WEOF; - } - - /* Put character back into the buffer */ if (isascii(c)) *--f->rpos = c; else memcpy(f->rpos -= l, mbc, l); - /* Clear EOF */ f->flags &= ~F_EOF; FUNLOCK(f);