From: Stefano Brivio <sbrivio@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: Yumei Huang <yuhuang@redhat.com>, passt-dev@passt.top
Subject: Re: [PATCH v3 2/4] util: Introduce read_file() and read_file_long() function
Date: Wed, 29 Oct 2025 00:12:48 +0100 [thread overview]
Message-ID: <20251029001248.09193eb4@elisabeth> (raw)
In-Reply-To: <aO8nFGkti0y4R1yS@zatzit>
On Wed, 15 Oct 2025 15:46:12 +1100
David Gibson <david@gibson.dropbear.id.au> wrote:
> On Wed, Oct 15, 2025 at 11:50:53AM +0800, Yumei Huang wrote:
> > On Wed, Oct 15, 2025 at 7:28 AM David Gibson
> > <david@gibson.dropbear.id.au> wrote:
> > > On Tue, Oct 14, 2025 at 03:38:34PM +0800, Yumei Huang wrote:
> > > > Signed-off-by: Yumei Huang <yuhuang@redhat.com>
> [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.
> >
> > 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")
By the way, while it doesn't cover intmax_t explicitly, I think this is
a pretty good resource as it covers most architectures supported by the
Linux kernel (hence, most architectures we support):
https://wiki.debian.org/ArchitectureSpecificsMemo#Summary
and judging from intmax_t(3type) I'd say that the sizeof(long double)
column tells you how big intmax_t is.
Well, at least, that's the page I use to know which architectures I can
use to check things when I suspect a type portability bug.
That's because 'long double' should always be the biggest "native" data
type, that is, excluding __int128 or vectorised / SIMD types such as
__m256i.
--
Stefano
next prev parent reply other threads:[~2025-10-28 23:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-14 7:38 [PATCH v3 0/4] Retry SYNs for inbound connections Yumei Huang
2025-10-14 7:38 ` [PATCH v3 1/4] tcp: Rename "retrans" to "retries" Yumei Huang
2025-10-14 22:50 ` David Gibson
2025-10-15 2:17 ` Yumei Huang
2025-10-14 7:38 ` [PATCH v3 2/4] util: Introduce read_file() and read_file_long() function Yumei Huang
2025-10-14 23:27 ` David Gibson
2025-10-15 3:50 ` Yumei Huang
2025-10-15 4:46 ` David Gibson
2025-10-15 5:46 ` Yumei Huang
2025-10-28 23:12 ` Stefano Brivio [this message]
2025-10-29 0:43 ` David Gibson
2025-10-29 4:43 ` Stefano Brivio
2025-10-29 9:35 ` David Gibson
2025-10-29 16:23 ` Stefano Brivio
2025-10-14 7:38 ` [PATCH v3 3/4] tcp: Resend SYN for inbound connections Yumei Huang
2025-10-14 23:40 ` David Gibson
2025-10-14 7:38 ` [PATCH v3 4/4] tcp: Update data retransmission timeout Yumei Huang
2025-10-15 0:05 ` David Gibson
2025-10-15 6:31 ` Yumei Huang
2025-10-15 22:54 ` David Gibson
2025-10-17 18:28 ` Stefano Brivio
2025-10-20 0:20 ` David Gibson
2025-10-20 5:11 ` Stefano Brivio
2025-10-20 9:17 ` David Gibson
2025-10-28 23:13 ` Stefano Brivio
2025-10-29 0:35 ` David Gibson
2025-10-29 4:52 ` Stefano Brivio
2025-10-29 9:37 ` David Gibson
2025-10-20 10:57 ` Yumei Huang
2025-10-20 23:20 ` Stefano Brivio
2025-10-22 2:23 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251029001248.09193eb4@elisabeth \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=yuhuang@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).