diff mbox series

[uclibc-ng-devel] features.h: Rework _DEFAULT_SOURCE

Message ID 20240210192930.296075-1-paul@crapouillou.net
State Accepted
Headers show
Series [uclibc-ng-devel] features.h: Rework _DEFAULT_SOURCE | expand

Commit Message

Paul Cercueil Feb. 10, 2024, 7:29 p.m. UTC
The (glibc) documentation for _DEFAULT_SOURCE states:

    The "default" definitions comprise those required by
    POSIX.1-2008 and ISO C99, as well as various definitions
    originally derived from BSD and System V.  On glibc 2.19
    and earlier, these defaults were approximately equivalent
    to explicitly defining the following:

      cc -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809

It also states that _BSD_SOURCE and _SVID_SOURCE are deprecated, and
have the same effect as setting _DEFAULT_SOURCE.

Therefore, when any of _BSD_SOURCE, _SVID_SOURCE or _DEFAULT_SOURCE is
set, the three macros should be set, and POSIX 2008.09 compatibility
should be enabled.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 include/features.h | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Waldemar Brodkorb Feb. 18, 2024, 6:20 a.m. UTC | #1
Hi Paul,

thanks, applied and pushed.

best regards
 Waldemar

Paul Cercueil wrote,

> The (glibc) documentation for _DEFAULT_SOURCE states:
> 
>     The "default" definitions comprise those required by
>     POSIX.1-2008 and ISO C99, as well as various definitions
>     originally derived from BSD and System V.  On glibc 2.19
>     and earlier, these defaults were approximately equivalent
>     to explicitly defining the following:
> 
>       cc -D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809
> 
> It also states that _BSD_SOURCE and _SVID_SOURCE are deprecated, and
> have the same effect as setting _DEFAULT_SOURCE.
> 
> Therefore, when any of _BSD_SOURCE, _SVID_SOURCE or _DEFAULT_SOURCE is
> set, the three macros should be set, and POSIX 2008.09 compatibility
> should be enabled.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  include/features.h | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 
> diff --git a/include/features.h b/include/features.h
> index d6e45c2ff..11b34205f 100644
> --- a/include/features.h
> +++ b/include/features.h
> @@ -40,7 +40,8 @@
>     _SVID_SOURCE		ISO C, POSIX, and SVID things.
>     _ATFILE_SOURCE	Additional *at interfaces.
>     _GNU_SOURCE		All of the above, plus GNU extensions.
> -   _DEFAULT_SOURCE	Equivalent to defining _BSD_SOURCE and _SVID_SOURCE.
> +   _DEFAULT_SOURCE	Equivalent to defining _BSD_SOURCE and _SVID_SOURCE,
> +			as well as _POSIX_C_SOURCE=200809L.
>     _REENTRANT		Select additionally reentrant object.
>     _THREAD_SAFE		Same as _REENTRANT, often used by other systems.
>     _FORTIFY_SOURCE	If set to numeric value > 0 additional security
> @@ -142,18 +143,19 @@
>  /* Whether to use feature set F.  */
>  #define __GLIBC_USE(F)  __GLIBC_USE_ ## F
>  
> -/* _DEFAULT_SOURCE is equivalent to defining _BSD_SOURCE and _SVID_SOURCE
> - * and vice versa. */
> -#ifdef _DEFAULT_SOURCE
> +/* _DEFAULT_SOURCE is equivalent to defining _BSD_SOURCE, _SVID_SOURCE
> + * and _POSIX_C_SOURCE=200809L and vice versa. */
> +#if defined _DEFAULT_SOURCE || defined _BSD_SOURCE || defined _SVID_SOURCE
> +# undef _DEFAULT_SOURCE
> +# define _DEFAULT_SOURCE 1
>  # undef  _BSD_SOURCE
>  # define _BSD_SOURCE	1
>  # undef  _SVID_SOURCE
>  # define _SVID_SOURCE	1
> -#endif
> -
> -#if defined _BSD_SOURCE || defined _SVID_SOURCE
> -# undef _DEFAULT_SOURCE
> -# define _DEFAULT_SOURCE	1
> +# if _POSIX_C_SOURCE < 200809L
> +#  undef _POSIX_C_SOURCE
> +#  define _POSIX_C_SOURCE 200809L
> +# endif
>  #endif
>  
>  /* If _GNU_SOURCE was defined by the user, turn on all the other features.  */
> -- 
> 2.43.0
> 
> _______________________________________________
> devel mailing list -- devel@uclibc-ng.org
> To unsubscribe send an email to devel-leave@uclibc-ng.org
>
diff mbox series

Patch

diff --git a/include/features.h b/include/features.h
index d6e45c2ff..11b34205f 100644
--- a/include/features.h
+++ b/include/features.h
@@ -40,7 +40,8 @@ 
    _SVID_SOURCE		ISO C, POSIX, and SVID things.
    _ATFILE_SOURCE	Additional *at interfaces.
    _GNU_SOURCE		All of the above, plus GNU extensions.
-   _DEFAULT_SOURCE	Equivalent to defining _BSD_SOURCE and _SVID_SOURCE.
+   _DEFAULT_SOURCE	Equivalent to defining _BSD_SOURCE and _SVID_SOURCE,
+			as well as _POSIX_C_SOURCE=200809L.
    _REENTRANT		Select additionally reentrant object.
    _THREAD_SAFE		Same as _REENTRANT, often used by other systems.
    _FORTIFY_SOURCE	If set to numeric value > 0 additional security
@@ -142,18 +143,19 @@ 
 /* Whether to use feature set F.  */
 #define __GLIBC_USE(F)  __GLIBC_USE_ ## F
 
-/* _DEFAULT_SOURCE is equivalent to defining _BSD_SOURCE and _SVID_SOURCE
- * and vice versa. */
-#ifdef _DEFAULT_SOURCE
+/* _DEFAULT_SOURCE is equivalent to defining _BSD_SOURCE, _SVID_SOURCE
+ * and _POSIX_C_SOURCE=200809L and vice versa. */
+#if defined _DEFAULT_SOURCE || defined _BSD_SOURCE || defined _SVID_SOURCE
+# undef _DEFAULT_SOURCE
+# define _DEFAULT_SOURCE 1
 # undef  _BSD_SOURCE
 # define _BSD_SOURCE	1
 # undef  _SVID_SOURCE
 # define _SVID_SOURCE	1
-#endif
-
-#if defined _BSD_SOURCE || defined _SVID_SOURCE
-# undef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE	1
+# if _POSIX_C_SOURCE < 200809L
+#  undef _POSIX_C_SOURCE
+#  define _POSIX_C_SOURCE 200809L
+# endif
 #endif
 
 /* If _GNU_SOURCE was defined by the user, turn on all the other features.  */