author | Rich Felker <dalias@aerifal.cx> | 2011年03月28日 01:14:44 -0400 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011年03月28日 01:14:44 -0400 |
commit | e3cd6c5c265cd481db6e0c5b529855d99f0bda30 (patch) | |
tree | 85d2c586e4ea8e261ed68cc4b1901a1711774441 /src/stdio/ungetwc.c | |
parent | ea343364a719add2cd8adf8a50c15bb5f9400dd8 (diff) | |
download | musl-e3cd6c5c265cd481db6e0c5b529855d99f0bda30.tar.gz |
-rw-r--r-- | src/stdio/ungetwc.c | 17 |
diff --git a/src/stdio/ungetwc.c b/src/stdio/ungetwc.c index 6871d034..5282fee1 100644 --- a/src/stdio/ungetwc.c +++ b/src/stdio/ungetwc.c @@ -15,29 +15,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); |