Re: [PATCH 3/7] read_in_full: reset errno before reading
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 27, 2017, 04:27 UTC
- Message-ID
- <xmqqa81g7ol9.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <20170927040721.6av4o7cjrrkzizzo@sigill.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 16 quoted lines
> You actually don't need errno for that. You can write:
>
> ret = read_in_full(..., size);
> if (ret < 0)
> die_errno("oops");
> else if (ret != size)
> die("short read");
>
> So I think using errno as a sentinel value to tell between the two cases
> doesn't have much value.
> ...
> One of the reasons I dislike the helper I showed earlier is that it
> involves assembling a lego sentence. But the alternative is requiring
> the caller to write both sentences from scratch (and writing a good
> sentence for the short read really is long: you expected X bytes but got
> Y).All sensible considerations. I probably should have read the entire discussion twice before starting to type X-<. Sorry about the noise.
> Sometimes a custom "short read" message can be better, if it's "could > not read enough bytes for packfile header" or similar. You don't need to > know the exact number then.
That's true, too. I dunno, either.