[PATCH] Core: use sysconf(_SC_PAGESIZE) instead of getpagesize()

Maxim Dounin mdounin at mdounin.ru
Fri Dec 4 12:19:37 UTC 2015


Hello!

On Thu, Dec 03, 2015 at 07:24:51PM -0800, Piotr Sikora wrote:

> Hey Maxim,
> 
> > Any practical reasons for the change?
> 
> Kind of... OS X doesn't expose getpagesize() when it's compiled with
> _POSIX_C_SOURCE >= 200112L and no other define (not even
> _DARWIN_C_SOURCE) can change that.
> 
> Side note: I considered adding _DARWIN_C_SOURCE to
> ngx_darwin_config.h, like it's done for _GNU_SOURCE, but I decided
> against it, because I found the ability to enforce strict POSIX
> interface (even if it doesn't really work right now) quite handy...
> and it's off by default, so someone needs to force it anyway.

So the real reason for the change is that you are trying to define 
_POSIX_C_SOURCE for some unknown reason, and it breaks things, 
right?

I suspect there are lots of things that will be broken by defining 
_POSIX_C_SOURCE, and there should be really good reason to define 
it.

> > While getpagesize() isn't required by the current issue of POSIX,
> > it is easier to use and used to be more widely available than
> > sysconf(_SC_PAGESIZE).
> 
> Considering that sysconf(_SC_PAGESIZE) is part of POSIX and
> getpagesize() isn't, I don't believe this is true anymore.

AFAIK, _SC_PAGESIZE is not available on HP-UX.  Though I have no 
access to one now to test.

> > The cast looks unneeded.
> 
> It's signed-to-unsigned conversion... it's a little bit on the
> pedantic side, but I wouldn't say it's unneeded... and it follows
> style from similar cast just few lines below.

Signed-to-unsigned conversion is perfectly defined in C for all 
possible values.  The cast below is unknown-to-signed, which can 
overflow with undefined result, and thus in some cases causes 
warnings.  General approach is to only add casts where they are 
needed, that is, where otherwise the behaviour will be wrong 
and/or a warning will be generated.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx-devel mailing list