Problems with default _POSIX_C_SOURCE in features.h ??
Adhemerval Zanella
adhemerval.zanella@linaro.org
Thu Mar 28 18:56:00 GMT 2019
On 26/03/2019 17:28, Chris Hall wrote:
>
> features.h (in glibc 2.29, 31-Jan-2019) includes:
> ______________________________________________________________________
> /* If none of the ANSI/POSIX macros are defined, or if _DEFAULT_SOURCE
> Â Â is defined, use POSIX.1-2008 (or another version depending on
>   _XOPEN_SOURCE). */
> #ifdef _DEFAULT_SOURCE
> # if !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE
> #Â define __USE_POSIX_IMPLICITLYÂ Â Â 1
> # endif
> # undef _POSIX_SOURCE
> # define _POSIX_SOURCEÂ Â Â 1
> # undef _POSIX_C_SOURCE
> # define _POSIX_C_SOURCEÂ Â Â 200809L
> #endif
>
> #if ((!defined __STRICT_ANSI__Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â \
> Â Â Â Â Â || (defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 500))Â Â Â \
> Â Â Â Â && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE)
> # define _POSIX_SOURCEÂ Â Â 1
> # if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 500
> #Â define _POSIX_C_SOURCEÂ Â Â 2
> # elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 600
> #Â define _POSIX_C_SOURCEÂ Â Â 199506L
> # elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 700
> #Â define _POSIX_C_SOURCEÂ Â Â 200112L
> # else
> #Â define _POSIX_C_SOURCEÂ Â Â 200809L
> # endif
> # define __USE_POSIX_IMPLICITLYÂ Â Â 1
> #endif
> ______________________________________________________________________
>
> But this does not do what the comment says it does :-(
>
> If _DEFAULT_SOURCE is defined, but neither POSIX_SOURCE nor
> _POSIX_C_SOURCE are defined, this sets _POSIX_C_SOURCEÂ Â Â 200809L,
> no matter what _XOPEN_SOURCE is.
>
> Bug #1 ??
I think the issue is the comment itself, since on glibc doc it states:
manual/creature.texi
219 @defvr Macro _DEFAULT_SOURCE
220 @standards{GNU, (none)}
221 If you define this macro, most features are included apart from
222 X/Open, LFS and GNU extensions: the effect is to enable features from
223 the 2008 edition of POSIX, as well as certain BSD and SVID features
224 without a separate feature test macro to control them.
So my understanding is the intentio of _DEFAULT_SOURCE is indeed to
support current POSIX 2008 (or the latest release) regardless of the
_XOPEN_SOURCE value.
>
>
> Further on in features.h we have:
> _______________________________________________________________________
> #if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 2 || \
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â defined _XOPEN_SOURCE
> # define __USE_POSIX2Â Â 1
> #endif
>
> #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199309L
> # define __USE_POSIX199309Â 1
> #endif
>
> #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199506L
> # define __USE_POSIX199506Â 1
> #endif
> _______________________________________________________________________
>
> If, say, _XOPEN_SOURCE == 500 the rules say that it is not necessary to define _POSIX_SOURCE or _POSIX_C_SOURCE, but whatever they are set to, the effect as if _POSIX_C_SOURCE == 199506L (except that if _POSIX_C_SOURCE > 199506L, where the effect is undefined).
>
> Should one or both of __USE_POSIX199309 and __USE_POSIX199506 be set if _XOPEN_SOURCE == 500 ?
My understanding is __USE_POSIX199309 refers internally to POSIX.1b Real-time
extensions and __USE_POSIX199506 to POSIX.1c Threads extensions. Their support
are orthogonal and my understanding if since glibc supports both I see no reason
to not advertise them for _XOPEN_SOURCE == 500.
>
> Bug #2 ??
>
>
> In cases where _POSIX_C_SOURCE is bigger than expected for the given _XOPEN_SOURCE the result does seem to be a mess -- but, hey, the standard says it's undefined !
>
> Am I missing something, or should I report these as bugs ?
>
> Chris
More information about the Libc-help
mailing list