Path: blob/master/waterbox/libc/functions/stdio/clearerr.c
2 views
/* clearerr( FILE * )12This file is part of the Public Domain C Library (PDCLib).3Permission is granted to use, modify, and / or redistribute at will.4*/56#include <stdio.h>78#ifndef REGTEST9#include "_PDCLIB_io.h"1011void _PDCLIB_clearerr_unlocked( FILE * stream )12{13stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG );14}1516void clearerr( FILE * stream )17{18_PDCLIB_flockfile( stream );19_PDCLIB_clearerr_unlocked( stream );20_PDCLIB_funlockfile( stream );21}2223#endif2425#ifdef TEST26#include "_PDCLIB_test.h"2728int main( void )29{30FILE * fh;31TESTCASE( ( fh = tmpfile() ) != NULL );32/* Flags should be clear */33TESTCASE( ! ferror( fh ) );34TESTCASE( ! feof( fh ) );35/* Reading from input stream - should provoke error */36/* FIXME: Apparently glibc disagrees on this assumption. How to provoke error on glibc? */37TESTCASE( fgetc( fh ) == EOF );38TESTCASE( ferror( fh ) );39TESTCASE( ! feof( fh ) );40/* clearerr() should clear flags */41clearerr( fh );42TESTCASE( ! ferror( fh ) );43TESTCASE( ! feof( fh ) );44/* Reading from empty stream - should provoke EOF */45rewind( fh );46TESTCASE( fgetc( fh ) == EOF );47TESTCASE( ! ferror( fh ) );48TESTCASE( feof( fh ) );49/* clearerr() should clear flags */50clearerr( fh );51TESTCASE( ! ferror( fh ) );52TESTCASE( ! feof( fh ) );53TESTCASE( fclose( fh ) == 0 );54return TEST_RESULTS;55}5657#endif58596061