fgetc.c 416 B

123456789101112131415161718
  1. #include <stdio.h>
  2. #include <peekpoke.h>
  3. __ATTR_LIB_C__ short fgetc(FILE *f)
  4. {
  5. short c,tmode=!(f->flags&_F_BIN);
  6. if(f->flags&_F_ERR) return EOF;
  7. if(!(f->flags&_F_READ)) __FERROR(f);
  8. if((c=f->unget)<0)
  9. {
  10. f->unget=0; return c&0xFF;
  11. }
  12. if(feof(f)) return EOF;
  13. c=peek(f->fpos++);
  14. if(c=='\r'&&tmode) fgetc(f);
  15. if(f->base+peek_w(f->base)+(tmode?0:2)==f->fpos) f->flags|=_F_EOF;
  16. return c;
  17. }