source: trunk/minix/lib/stdio/fseek.c@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.1 KB
Line 
1/*
2 * fseek.c - perform an fseek
3 */
4/* $Header: /cvsup/minix/src/lib/stdio/fseek.c,v 1.1.1.1 2005/04/21 14:56:35 beng Exp $ */
5
6#include <stdio.h>
7
8#if (SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0)
9#error SEEK_* values are wrong
10#endif
11
12#include "loc_incl.h"
13
14#include <sys/types.h>
15
16off_t _lseek(int fildes, off_t offset, int whence);
17
18int
19fseek(FILE *stream, long int offset, int whence)
20{
21 int adjust = 0;
22 long pos;
23
24 stream->_flags &= ~(_IOEOF | _IOERR);
25 /* Clear both the end of file and error flags */
26
27 if (io_testflag(stream, _IOREADING)) {
28 if (whence == SEEK_CUR
29 && stream->_buf
30 && !io_testflag(stream,_IONBF))
31 adjust = stream->_count;
32 stream->_count = 0;
33 } else if (io_testflag(stream,_IOWRITING)) {
34 fflush(stream);
35 } else /* neither reading nor writing. The buffer must be empty */
36 /* EMPTY */ ;
37
38 pos = _lseek(fileno(stream), offset - adjust, whence);
39 if (io_testflag(stream, _IOREAD) && io_testflag(stream, _IOWRITE))
40 stream->_flags &= ~(_IOREADING | _IOWRITING);
41
42 stream->_ptr = stream->_buf;
43 return ((pos == -1) ? -1 : 0);
44}
Note: See TracBrowser for help on using the repository browser.