On Wed, Oct 15, 2025 at 11:50:53AM +0800, Yumei Huang wrote: > On Wed, Oct 15, 2025 at 7:28 AM 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. > > 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") -- 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