]> pd.if.org Git - pdclib/blob - functions/stdio/fflush.c
Added handling for fflush( NULL ).
[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->bufidx > stream->bufend )
26             {
27                 rc |= _PDCLIB_fflush( stream );
28             }
29             stream = stream->next;
30         }
31         return rc;
32     }
33     else
34     {
35         return _PDCLIB_fflush( stream );
36     }
37 }
38                 
39 #endif
40
41 #ifdef TEST
42 #include <_PDCLIB_test.h>
43
44 int main( void )
45 {
46     TESTCASE( NO_TESTDRIVER );
47     return TEST_RESULTS;
48 }
49
50 #endif
51