Re: [PATCH] tempfile: avoid "ferror | fclose" trick
- From
Jeff King <peff@peff.net>
- Date
- Feb 17, 2017, 20:54 UTC
- Message-ID
- <20170217205442.wnldfsxbj3dnnqvj@sigill.intra.peff.net>
- In-Reply-To
- <64eedabd-c0de-a7e0-8d98-ad23a9625b45@alum.mit.edu>
On Fri, Feb 17, 2017 at 11:42:25AM +0100, Michael Haggerty wrote:
Show 13 quoted lines
> On 02/17/2017 09:07 AM, Jeff King wrote: > > [...] > > That's similar to what I wrote earlier, but if we don't mind overwriting > > errno unconditionally, I think just: > > > > errno = EIO; /* covers ferror(), overwritten by failing fclose() */ > > err |= ferror(fp); > > err |= fclose(fp); > > > > does the same thing. > > True; I'd forgotten the convention that non-failing functions are > allowed to change errno. Your solution is obviously simpler and faster.
I guess we are simultaneously assuming that it is OK to munge errno on success in our function, but that fclose() will not do so. Which seems a bit hypocritical. Maybe the "if" dance is better.
-Peff