Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdio/clearerr.c
2 views
1
/* clearerr( 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
void _PDCLIB_clearerr_unlocked( FILE * stream )
13
{
14
stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG );
15
}
16
17
void clearerr( FILE * stream )
18
{
19
_PDCLIB_flockfile( stream );
20
_PDCLIB_clearerr_unlocked( stream );
21
_PDCLIB_funlockfile( stream );
22
}
23
24
#endif
25
26
#ifdef TEST
27
#include "_PDCLIB_test.h"
28
29
int main( void )
30
{
31
FILE * fh;
32
TESTCASE( ( fh = tmpfile() ) != NULL );
33
/* Flags should be clear */
34
TESTCASE( ! ferror( fh ) );
35
TESTCASE( ! feof( fh ) );
36
/* Reading from input stream - should provoke error */
37
/* FIXME: Apparently glibc disagrees on this assumption. How to provoke error on glibc? */
38
TESTCASE( fgetc( fh ) == EOF );
39
TESTCASE( ferror( fh ) );
40
TESTCASE( ! feof( fh ) );
41
/* clearerr() should clear flags */
42
clearerr( fh );
43
TESTCASE( ! ferror( fh ) );
44
TESTCASE( ! feof( fh ) );
45
/* Reading from empty stream - should provoke EOF */
46
rewind( fh );
47
TESTCASE( fgetc( fh ) == EOF );
48
TESTCASE( ! ferror( fh ) );
49
TESTCASE( feof( fh ) );
50
/* clearerr() should clear flags */
51
clearerr( fh );
52
TESTCASE( ! ferror( fh ) );
53
TESTCASE( ! feof( fh ) );
54
TESTCASE( fclose( fh ) == 0 );
55
return TEST_RESULTS;
56
}
57
58
#endif
59
60
61