ungetc.c 278 B

1234567891011121314151617181920
  1. #include "stdio_impl.h"
  2. int ungetc(int c, FILE *f)
  3. {
  4. if (c == EOF) return c;
  5. FLOCK(f);
  6. if (!f->rpos) __toread(f);
  7. if (!f->rpos || f->rpos <= f->buf - UNGET) {
  8. FUNLOCK(f);
  9. return EOF;
  10. }
  11. *--f->rpos = c;
  12. f->flags &= ~F_EOF;
  13. FUNLOCK(f);
  14. return (unsigned char)c;
  15. }