Ian Collins
8/12/2008 8:16:00 AM
Richard Heathfield wrote:
> And so was mine. Yours was a much simpler suggestion, but I'm at a loss to
> know how you're supposed to get it to work except by deliberately breaking
> the code you're trying to test. Could you explain more fully what you were
> getting at, please?
>
Well I have to admit that on my normal development platform (Solaris) I
would take advantage of the fact that library functions are week symbols
and simply provide my own ferror().
On less accommodating systems, I had assumed the OP would have something
like:
int writeFile( FILE* stream )
{
if (ferror(stream))
{
// ... I should be able to test the code here.
//
printf( "%s\n", strerror( ferror( stream )) );
return someError;
}
// Normal processing.
//
return OK;
}
The error path could be tested with:
int main(void)
{
FILE* f = fopen( "someFile", "w" );
char buf;
fread( &buf, 1, 1, f );
writeFile( f );
}
--
Ian Collins.