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

Piotr Sikora piotrsikora at google.com
Fri Dec 4 22:43:11 UTC 2015


Hey Maxim,

> 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.

I want to be able to compile nginx as a strictly conforming POSIX
application, which doesn't depend on any GNU-ism and/or BSD-ism. For
me, this is a really good reason, especially when virtually all
operating systems support defining _POSIX_C_SOURCE and/or
_XOPEN_SOURCE for exactly this purpose.

Yes, getpagesize() isn't the only thing that breaks when enforcing
strict POSIX compliance, but it's a low-hanging fruit and it's the
only thing that breaks build on OS X when compiling with
-D_POSIX_C_SOURCE=200809L -D_DARWIN_C_SOURCE.

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

I would be surprised if that's the case, considering that HP-UX is one
of the few UNIX03-certified operating systems.

> 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.

I never said it's undefined. However, it's an error, when you try to
be strict enough:

error: implicit conversion changes signedness: 'long' to 'ngx_uint_t'
(aka 'unsigned long') [-Werror,-Wsign-conversion]
    ngx_pagesize = value;
                 ~ ^~~~~
1 error generated.

(But that's a moot point, since nginx breaks all over the place with
-Wconversion).

Feel free to drop the cast from the change, if you ever decide it's
worth committing.

Best regards,
Piotr Sikora



More information about the nginx-devel mailing list