home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix / stdio / ftell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  427 b   |  21 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4.  
  5. extern void __chkabort(void);
  6.  
  7. long ftell(FILE *stream)
  8. {
  9.   long pos;
  10.   __chkabort();
  11.   if(stream->flags&64) /* Error on stream */
  12.   { errno=EPERM;
  13.     return EOF; }
  14.   pos=lseek(stream->file,0,SEEK_CUR);
  15.   if(stream->flags&4)
  16.     pos-=stream->incount+(stream->tmpp!=NULL?stream->tmpinc:0);
  17.   else if(stream->flags&8)
  18.     pos+=stream->p-stream->buffer;
  19.   return pos;
  20. }
  21.