X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fungetc.c;h=bc629d4ca511f812976abb93224e2732e0788e6e;hb=4554f155dd23a65fcdfd39f1d5af8af55ba37694;hp=0718168427603259924da29e38e4fb8d30b49302;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/stdio/ungetc.c b/src/stdio/ungetc.c index 07181684..bc629d4c 100644 --- a/src/stdio/ungetc.c +++ b/src/stdio/ungetc.c @@ -6,28 +6,15 @@ int ungetc(int c, FILE *f) FLOCK(f); - /* Fail if unreadable or writing and unable to flush */ - if ((f->flags & (F_ERR|F_NORD)) || (f->wpos && __oflow(f))) { + if (!f->rpos) __toread(f); + if (!f->rpos || f->rpos <= f->buf - UNGET) { FUNLOCK(f); return EOF; } - /* Clear write mode */ - f->wbase = 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 already full, fail. */ - if (f->rpos <= f->buf - UNGET) { - FUNLOCK(f); - return EOF; - } - - /* Put a byte back into the buffer */ *--f->rpos = c; f->flags &= ~F_EOF; FUNLOCK(f); - return c; + return (unsigned char)c; }