1c5332d0b5832f8e49535a6bb69e8214891dab2f
[fw/pdclib] / functions / stdio / fseek.c
1 /* $Id$ */
2
3 /* fseek( FILE *, long offset, int )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10
11 #ifndef REGTEST
12
13 #include <_PDCLIB_glue.h>
14
15 int fseek( struct _PDCLIB_file_t * stream, long offset, int whence )
16 {
17     if ( stream->status & _PDCLIB_FWRITE )
18     {
19         if ( _PDCLIB_flushbuffer( stream ) == EOF )
20         {
21             return EOF;
22         }
23     }
24     stream->status &= ~ _PDCLIB_EOFFLAG;
25     if ( stream->status & _PDCLIB_FRW )
26     {
27         stream->status &= ~ ( _PDCLIB_FREAD | _PDCLIB_FWRITE );
28     }
29     return ( _PDCLIB_seek( stream, offset, whence ) != EOF ) ? 0 : EOF;
30 }
31
32 #endif
33
34 #ifdef TEST
35 #include <_PDCLIB_test.h>
36
37 int main( void )
38 {
39     TESTCASE( NO_TESTDRIVER );
40     return TEST_RESULTS;
41 }
42
43 #endif
44