2 * fseek.c - perform an fseek
4 /* $Id: fseek.c,v 1.6 1994/06/24 11:50:01 ceriel Exp $ */
8 #if (SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0)
9 #error SEEK_* values are wrong
14 #include <sys/types.h>
16 off_t _lseek(int fildes, off_t offset, int whence);
19 fseek(FILE *stream, long int offset, int whence)
24 stream->_flags &= ~(_IOEOF | _IOERR);
25 /* Clear both the end of file and error flags */
27 if (io_testflag(stream, _IOREADING)) {
28 if (whence == SEEK_CUR
30 && !io_testflag(stream,_IONBF))
31 adjust = stream->_count;
33 } else if (io_testflag(stream,_IOWRITING)) {
35 } else /* neither reading nor writing. The buffer must be empty */
38 pos = _lseek(fileno(stream), offset - adjust, whence);
39 if (io_testflag(stream, _IOREAD) && io_testflag(stream, _IOWRITE))
40 stream->_flags &= ~(_IOREADING | _IOWRITING);
42 stream->_ptr = stream->_buf;
43 return ((pos == -1) ? -1 : 0);