9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

ftell.c (424B)


      1 #include <stdio.h>
      2 #include "../syscall.h"
      3 #undef ftell
      4 
      5 long
      6 ftell(FILE *fp)
      7 {
      8 	long off;
      9 	unsigned char *p;
     10 
     11 	if (fp->flags & _IOERR)
     12 		return EOF;
     13 
     14 	if ((off = _lseek(fp->fd, 0, SEEK_CUR)) < 0) {
     15 		fp->flags |= _IOERR;
     16 		return EOF;
     17 	}
     18 
     19 	if (fp->flags & _IOREAD)
     20 		return off - (fp->wp - fp->rp);
     21 
     22 	if (fp->flags & _IOWRITE) {
     23 		p = (fp->flags & _IOLBF) ? fp->lp : fp->wp;
     24 		return off + (p - fp->buf);
     25 	}
     26 	return off;
     27 }