ungetc.c 252 B

12345678910111213141516171819
  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->rend && __toread(f)) || f->rpos <= f->buf - UNGET) {
  7. FUNLOCK(f);
  8. return EOF;
  9. }
  10. *--f->rpos = c;
  11. f->flags &= ~F_EOF;
  12. FUNLOCK(f);
  13. return c;
  14. }