Module Name:    src
Committed By:   riastradh
Date:           Mon Sep  9 15:05:39 UTC 2024

Modified Files:
        src/sys/sys: featuretest.h

Log Message:
sys/featuretest.h: Define _POSIX_C_SOURCE according to _XOPEN_SOURCE.

If _XOPEN_SOURCE is defined but _POSIX_C_SOURCE is not, there is a
corresponding value of _POSIX_C_SOURCE that _XOPEN_SOURCE is supposed
to be equivalent to.  We could sprinkle conditionals for
_XOPEN_SOURCE everywhere we already have conditionals for
_POSIX_C_SOURCE, like in <locale.h>, but it's simpler and more
reliable to simply define _POSIX_C_SOURCE based on _XOPEN_SOURCE in
one place.

PR standards/55577: locale_t not defined if _XOPEN_SOURCE is defined


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/sys/featuretest.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/featuretest.h
diff -u src/sys/sys/featuretest.h:1.12 src/sys/sys/featuretest.h:1.13
--- src/sys/sys/featuretest.h:1.12	Thu Aug 15 20:42:59 2024
+++ src/sys/sys/featuretest.h	Mon Sep  9 15:05:39 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: featuretest.h,v 1.12 2024/08/15 20:42:59 riastradh Exp $	*/
+/*	$NetBSD: featuretest.h,v 1.13 2024/09/09 15:05:39 riastradh Exp $	*/
 
 /*
  * Written by Klaus Klein <kle...@netbsd.org>, February 2, 1998.
@@ -92,3 +92,61 @@
     !defined(_REENTRANT)
 #define _REENTRANT
 #endif
+
+/*
+ * The _XOPEN_SOURCE namespaces are supersets of corresponding
+ * _POSIX_C_SOURCE namespaces, so to keep the namespace tests in header
+ * files simpler, if _XOPEN_SOURCE is defined but _POSIX_C_SOURCE is
+ * not, define _POSIX_C_SOURCE to the corresponding value.
+ */
+#if defined(_XOPEN_SOURCE) && !defined(_POSIX_C_SOURCE)
+
+/*
+ * `[I]f _XOPEN_SOURCE is set equal to 800 and _POSIX_C_SOURCE is set
+ *  equal to 202405L, the behavior is the same as if only _XOPEN_SOURCE
+ *  is defined and set equal to 800.
+ *
+ * IEEE Std 1003.1-2024, 2.2.1.2 `The _XOPEN_SOURCE Feature Test Macro'
+ * https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/V2_chap02.html#tag_16_02_01_02
+ */
+#if (_XOPEN_SOURCE - 0) == 800
+#define	_POSIX_C_SOURCE	202405L
+
+/*
+ * `[I]f _XOPEN_SOURCE is set equal to 700 and _POSIX_C_SOURCE is set
+ *  equal to 200809L, the behavior is the same as if only _XOPEN_SOURCE
+ *  is defined and set equal to 700.'
+ *
+ * IEEE Std 1003.1-2008, 2.2.1 `POSIX.1 Symbols', subsection `The
+ * _XOPEN_SOURCE Feature Test Macro'
+ * https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/V2_chap02.html
+ */
+#elif (_XOPEN_SOURCE - 0) == 700
+#define	_POSIX_C_SOURCE	200809L
+
+/*
+ * `[I]f _XOPEN_SOURCE is set equal to 600 and _POSIX_C_SOURCE is set
+ *  equal to 200112L, the behavior is the same as if only _XOPEN_SOURCE
+ *  is defined and set equal to 600.'
+ *
+ * IEEE Std 1003.1-2001, 2.2.1 `POSIX.1 Symbols', subsection `The
+ * _XOPEN_SOURCE Feature Test Macro'
+ * https://pubs.opengroup.org/onlinepubs/007904875/functions/xsh_chap02_02.html
+ */
+#elif (_XOPEN_SOURCE - 0) == 600
+#define	_POSIX_C_SOURCE	200112L
+
+/*
+ * `[I]f _XOPEN_SOURCE is set equal to 500 and _POSIX_SOURCE is
+ *  defined, or _POSIX_C_SOURCE is set greater than zero and less than
+ *  or equal to 199506L, the behaviour is the same as if only
+ *  _XOPEN_SOURCE is defined and set equal to 500.'
+ *
+ * Single UNIX Specification, Version 2, `The Compilation Environment'
+ * https://pubs.opengroup.org/onlinepubs/007908799/xsh/compilation.html
+ */
+#elif (_XOPEN_SOURCE - 0) == 500
+#define	_POSIX_C_SOURCE	199506L
+#endif
+
+#endif

Reply via email to