fix dup3 ignoring all flags but O_CLOEXEC on archs with SYS_dup2 syscall
[musl] / src / stdio / ungetc.c
index 7f56f8d..bc629d4 100644 (file)
@@ -6,7 +6,8 @@ int ungetc(int c, FILE *f)
 
        FLOCK(f);
 
-       if ((!f->rend && __toread(f)) || f->rpos <= f->buf - UNGET) {
+       if (!f->rpos) __toread(f);
+       if (!f->rpos || f->rpos <= f->buf - UNGET) {
                FUNLOCK(f);
                return EOF;
        }
@@ -15,5 +16,5 @@ int ungetc(int c, FILE *f)
        f->flags &= ~F_EOF;
 
        FUNLOCK(f);
-       return c;
+       return (unsigned char)c;
 }