> From: Stephen Hemminger [mailto:step...@networkplumber.org]
> Sent: Monday, 9 June 2025 17.26
> 
> On Mon,  9 Jun 2025 14:42:26 +0000
> Morten Brørup <m...@smartsharesystems.com> wrote:
> 
> > @@ -141,8 +141,13 @@ rte_mem_page_size(void)
> >  {
> >     static size_t page_size;
> >
> > -   if (!page_size)
> > +   if (page_size == 0) {
> > +           errno = 0; /* man sysconf(3) */
> >             page_size = sysconf(_SC_PAGESIZE);
> > +           if ((ssize_t)page_size < 0)
> > +                   rte_panic("sysconf(_SC_PAGESIZE) failed: %s",
> > +                                   errno == 0 ? "Indeterminate" :
> strerror(errno));
> > +   }
> 
> Why not make page_size a ssize_t or long?
> The return value of sysconf is long.

I guess it's a matter of preference...
This function returns size_t, i.e. an unsigned type. So I kept page_size (the 
cached return value) the same type, and put the type cast in the unlikely code 
path.
The alternative, changing page_size to a signed type (ssize_t or long), would 
require casting to an unsigned type in the return statement.

> Not sure if setting errno to zero is required, sysconf only touchs it if
> return value is negative.

The Linux man sysconf(3) page recommends setting errno to zero before calling 
sysconf(), so errno can be used to discriminate between actual errors and an 
indeterminate value when sysconf() returns -1.
Hence the "man sysconf(3)" comment.
BSD sysconf(3) behaves the same way, but the BSD man page is less explicit 
about setting errno to zero.

Reply via email to