]> pd.if.org Git - pdclib/blob - functions/stdio/fsetpos.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / stdio / fsetpos.c
1 /* fsetpos( FILE *, const fpos_t * )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdio.h>
8
9 #ifndef REGTEST
10 #include "_PDCLIB_io.h"
11
12 int _PDCLIB_fsetpos_unlocked( FILE * stream, 
13                       const _PDCLIB_fpos_t * pos )
14 {
15     if ( stream->status & _PDCLIB_FWRITE )
16     {
17         if ( _PDCLIB_flushbuffer( stream ) == EOF )
18         {
19             return EOF;
20         }
21     }
22     if ( _PDCLIB_seek( stream, pos->offset, SEEK_SET ) == EOF )
23     {
24         return EOF;
25     }
26     stream->pos.mbs = pos->mbs;
27     
28     return 0;
29 }
30
31 int fsetpos( FILE * stream, 
32              const _PDCLIB_fpos_t * pos )
33 {
34     _PDCLIB_flockfile( stream );
35     int res = _PDCLIB_fsetpos_unlocked( stream, pos );
36     _PDCLIB_funlockfile( stream );
37     return res;
38 }
39
40 #endif
41
42 #ifdef TEST
43 #include "_PDCLIB_test.h"
44
45 int main( void )
46 {
47     /* fsetpos() tested together with fsetpos(). */
48     return TEST_RESULTS;
49 }
50
51 #endif