1 /* $NetBSD: featuretest.h,v 1.13 2024/09/09 15:05:39 riastradh Exp $ */ 2 3 /* 4 * Written by Klaus Klein <kleink@NetBSD.org>, February 2, 1998. 5 * Public domain. 6 * 7 * NOTE: Do not protect this header against multiple inclusion. Doing 8 * so can have subtle side-effects due to header file inclusion order 9 * and testing of e.g. _POSIX_SOURCE vs. _POSIX_C_SOURCE. Instead, 10 * protect each CPP macro that we want to supply. 11 */ 12 13 /* 14 * Feature-test macros are defined by several standards, and allow an 15 * application to specify what symbols they want the system headers to 16 * expose, and hence what standard they want them to conform to. 17 * There are two classes of feature-test macros. The first class 18 * specify complete standards, and if one of these is defined, header 19 * files will try to conform to the relevant standard. They are: 20 * 21 * ANSI macros: 22 * _ANSI_SOURCE ANSI C89 23 * 24 * POSIX macros: 25 * _POSIX_SOURCE == 1 IEEE Std 1003.1 (version?) 26 * _POSIX_C_SOURCE == 1 IEEE Std 1003.1-1990 27 * _POSIX_C_SOURCE == 2 IEEE Std 1003.2-1992 28 * _POSIX_C_SOURCE == 199309L IEEE Std 1003.1b-1993 29 * _POSIX_C_SOURCE == 199506L ISO/IEC 9945-1:1996 30 * _POSIX_C_SOURCE == 200112L IEEE Std 1003.1-2001 31 * _POSIX_C_SOURCE == 200809L IEEE Std 1003.1-2008 32 * _POSIX_C_SOURCE == 202405L IEEE Std 1003.1-2024 33 * 34 * Reference: 35 * 36 * The Open Group Base Specifications Issue 8, IEEE Std 37 * 1003.1-2024, IEEE and The Open Group, 2024, Sec. 2.2.1.1 `The 38 * _POSIX_C_SOURCE Feature Test Macro'. 39 * https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/V2_chap02.html#tag_16_02_01_01 40 * 41 * X/Open macros: 42 * _XOPEN_SOURCE System Interfaces and Headers, Issue 4, Ver 2 43 * _XOPEN_SOURCE_EXTENDED == 1 XSH4.2 UNIX extensions 44 * _XOPEN_SOURCE == 500 System Interfaces and Headers, Issue 5 45 * _XOPEN_SOURCE == 520 Networking Services (XNS), Issue 5.2 46 * _XOPEN_SOURCE == 600 IEEE Std 1003.1-2001, XSI option 47 * _XOPEN_SOURCE == 700 IEEE Std 1003.1-2008, XSI option 48 * _XOPEN_SOURCE == 800 IEEE Std 1003.1-2024, XSI option 49 * 50 * Reference: 51 * 52 * The Open Group Base Specifications Issue 8, IEEE Std 53 * 1003.1-2024, IEEE and The Open Group, 2024, Sec. 2.2.1.2 `The 54 * _XOPEN_SOURCE Feature Test Macro'. 55 * https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/V2_chap02.html#tag_16_02_01_02 56 * 57 * NetBSD macros: 58 * _NETBSD_SOURCE == 1 Make all NetBSD features available. 59 * 60 * If more than one of these "major" feature-test macros is defined, 61 * then the set of facilities provided (and namespace used) is the 62 * union of that specified by the relevant standards, and in case of 63 * conflict, the earlier standard in the above list has precedence (so 64 * if both _POSIX_C_SOURCE and _NETBSD_SOURCE are defined, the version 65 * of rename() that's used is the POSIX one). If none of the "major" 66 * feature-test macros is defined, _NETBSD_SOURCE is assumed. 67 * 68 * There are also "minor" feature-test macros, which enable extra 69 * functionality in addition to some base standard. They should be 70 * defined along with one of the "major" macros. The "minor" macros 71 * are: 72 * 73 * _REENTRANT Some thread-safety extensions like lgamma_r(3) 74 * (mostly subsumed by _POSIX_C_SOURCE >= 199506L) 75 * _ISOC99_SOURCE C99 extensions like snprintf without -std=c99 76 * _ISOC11_SOURCE C11 extensions like aligned_alloc without -std=c11 77 * _ISOC23_SOURCE C23 extensions like mbrtoc8 without -std=c23 78 * _OPENBSD_SOURCE Nonstandard OpenBSD extensions like strtonum(3) 79 * _GNU_SOURCE Nonstandard GNU extensions like feenableexcept(3) 80 */ 81 82 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 83 #define _POSIX_C_SOURCE 1L 84 #endif 85 86 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_C_SOURCE) && \ 87 !defined(_XOPEN_SOURCE) && !defined(_NETBSD_SOURCE) 88 #define _NETBSD_SOURCE 1 89 #endif 90 91 #if ((_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500) && \ 92 !defined(_REENTRANT) 93 #define _REENTRANT 94 #endif 95 96 /* 97 * The _XOPEN_SOURCE namespaces are supersets of corresponding 98 * _POSIX_C_SOURCE namespaces, so to keep the namespace tests in header 99 * files simpler, if _XOPEN_SOURCE is defined but _POSIX_C_SOURCE is 100 * not, define _POSIX_C_SOURCE to the corresponding value. 101 */ 102 #if defined(_XOPEN_SOURCE) && !defined(_POSIX_C_SOURCE) 103 104 /* 105 * `[I]f _XOPEN_SOURCE is set equal to 800 and _POSIX_C_SOURCE is set 106 * equal to 202405L, the behavior is the same as if only _XOPEN_SOURCE 107 * is defined and set equal to 800. 108 * 109 * IEEE Std 1003.1-2024, 2.2.1.2 `The _XOPEN_SOURCE Feature Test Macro' 110 * https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/V2_chap02.html#tag_16_02_01_02 111 */ 112 #if (_XOPEN_SOURCE - 0) == 800 113 #define _POSIX_C_SOURCE 202405L 114 115 /* 116 * `[I]f _XOPEN_SOURCE is set equal to 700 and _POSIX_C_SOURCE is set 117 * equal to 200809L, the behavior is the same as if only _XOPEN_SOURCE 118 * is defined and set equal to 700.' 119 * 120 * IEEE Std 1003.1-2008, 2.2.1 `POSIX.1 Symbols', subsection `The 121 * _XOPEN_SOURCE Feature Test Macro' 122 * https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/V2_chap02.html 123 */ 124 #elif (_XOPEN_SOURCE - 0) == 700 125 #define _POSIX_C_SOURCE 200809L 126 127 /* 128 * `[I]f _XOPEN_SOURCE is set equal to 600 and _POSIX_C_SOURCE is set 129 * equal to 200112L, the behavior is the same as if only _XOPEN_SOURCE 130 * is defined and set equal to 600.' 131 * 132 * IEEE Std 1003.1-2001, 2.2.1 `POSIX.1 Symbols', subsection `The 133 * _XOPEN_SOURCE Feature Test Macro' 134 * https://pubs.opengroup.org/onlinepubs/007904875/functions/xsh_chap02_02.html 135 */ 136 #elif (_XOPEN_SOURCE - 0) == 600 137 #define _POSIX_C_SOURCE 200112L 138 139 /* 140 * `[I]f _XOPEN_SOURCE is set equal to 500 and _POSIX_SOURCE is 141 * defined, or _POSIX_C_SOURCE is set greater than zero and less than 142 * or equal to 199506L, the behaviour is the same as if only 143 * _XOPEN_SOURCE is defined and set equal to 500.' 144 * 145 * Single UNIX Specification, Version 2, `The Compilation Environment' 146 * https://pubs.opengroup.org/onlinepubs/007908799/xsh/compilation.html 147 */ 148 #elif (_XOPEN_SOURCE - 0) == 500 149 #define _POSIX_C_SOURCE 199506L 150 #endif 151 152 #endif 153