Re: [PATCH] strbuf: clear errno before calling getdelim(3)
- From
Jeff King <peff@peff.net>
- Date
- Aug 13, 2017, 05:58 UTC
- Message-ID
- <20170813055853.vrrfot3ijrpjk2rv@sigill.intra.peff.net>
- In-Reply-To
- <4bf18555-f8ea-a3f6-5204-b02bfd8f1ff9@web.de>
On Sun, Aug 13, 2017 at 07:51:34AM +0200, René Scharfe wrote:
Show 23 quoted lines
> Am 13.08.2017 um 06:32 schrieb Jeff King:
> > On Sat, Aug 12, 2017 at 01:57:06PM +0200, René Scharfe wrote:
> >
> >> But we probably want to check for other errors. They look unlikely
> >> enough that we may get away with something like this:
> >>
> >> - if (errno == ENOMEM)
> >> - die("Out of memory, getdelim failed");
> >> + if (errno || ferror(fp))
> >> + die_errno(_("getdelim failed"));
> >>
> >> NB: The other errors are EINVAL (input pointers are NULL or the
> >> stream is invalid) and EOVERFLOW (read more than fits into ssize_t)
> >> according to POSIX and the Linux manpage.
> >
> > Can't we also get any of the errors that fgetc() would return. I.e., any
> > normal read errors? We should return EOF on those, not die (and the
> > caller can check ferror()).
>
> Yes, we can get those as well, and leaving error checking to the caller
> is a flexible way to handle them.
>
> Many of the existing callers don't seem to be bother, though.Yes, but keep in mind that we need to match the non-getdelim() implementation here (which itself tries to behave like more or less like a dynamic fgets, including the eof/error handling). Because the callers don't know which one they're getting.
-Peff