scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

fseek.c (455B)


      1 #include <stdio.h>
      2 
      3 #include "../syscall.h"
      4 #include "../libc.h"
      5 
      6 #undef fseek
      7 
      8 int
      9 fseek(FILE *fp, long off, int whence)
     10 {
     11 	if (fp->flags & _IOERR)
     12 		return EOF;
     13 
     14 	if ((fp->flags & _IOWRITE) && _flsbuf(fp))
     15 		return -1;
     16 	else if (whence == SEEK_CUR && (fp->flags & _IOREAD))
     17 		off -= fp->wp - fp->rp;
     18 
     19 	if (_lseek(fp->fd, off, whence) < 0)
     20 		return EOF;
     21 
     22 	if (fp->flags & _IORW)
     23 		fp->flags &= ~(_IOREAD | _IOWRITE);
     24 	fp->flags &= ~_IOEOF;
     25 
     26 	return 0;
     27 }