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=r7Yst9Ms; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 2FE0C5A026F for ; Wed, 15 Oct 2025 06:46:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202510; t=1760503575; bh=Gm9RYB34dIK93YmEEgAHGS6EnCxC6Xqb/o/GJFAFhts=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=r7Yst9MsKVyFnCTWwMLvtsaFOAh9BypPjvRD9YtYPVnYRgzeQgL0ivmWF7qnneB34 RnDqUK0UhqWeUvgFEhUn27qIxz78mEPqX0nsa1MkdsWJIlc1Goqjh2gKBoCy4P+UXQ p+ktf1/5hBeAniDc9CJe9DxH6lP6civUWbSqyWQv77nr7vIIz7m8Lo7ffcu3qFIHBD er588jADUggPQoDUnSzHymrtZt+JaK5XbXZb0a90L87VxJOEH+PZOSvYMz2U5kVEI7 q3fVTN59nHe4E9iPYFuOkai5cFOqRDymK4DdiwJ+PKYMkJ1hqP56oxADFiCHhkpJ3k YVIYvflPrgb/A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4cmdnz655Lz4wB4; Wed, 15 Oct 2025 15:46:15 +1100 (AEDT) Date: Wed, 15 Oct 2025 15:46:12 +1100 From: David Gibson To: Yumei Huang Subject: Re: [PATCH v3 2/4] util: Introduce read_file() and read_file_long() function Message-ID: References: <20251014073836.18150-1-yuhuang@redhat.com> <20251014073836.18150-3-yuhuang@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ib4HIpgMqLFAHvLv" Content-Disposition: inline In-Reply-To: Message-ID-Hash: G2JEN2TFHA2NFV3R2D7UCC7HTPIRGNIQ X-Message-ID-Hash: G2JEN2TFHA2NFV3R2D7UCC7HTPIRGNIQ 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: passt-dev@passt.top, sbrivio@redhat.com 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: --ib4HIpgMqLFAHvLv Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 15, 2025 at 11:50:53AM +0800, Yumei Huang wrote: > On Wed, Oct 15, 2025 at 7:28=E2=80=AFAM David Gibson > wrote: > > On Tue, Oct 14, 2025 at 03:38:34PM +0800, Yumei Huang wrote: > > > Signed-off-by: Yumei Huang [snip] > > > + * @path: Path to the sysctl file > > > + * @fallback: Default value if file can't be read > > > + * > > > + * Return: Parameter value, fallback on failure > > > +*/ > > > +long read_file_long(const char *path, long fallback) > > > +{ > > > + char buf[32]; > > > > Rather than just using a semi-arbitrary 32 here, I'd suggest defining > > a new constant similar to UINT16_STRLEN. Except that's trickier for a > > type that doesn't have a known fixed width. Pity the C library > > doesn't have constants for these AFAICT. >=20 > I will just define a UINTMAX_STRLEN with (sizeof("2147483647")). That's not quite right. - It should be INTMAX_STRLEN (signed), UINTMAX would be for the unsigned version - That assumes intmax_t is 32-bit which is probably not the case (it will be 64-bit, maybe even 128-bit on modern systems) - For signed cases, it's the minimum (negative) value that gives the longest possible string (for 32-bit, "-2147483648") --=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 --ib4HIpgMqLFAHvLv Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmjvJxMACgkQzQJF27ox 2GfPTw/9EZ+G3VoxVE9HO0YYly/sc9LaxKlsnjep4H7Z95/ZhE/1WC8xyQkXrBCM nYGOEnrHnJDTRUxwdWV+rHOcILJVtbFLFzB3rv5APA08wV4y6unAUn3HjGfw8K3b 0rI2Rx18pzCTI0wdV2leSy4vSqOw/ckKrT8QZ1y3Kwknw38088u85u1SoWi8zDmP 1xW5fvDUfYvOdJ50iJQU14QmPuXSpmMxQsdnZsc1ZDsysfzh0NRH4CwRBTU6RCE2 J27bfM3ScfTAcT2Rc0IH7MRUyIMaHsQfUxZalq1hDzWi9OytUkor6zaL/q6lRfeg QmLswvIYOV+G2qqVZOYn4FmHsaqzq13hLdFr68eHctQZn6oHz0oglB2VVYoDM2aO 2KcTXCEq21yQNu6/WgwG2DWlOu21yxMhKM5knLXtxsZN0BMQgpsaMQwzC3OSKGXR deaspFhdHhV3jrykYjtg+Kx0wzpC0wJC7TMnGSXrBxbnfce6auIjup3Ndk0qaysC g1V0rXUP6t3ov1HtJeJqHk5uNASNb2/Lnvb9RzSVUyL/2bXy2rIpcLL73MvXzNWt iBCzFDTSCbOZIFLAPhJ7FTeZB3dKPSfUB6Ir1r/+gWcAig3hjZhYHR+7UM/kKXqx g5VUnOMvTXkpfovy1X8pI1Qlg2h6EyWljJoWLPikHoi/WfQhvAE= =LGAV -----END PGP SIGNATURE----- --ib4HIpgMqLFAHvLv--