X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2Fstdio%2Fclearerr.c;h=4c51d714f54aefb4c019a6b8c216bd6820d19634;hb=52e702f02142dc34a476f01ca6bf8257cc9bc7e4;hp=d54e559fe6a95dbecd241dd6a634917f61cf47f6;hpb=e5456e3c2697c4e17fc9aa3439f2e305517b4d96;p=pdclib.old diff --git a/functions/stdio/clearerr.c b/functions/stdio/clearerr.c index d54e559..4c51d71 100644 --- a/functions/stdio/clearerr.c +++ b/functions/stdio/clearerr.c @@ -1,16 +1,58 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* $Id$ */ -void clearerr( FILE * stream ) { /* TODO */ }; +/* clearerr( FILE * ) -/* PDPC code - unreviewed + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef REGTEST + +void clearerr( struct _PDCLIB_file_t * stream ) { - stream->errorInd = 0; - stream->eofInd = 0; - return; + stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG ); } -*/ + +#endif + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main( void ) +{ +#ifndef REGTEST + FILE file = { 0, { 0 }, NULL, 0, 0, 0, NULL }; + FILE * fh = &file; + TESTCASE( ! ferror( fh ) ); + TESTCASE( ! feof( fh ) ); + fh->status |= _PDCLIB_ERRORFLAG; + TESTCASE( ferror( fh ) ); + TESTCASE( ! feof( fh ) ); + clearerr( fh ); + TESTCASE( ! ferror( fh ) ); + TESTCASE( ! feof( fh ) ); + fh->status |= _PDCLIB_EOFFLAG; + TESTCASE( ! ferror( fh ) ); + TESTCASE( feof( fh ) ); + clearerr( fh ); + TESTCASE( ! ferror( fh ) ); + TESTCASE( ! feof( fh ) ); + fh->status |= _PDCLIB_EOFFLAG | _PDCLIB_ERRORFLAG; + TESTCASE( ferror( fh ) ); + TESTCASE( feof( fh ) ); + clearerr( fh ); + TESTCASE( ! ferror( fh ) ); + TESTCASE( ! feof( fh ) ); +#else + /* TODO: The above is ad-hoc and PDCLib specific. A better test driver + should be internals-agnostic (provoking the error / eof flag by + "regular" operations). + */ + TESTCASE( NO_TESTDRIVER ); +#endif + return TEST_RESULTS; +} + +#endif