From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202510 header.b=BBEQIo7o; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id A92FC5A061E for ; Fri, 14 Nov 2025 05:32:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202510; t=1763094763; bh=6gqcYqe/YXaBzbvHxITJHY+Pr82bJv7bjHvx7UNssXM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BBEQIo7oOEowx4WGBktwrKFO+MsBqY7f9oPKz8AA9cVrLAOLE1dlGFJWIVQn46hoa IDTPNHPBaPwej3JmPwjvJ2UEPS9WJiWIo5jEBwRXOJtZL/1ARO6zgEILTe/gk5kloe SX/9kn6P7Cc68stgPF19f7qn9J5/GijD1o9pqn3vRyLJ7q2niB/+APlk59kOtZJUsc LpNlS/2SsGPBvi5ePvFZYITlKx1sTuurb3AFEvatUerET2j8imS3PMEr81iCfRF2H0 ntR3bC9nelB7c0fEk2V43A++H3Pw/VJog4lVM/gdXjXWe4BOA8/0nPnOWNgBtQwIYL sSZqJvJZ8FTPQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4d744W5dcGz4wD3; Fri, 14 Nov 2025 15:32:43 +1100 (AEDT) Date: Fri, 14 Nov 2025 15:32:39 +1100 From: David Gibson To: Yumei Huang Subject: Re: [PATCH v8 2/6] util: Introduce read_file() and read_file_integer() function Message-ID: References: <20251110093137.87705-1-yuhuang@redhat.com> <20251110093137.87705-3-yuhuang@redhat.com> <20251114010134.6a79cb30@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="yCN/DInFDw7qP3Jm" Content-Disposition: inline In-Reply-To: Message-ID-Hash: VFSZIG77WBPFDGRZRENZ7QOLRZQFXJ5J X-Message-ID-Hash: VFSZIG77WBPFDGRZRENZ7QOLRZQFXJ5J X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Stefano Brivio , passt-dev@passt.top X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --yCN/DInFDw7qP3Jm Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Nov 14, 2025 at 09:58:57AM +0800, Yumei Huang wrote: > On Fri, Nov 14, 2025 at 8:01=E2=80=AFAM Stefano Brivio wrote: > > > > On Mon, 10 Nov 2025 17:31:33 +0800 > > Yumei Huang wrote: > > > > > Signed-off-by: Yumei Huang > > > Reviewed-by: David Gibson > > > --- > > > util.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++ > > > util.h | 2 ++ > > > 2 files changed, 88 insertions(+) > > > > > > diff --git a/util.c b/util.c > > > index 44c21a3..c4c849c 100644 > > > --- a/util.c > > > +++ b/util.c > > > @@ -590,6 +590,92 @@ int write_file(const char *path, const char *buf) > > > return len =3D=3D 0 ? 0 : -1; > > > } > > > > > > +/** > > > + * read_file() - Read contents of file into a NULL-terminated buffer > > > + * @path: Path to file to read > > > + * @buf: Buffer to store file contents > > > + * @buf_size: Size of buffer > > > + * > > > + * Return: number of bytes read on success, -1 on error, -ENOBUFS on= truncation > > > + */ > > > +ssize_t read_file(const char *path, char *buf, size_t buf_size) > > > +{ > > > + int fd =3D open(path, O_RDONLY | O_CLOEXEC); > > > + size_t total_read =3D 0; > > > + ssize_t rc; > > > + > > > + if (fd < 0) { > > > + warn_perror("Could not open %s", path); > > > + return -1; > > > + } > > > + > > > + while (total_read < buf_size) { > > > + rc =3D read(fd, buf + total_read, buf_size - total_read= ); > > > > cppcheck rightfully says that: > > > > util.c:604:10: style: The scope of the variable 'rc' can be reduced. [v= ariableScope] > > ssize_t rc; > > ^ >=20 > Right. > Seems it also says: >=20 > tcp.c:2814:0: style: The function 'tcp_get_rto_params' should have > static linkage since it is not used outside of its translation unit. > [staticFunction] > void tcp_get_rto_params(struct ctx *c) > ^ Ah, yes, that should be 'static'. Sorry, missed that in earlier reviews. > util.c:601:0: style: The function 'read_file' should have static > linkage since it is not used outside of its translation unit. > [staticFunction] > ssize_t read_file(const char *path, char *buf, size_t buf_size) >=20 > I understand read_file() may be called from other places in the > future. But do we need to add static now? I guess we need it for > tcp_get_rto_params(). It's true that read_file() might be used elsewhere in future. I'd still make it 'static' for now, and we can change that if/when we use it somewhere else. --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --yCN/DInFDw7qP3Jm Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmkWsOYACgkQzQJF27ox 2GfqlA//cZrVoJuRgFQawmYuTmP6BL1RLC6S7YyaLld8yO9+XL0Yhugo0U3y5EcX iS0Q0x8Lcx/PhxUDaasL17xm2+p0UAcNpzK5FYfoY+lZlUdTff2kM+tPUZvjHe99 sZBLVucKcHqPJ0jA14pKRi1Dz73X446pv843YZ9RcuYzrxBTsX/YiPqehPJi+QLm A2dGsYTKrR8DeSNE9i+Wae3ggmq9GHa3xvzMLHOZ1tJxlE8SAYZ4Un+ISt57EbWX 3qR8pUwnjJBJYJswhg0g/BLrZJ9ifqzj597OY0eUpfu+RqdIrD0AwM3lf7tx3ydP Ep9M+95StvWD+J8zcznAbBcoh69Mvz7qeirZMTB7xsGUpzTwEk9RDhPG693iX8E+ IqU/+e28LSFkBUSTMg4PxdXqRsiB/2L4zwBOdggpQQOU+U9/rrbkK6sZR/5Ql5VC GigFHOVCzRhiGG11uGNYNBFB294rwQ3cud6aycEUvlTEU+VK5lZgCwNgpVHsaS+P v630Qs0myrBqxrX7H/SCzOy3CX5EOYN7WKvRaMEBsYtf35SGaYVGlFQ8T1su5JmL nbWlP1F/4woakVuPFMD5clFsjSBPjPyedzaXBtk4j1PNZjj9XxTOwX07yzW7wloh +DgSabJ+DVkGlARTLXep9t0S5OqyOWT7AUc+Sr8Siy2WwF2E5Yc= =Xglw -----END PGP SIGNATURE----- --yCN/DInFDw7qP3Jm--