fix dlsym RTLD_NEXT support
[oweals/musl.git] / src / stdio / ungetc.c
index 0718168427603259924da29e38e4fb8d30b49302..7f56f8d5f07b79dba384f9ef02fe2b8c160b6467 100644 (file)
@@ -6,25 +6,11 @@ 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->rend && __toread(f)) || 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;