]> pd.if.org Git - pdclib/blob - functions/stdio/fflush.c
b8d32ec307d45b389d3a0fa37fb79263998e9f16
[pdclib] / 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_glue.h>
13
14 extern struct _PDCLIB_file_t * _PDCLIB_filelist;
15
16 int fflush( struct _PDCLIB_file_t * 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 #endif
43
44 #ifdef TEST
45 #include <_PDCLIB_test.h>
46
47 int main( void )
48 {
49     /* Testing covered by ftell.c */
50     return TEST_RESULTS;
51 }
52
53 #endif
54