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