ftell.c 306 B

12345678910111213141516
  1. /*
  2. * pANS stdio -- ftell
  3. */
  4. #include "iolib.h"
  5. long ftell(FILE *f){
  6. long seekp=seek(f->fd, 0L, 1);
  7. if(seekp<0) return -1; /* enter error state? */
  8. switch(f->state){
  9. default:
  10. return seekp;
  11. case RD:
  12. return seekp-(f->wp-f->rp);
  13. case WR:
  14. return (f->flags&LINEBUF?f->lp:f->wp)-f->buf+seekp;
  15. }
  16. }