Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdio/fflush.c
2 views
1
/* fflush( FILE * )
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
extern FILE * _PDCLIB_filelist;
13
14
int _PDCLIB_fflush_unlocked( FILE * stream )
15
{
16
if ( stream == NULL )
17
{
18
stream = _PDCLIB_filelist;
19
/* TODO: Check what happens when fflush( NULL ) encounters write errors, in other libs */
20
int rc = 0;
21
while ( stream != NULL )
22
{
23
if ( stream->status & _PDCLIB_FWRITE )
24
{
25
if ( _PDCLIB_flushbuffer( stream ) == EOF )
26
{
27
rc = EOF;
28
}
29
}
30
stream = stream->next;
31
}
32
return rc;
33
}
34
else
35
{
36
return _PDCLIB_flushbuffer( stream );
37
}
38
}
39
40
int fflush( FILE * stream )
41
{
42
_PDCLIB_flockfile( stream );
43
int res = _PDCLIB_fflush_unlocked(stream);
44
_PDCLIB_funlockfile( stream );
45
return res;
46
}
47
48
#endif
49
50
#ifdef TEST
51
#include "_PDCLIB_test.h"
52
53
int main( void )
54
{
55
/* Testing covered by ftell.c */
56
return TEST_RESULTS;
57
}
58
59
#endif
60
61
62