Re: [PATCH] strbuf: clear errno before calling getdelim(3)
- From
René Scharfe <l.s.r@web.de>
- Date
- Aug 13, 2017, 05:51 UTC
- Message-ID
- <4bf18555-f8ea-a3f6-5204-b02bfd8f1ff9@web.de>
- In-Reply-To
- <20170813043237.ndcm77i43ivepo7b@sigill.intra.peff.net>
Am 13.08.2017 um 06:32 schrieb Jeff King:
Show 17 quoted lines
> 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.
René