From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS53758 23.128.96.0/24 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 781931F8C6 for ; Tue, 31 Aug 2021 10:40:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241139AbhHaKic (ORCPT ); Tue, 31 Aug 2021 06:38:32 -0400 Received: from cloud.peff.net ([104.130.231.41]:34816 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241081AbhHaKiF (ORCPT ); Tue, 31 Aug 2021 06:38:05 -0400 Received: (qmail 5782 invoked by uid 109); 31 Aug 2021 10:37:10 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Tue, 31 Aug 2021 10:37:10 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 22697 invoked by uid 111); 31 Aug 2021 10:37:09 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Tue, 31 Aug 2021 06:37:09 -0400 Authentication-Results: peff.net; auth=none Date: Tue, 31 Aug 2021 06:37:09 -0400 From: Jeff King To: Jacob Vosmaer Cc: gitster@pobox.com, me@ttaylorr.com, git@vger.kernel.org, ps@pks.im Subject: Re: [PATCH v3 1/2] pkt-line: add stdio packet write functions Message-ID: References: <20210831093444.28199-1-jacob@gitlab.com> <20210831093444.28199-2-jacob@gitlab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210831093444.28199-2-jacob@gitlab.com> Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On Tue, Aug 31, 2021 at 11:34:43AM +0200, Jacob Vosmaer wrote: > +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