Print this page
Be more consistent with other OSes. Try to avoid failing on unknown _XOPEN_SOURCE values.
3801 _XOPEN_SOURCE value is ignored if __XOPEN_SOURCE_EXTENDED is set

@@ -234,15 +234,15 @@
  * requirements, the appropriate feature test macros must be defined at
  * compile time. These are as follows. For more info, see standards(5).
  *
  * Feature Test Macro                                Specification
  * ------------------------------------------------  -------------
- * _XOPEN_SOURCE                                         XPG3
- * _XOPEN_SOURCE && _XOPEN_VERSION = 4                   XPG4
+ * _XOPEN_SOURCE >= 600  (or POSIX_C_SOURCE>=200112L)    XPG6
+ * _XOPEN_SOURCE >= 500                                  XPG5
  * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1           XPG4v2
- * _XOPEN_SOURCE = 500                                   XPG5
- * _XOPEN_SOURCE = 600  (or POSIX_C_SOURCE=200112L)      XPG6
+ * _XOPEN_SOURCE && _XOPEN_VERSION = 4                   XPG4
+ * _XOPEN_SOURCE                                         XPG3
  *
  * In order to simplify the guards within the headers, the following
  * implementation private test macros have been created. Applications
  * must NOT use these private test macros as unexpected results will
  * occur.

@@ -260,42 +260,41 @@
  * _XPG4_2  X/Open CAE Specification, Issue 4, Version 2 (XPG4v2/UNIX 95/SUS)
  * _XPG5    X/Open CAE Specification, Issue 5 (XPG5/UNIX 98/SUSv2)
  * _XPG6    Open Group Technical Standard, Issue 6 (XPG6/UNIX 03/SUSv3)
  */
 
-/* X/Open Portability Guide, Issue 3 */
-#if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 < 500) && \
-        (_XOPEN_VERSION - 0 < 4) && !defined(_XOPEN_SOURCE_EXTENDED)
-#define _XPG3
-/* X/Open CAE Specification, Issue 4 */
-#elif   (defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
-#define _XPG4
-#define _XPG3
-/* X/Open CAE Specification, Issue 4, Version 2 */
-#elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
+/* Open Group Technical Standard , Issue 6 */
+#if     (_XOPEN_SOURCE - 0 >= 600) || (_POSIX_C_SOURCE - 0 >= 200112L)
+#define _XPG6
+#define _XPG5
 #define _XPG4_2
 #define _XPG4
 #define _XPG3
+#undef  _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE                 200112L
+#undef  _XOPEN_SOURCE
+#define _XOPEN_SOURCE                   600
 /* X/Open CAE Specification, Issue 5 */
-#elif   (_XOPEN_SOURCE - 0 == 500)
+#elif   (_XOPEN_SOURCE - 0 >= 500)
 #define _XPG5
 #define _XPG4_2
 #define _XPG4
 #define _XPG3
 #undef  _POSIX_C_SOURCE
 #define _POSIX_C_SOURCE                 199506L
-/* Open Group Technical Standard , Issue 6 */
-#elif   (_XOPEN_SOURCE - 0 == 600) || (_POSIX_C_SOURCE - 0 == 200112L)
-#define _XPG6
-#define _XPG5
+/* X/Open CAE Specification, Issue 4, Version 2 */
+#elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
 #define _XPG4_2
 #define _XPG4
 #define _XPG3
-#undef  _POSIX_C_SOURCE
-#define _POSIX_C_SOURCE                 200112L
-#undef  _XOPEN_SOURCE
-#define _XOPEN_SOURCE                   600
+/* X/Open CAE Specification, Issue 4 */
+#elif   (defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
+#define _XPG4
+#define _XPG3
+/* X/Open Portability Guide, Issue 3 */
+#elif defined(_XOPEN_SOURCE) && (_XOPEN_VERSION - 0 < 4)
+#define _XPG3
 #endif
 
 /*
  * _XOPEN_VERSION is defined by the X/Open specifications and is not
  * normally defined by the application, except in the case of an XPG4