1 #include "stdio_impl.h"
3 int ungetc(int c, FILE *f)
5 if (c == EOF) return c;
9 /* Fail if unreadable or writing and unable to flush */
10 if ((f->flags & (F_ERR|F_NORD)) || (f->wpos && __oflow(f))) {
15 /* Clear write mode */
16 f->wbase = f->wpos = f->wstop = f->wend = 0;
18 /* Put the file in read mode */
19 if (!f->rpos) f->rpos = f->rend = f->buf;
21 /* If unget buffer is already full, fail. */
22 if (f->rpos <= f->buf - UNGET) {
27 /* Put a byte back into the buffer */