1#include <stdio.h>23#include "../syscall.h"4#include "../libc.h"56#undef fseek78int9fseek(FILE *fp, long off, int whence)10{11 if (fp->flags & _IOERR)12 return EOF;1314 if ((fp->flags & _IOWRITE) && _flsbuf(fp))15 return -1;16 else if (whence == SEEK_CUR && (fp->flags & _IOREAD))17 off -= fp->wp - fp->rp;1819 if (_lseek(fp->fd, off, whence) < 0)20 return EOF;2122 if (fp->flags & _IORW)23 fp->flags &= ~(_IOREAD | _IOWRITE);24 fp->flags &= ~_IOEOF;2526 return 0;27}