[PATCH v3 02/29] Prepare for the addition of the <sys/pagesize.h> header

Paul Eggert eggert@cs.ucla.edu
Wed Oct 2 03:46:42 GMT 2024


On 2024-10-01 15:54, Florian Weimer wrote:

> We already have __extern_inline in <sys/cdefs.h> for that.

Thanks, didn't know that.


> The tricky part is that we want to tell GCC that sysconf (_SC_PAGE_SIZE)
> is a constant, but sysconf in general is not __attribute__
> ((__const__)).  The easiest way to implement that is to call
> __getpagesize, which has the right attribute.  The patch doesn't
> implement that, though.

Can we do something like the following to make sysconf (_SC_PAGESIZE) 
effectively const?

   #ifdef __extern_always_inline
   __extern_always_inline __attribute_const__ long int
   __glibc_sysconf_const (int __name)
   {
     return sysconf (__name);
   }

   # define sysconf(name) \
      ((__builtin_constant_p (name) \
        && ((name) == _SC_PAGESIZE || (name) == _SC_RE_DUP_MAX)) \
       ? __glibc_sysconf_const (name) \
       : sysconf (name))
   #endif

Of course add any other relevant _SC_... values to the disjunct.


More information about the Libc-alpha mailing list