Subject: Re: scan_ffs from OpenBSD ported and improved.
To: None <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 06/07/2005 04:38:15
>> I hope that in all the non-void cases ferror() is called after
>> printing, but my guess is that it isn't.
> You need to check ferror() after fflush(), not fprintf().

Actually, you need to check both - errors can occur during fprintf as
well as fflush, especially if you're printing voluminous output or
happen to be talking to a less-than-block-buffered stream.

And it's not just the cases without a cast to (void).  All casting the
return value to void does is shut up "return value is ignored" whines
from lint and its ilk; it doesn't magically introduce error checking.

If you need to trap error conditions in stdio output, you need to

(1a) check the return values from printf() (and fprintf, et al), *and*
(1b) check the return value wherever you fflush(), *or*
(2) check every now and then with ferror().

Method (2) lets you locate the error only to the granularity with which
you call ferror(), but is (usually) significantly less code.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B