]> pd.if.org Git - pdclib/blob - functions/stdio/clearerr.c
Comment cleanups.
[pdclib] / functions / stdio / clearerr.c
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
11 void clearerr( struct _PDCLIB_file_t * stream )
12 {
13     stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG );
14 }
15
16 #endif
17
18 #ifdef TEST
19 #include <_PDCLIB_test.h>
20
21 int main( void )
22 {
23     FILE * fh;
24     TESTCASE( ( fh = tmpfile() ) != NULL );
25     /* Flags should be clear */
26     TESTCASE( ! ferror( fh ) );
27     TESTCASE( ! feof( fh ) );
28     /* Reading from input stream - should provoke error */
29     /* FIXME: Apparently glibc disagrees on this assumption. How to provoke error on glibc? */
30     TESTCASE( fgetc( fh ) == EOF );
31     TESTCASE( ferror( fh ) );
32     TESTCASE( ! feof( fh ) );
33     /* clearerr() should clear flags */
34     clearerr( fh );
35     TESTCASE( ! ferror( fh ) );
36     TESTCASE( ! feof( fh ) );
37     /* Reading from empty stream - should provoke EOF */
38     rewind( fh );
39     TESTCASE( fgetc( fh ) == EOF );
40     TESTCASE( ! ferror( fh ) );
41     TESTCASE( feof( fh ) );
42     /* clearerr() should clear flags */
43     clearerr( fh );
44     TESTCASE( ! ferror( fh ) );
45     TESTCASE( ! feof( fh ) );
46     TESTCASE( fclose( fh ) == 0 );
47     return TEST_RESULTS;
48 }
49
50 #endif
51