]> pd.if.org Git - pdclib.old/blob - functions/stdio/fsetpos.c
Namespace cleanliness: Rename all ***_unlocked functions to _PDCLIB_***_unlocked.
[pdclib.old] / functions / stdio / fsetpos.c
1 /* $Id$ */
2
3 /* fsetpos( FILE *, const fpos_t * )
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 #include <_PDCLIB_io.h>
13
14 int _PDCLIB_fsetpos_unlocked( FILE * stream, 
15                       const _PDCLIB_fpos_t * pos )
16 {
17     if ( stream->status & _PDCLIB_FWRITE )
18     {
19         if ( _PDCLIB_flushbuffer( stream ) == EOF )
20         {
21             return EOF;
22         }
23     }
24     if ( _PDCLIB_seek( stream, pos->offset, SEEK_SET ) == EOF )
25     {
26         return EOF;
27     }
28     stream->pos.mbs = pos->mbs;
29     
30     return 0;
31 }
32
33 int fsetpos( FILE * stream, 
34              const _PDCLIB_fpos_t * pos )
35 {
36     _PDCLIB_flockfile( stream );
37     int res = _PDCLIB_fsetpos_unlocked( stream, pos );
38     _PDCLIB_funlockfile( stream );
39     return res;
40 }
41
42 #endif
43
44 #ifdef TEST
45 #include <_PDCLIB_test.h>
46
47 int main( void )
48 {
49     /* fsetpos() tested together with fsetpos(). */
50     return TEST_RESULTS;
51 }
52
53 #endif