]> pd.if.org Git - pdclib.old/blob - functions/stdio/fflush.c
[gandr] s/__lp64__/__LP64__/ to match GCC define
[pdclib.old] / functions / stdio / fflush.c
1 /* $Id$ */
2
3 /* fflush( FILE * )
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 extern FILE * _PDCLIB_filelist;
15
16 int _PDCLIB_fflush_unlocked( FILE * stream )
17 {
18     if ( stream == NULL )
19     {
20         stream = _PDCLIB_filelist;
21         /* TODO: Check what happens when fflush( NULL ) encounters write errors, in other libs */
22         int rc = 0;
23         while ( stream != NULL )
24         {
25             if ( stream->status & _PDCLIB_FWRITE )
26             {
27                 if ( _PDCLIB_flushbuffer( stream ) == EOF )
28                 {
29                     rc = EOF;
30                 }
31             }
32             stream = stream->next;
33         }
34         return rc;
35     }
36     else
37     {
38         return _PDCLIB_flushbuffer( stream );
39     }
40 }
41
42 int fflush( FILE * stream )
43 {
44     _PDCLIB_flockfile( stream );
45     int res = _PDCLIB_fflush_unlocked(stream);
46     _PDCLIB_funlockfile( stream );
47     return res;
48 }
49                 
50 #endif
51
52 #ifdef TEST
53 #include <_PDCLIB_test.h>
54
55 int main( void )
56 {
57     /* Testing covered by ftell.c */
58     return TEST_RESULTS;
59 }
60
61 #endif
62