1#include <stdio.h>23#include "../syscall.h"45#undef ftell67long8ftell(FILE *fp)9{10 long off;11 unsigned char *p;1213 if (fp->flags & _IOERR)14 return EOF;1516 if ((off = _lseek(fp->fd, 0, SEEK_CUR)) < 0) {17 fp->flags |= _IOERR;18 return EOF;19 }2021 if (fp->flags & _IOREAD)22 return off - (fp->wp - fp->rp);2324 if (fp->flags & _IOWRITE) {25 p = (fp->flags & _IOLBF) ? fp->lp : fp->wp;26 return off + (p - fp->buf);27 }28 return off;29}