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 / fseek.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-01  |  599 b   |  29 lines

  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4.  
  5. extern void __chkabort(void);
  6. extern int __fflush(FILE *stream);
  7.  
  8. int fseek(FILE *stream,long int offset,int whence)
  9. {
  10.   __chkabort();
  11.   if(stream->flags&64) /* Error on stream */
  12.   { errno=EPERM;
  13.     return EOF; }
  14.   if(stream->flags&8)
  15.     if(__fflush(stream))
  16.       return EOF;
  17.   if(whence==SEEK_CUR)
  18.     offset-=stream->incount+(stream->tmpp!=NULL?stream->tmpinc:0);
  19.   stream->incount=0;
  20.   stream->tmpp=NULL;
  21.   stream->flags&=~36;
  22.   if(lseek(stream->file,offset,whence)==EOF)
  23.   {
  24.     stream->flags|=64;
  25.     return EOF;
  26.   }
  27.   return 0;
  28. }
  29.