Re: [PATCH v3 1/2] pkt-line: add stdio packet write functions
- From
Jeff King <peff@peff.net>
- Date
- Aug 31, 2021, 10:37 UTC
- Message-ID
- <YS4GVWdsnRqpM+4y@coredump.intra.peff.net>
- In-Reply-To
- <20210831093444.28199-2-jacob@gitlab.com>
On Tue, Aug 31, 2021 at 11:34:43AM +0200, Jacob Vosmaer wrote:
Show 5 quoted lines
> +void fwrite_or_die(FILE *f, const void *buf, size_t count)
> +{
> + if (fwrite(buf, count, 1, f) != 1)
> + die_errno("fwrite error");
> +}One small oddity I noticed. The definition of fwrite is fwrite(ptr, size, nmemb, strea), where we write "nmemb" items of "size" bytes each. I'd argue we're writing "count" single bytes, so it should be:
if (fwrite(buf, 1, count, f) != count)
This matters a lot for fread(), where any read shorter than "count" (e.g., due to EOF) would return "0" rather than a partial result. But I have a hard time imagining an implementation of fwrite() where the distinction would matter. And grepping around, we seem to have both forms in our code base already. So it's probably fine.
-Peff