On Sat, Feb 3, 2024 at 1:05 PM Chet Ramey <chet.ra...@case.edu> wrote: > > On 2/2/24 6:33 PM, Grisha Levit wrote: > > Is it necessary to check the error indicator if printf(3) just had a non- > > negative return? > > I think printf is allowed to set the error flag that ferror checks even if > it returns 0, but I could be convinced otherwise.
My reading is that fprintf can fail either: * in one of the ways that fputc or fputwc can fail (each of which set the stream error indicator if they fail) or * with EILSEQ, in which case the stream error indicator may or may not get set. (The requirement to do so is CX shaded). Neither of these seems to allow for setting the stream error indicator without also returning a negative status (while returning a negative status without setting the error indicator _is_ allowed). If we trust this to be true, we can eliminate the ferror and clearerror calls in each PF invocation. But I don't think this is likely to be a significant performance gain, so keeping it as is to stay on the safe side seems not unreasonable to me.