xref: /freebsd/sys/sys/_visible.h (revision 5a2f6016dec69cbcfe9595c7f40a7e44d85a9288)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1991, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Berkeley Software Design, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #ifndef	_SYS__VISIBLE_H_
36 #define	_SYS__VISIBLE_H_
37 
38 /*-
39  * The following definitions are an extension of the behavior originally
40  * implemented in <sys/_posix.h>, but with a different level of granularity.
41  * POSIX.1 requires that the macros we test be defined before any standard
42  * header file is included.
43  *
44  * Here's a quick run-down of the versions (and some informal names)
45  *  defined(_POSIX_SOURCE)		1003.1-1988
46  *					encoded as 198808 below
47  *  _POSIX_C_SOURCE == 1		1003.1-1990
48  *					encoded as 199009 below
49  *  _POSIX_C_SOURCE == 2		1003.2-1992 C Language Binding Option
50  *					encoded as 199209 below
51  *  _POSIX_C_SOURCE == 199309		1003.1b-1993
52  *					(1003.1 Issue 4, Single Unix Spec v1, Unix 93)
53  *  _POSIX_C_SOURCE == 199506		1003.1c-1995, 1003.1i-1995,
54  *					and the omnibus ISO/IEC 9945-1: 1996
55  *					(1003.1 Issue 5, Single	Unix Spec v2, Unix 95)
56  *  _POSIX_C_SOURCE == 200112		1003.1-2001 (1003.1 Issue 6, Unix 03)
57  *					with _XOPEN_SOURCE=600
58  *  _POSIX_C_SOURCE == 200809		1003.1-2008 (1003.1 Issue 7)
59  *					IEEE Std 1003.1-2017 (Rev of 1003.1-2008) is
60  *					1003.1-2008 with two TCs applied and
61  *					_XOPEN_SOURCE=700
62  * _POSIX_C_SOURCE == 202405		1003.1-2004 (1003.1 Issue 8), IEEE Std 1003.1-2024
63  * 					with _XOPEN_SOURCE=800
64  *
65  * In addition, the X/Open Portability Guide, which is now the Single UNIX
66  * Specification, defines a feature-test macro which indicates the version of
67  * that specification, and which subsumes _POSIX_C_SOURCE.
68  *
69  * Our macros begin with two underscores to avoid namespace screwage.
70  */
71 
72 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
73 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
74 #undef _POSIX_C_SOURCE		/* Probably illegal, but beyond caring now. */
75 #define	_POSIX_C_SOURCE		199009
76 #endif
77 
78 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
79 #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
80 #undef _POSIX_C_SOURCE
81 #define	_POSIX_C_SOURCE		199209
82 #endif
83 
84 /*
85  * Deal with various X/Open Portability Guides and Single UNIX Spec. We use the
86  * '- 0' construct so software that defines _XOPEN_SOURCE to nothing doesn't
87  * cause errors. X/Open CAE Specification, August 1994, System Interfaces and
88  * Headers, Issue 4, Version 2 section 2.2 states an empty definition means the
89  * same thing as _POSIX_C_SOURCE == 2. This broadly mirrors "System V Interface
90  * Definition, Fourth Edition", but earlier editions suggest some ambiguity.
91  * However, FreeBSD has histoically implemented this as a NOP, so we just
92  * document what it should be for now to not break ports gratuitously.
93  */
94 #ifdef _XOPEN_SOURCE
95 #if _XOPEN_SOURCE - 0 >= 800
96 #define	__XSI_VISIBLE		800
97 #undef _POSIX_C_SOURCE
98 #define	_POSIX_C_SOURCE		202405
99 #elif _XOPEN_SOURCE - 0 >= 700
100 #define	__XSI_VISIBLE		700
101 #undef _POSIX_C_SOURCE
102 #define	_POSIX_C_SOURCE		200809
103 #elif _XOPEN_SOURCE - 0 >= 600
104 #define	__XSI_VISIBLE		600
105 #undef _POSIX_C_SOURCE
106 #define	_POSIX_C_SOURCE		200112
107 #elif _XOPEN_SOURCE - 0 >= 500
108 #define	__XSI_VISIBLE		500
109 #undef _POSIX_C_SOURCE
110 #define	_POSIX_C_SOURCE		199506
111 #else
112 /* #define	_POSIX_C_SOURCE		199209 */
113 #endif
114 #endif
115 
116 /*
117  * Deal with all versions of POSIX.  The ordering relative to the tests above is
118  * important.
119  */
120 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
121 #define	_POSIX_C_SOURCE		198808
122 #endif
123 #ifdef _POSIX_C_SOURCE
124 #if _POSIX_C_SOURCE >= 202405
125 #define	__POSIX_VISIBLE		202405
126 #define	__ISO_C_VISIBLE		2017
127 #elif _POSIX_C_SOURCE >= 200809
128 #define	__POSIX_VISIBLE		200809
129 #define	__ISO_C_VISIBLE		1999
130 #elif _POSIX_C_SOURCE >= 200112
131 #define	__POSIX_VISIBLE		200112
132 #define	__ISO_C_VISIBLE		1999
133 #elif _POSIX_C_SOURCE >= 199506
134 #define	__POSIX_VISIBLE		199506
135 #define	__ISO_C_VISIBLE		1990
136 #elif _POSIX_C_SOURCE >= 199309
137 #define	__POSIX_VISIBLE		199309
138 #define	__ISO_C_VISIBLE		1990
139 #elif _POSIX_C_SOURCE >= 199209
140 #define	__POSIX_VISIBLE		199209
141 #define	__ISO_C_VISIBLE		1990
142 #elif _POSIX_C_SOURCE >= 199009
143 #define	__POSIX_VISIBLE		199009
144 #define	__ISO_C_VISIBLE		1990
145 #else
146 #define	__POSIX_VISIBLE		198808
147 #define	__ISO_C_VISIBLE		0
148 #endif /* _POSIX_C_SOURCE */
149 
150 /*
151  * When we've explicitly asked for a newer C version, make the C variable
152  * visible by default. Also honor the glibc _ISOC{11,23}_SOURCE macros
153  * extensions. Both glibc and OpenBSD do this, even when a more strict
154  * _POSIX_C_SOURCE has been requested, and it makes good sense (especially for
155  * pre POSIX 2024, since C11 is much nicer than the old C99 base). Continue the
156  * practice with C23, though don't do older standards. Also, GLIBC doesn't have
157  * a _ISOC17_SOURCE, so it's not implemented here. glibc has earlier ISOCxx defines,
158  * but we don't implement those as they are not relevant enough.
159  */
160 #if _ISOC23_SOURCE || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L)
161 #undef __ISO_C_VISIBLE
162 #define __ISO_C_VISIBLE		2023
163 #elif _ISOC11_SOURCE || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
164 #undef __ISO_C_VISIBLE
165 #define __ISO_C_VISIBLE		2011
166 #endif
167 #else /* _POSIX_C_SOURCE */
168 /*-
169  * Deal with _ANSI_SOURCE:
170  * If it is defined, and no other compilation environment is explicitly
171  * requested, then define our internal feature-test macros to zero.  This
172  * makes no difference to the preprocessor (undefined symbols in preprocessing
173  * expressions are defined to have value zero), but makes it more convenient for
174  * a test program to print out the values.
175  *
176  * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
177  * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
178  * environment (and in fact we will never get here).
179  */
180 #if defined(_ANSI_SOURCE)	/* Hide almost everything. */
181 #define	__POSIX_VISIBLE		0
182 #define	__XSI_VISIBLE		0
183 #define	__BSD_VISIBLE		0
184 #define	__ISO_C_VISIBLE		1990
185 #define	__EXT1_VISIBLE		0
186 #elif defined(_C99_SOURCE)	/* Localism to specify strict C99 env. */
187 #define	__POSIX_VISIBLE		0
188 #define	__XSI_VISIBLE		0
189 #define	__BSD_VISIBLE		0
190 #define	__ISO_C_VISIBLE		1999
191 #define	__EXT1_VISIBLE		0
192 #elif defined(_C11_SOURCE)	/* Localism to specify strict C11 env. */
193 #define	__POSIX_VISIBLE		0
194 #define	__XSI_VISIBLE		0
195 #define	__BSD_VISIBLE		0
196 #define	__ISO_C_VISIBLE		2011
197 #define	__EXT1_VISIBLE		0
198 #elif defined(_C23_SOURCE)	/* Localism to specify strict C23 env. */
199 #define	__POSIX_VISIBLE		0
200 #define	__XSI_VISIBLE		0
201 #define	__BSD_VISIBLE		0
202 #define	__ISO_C_VISIBLE		2023
203 #define	__EXT1_VISIBLE		0
204 #else				/* Default environment: show everything. */
205 #define	__POSIX_VISIBLE		202405
206 #define	__XSI_VISIBLE		800
207 #define	__BSD_VISIBLE		1
208 #define	__ISO_C_VISIBLE		2023
209 #define	__EXT1_VISIBLE		1
210 #endif
211 #endif /* _POSIX_C_SOURCE */
212 
213 /* User override __EXT1_VISIBLE */
214 #if defined(__STDC_WANT_LIB_EXT1__)
215 #undef	__EXT1_VISIBLE
216 #if __STDC_WANT_LIB_EXT1__
217 #define	__EXT1_VISIBLE		1
218 #else
219 #define	__EXT1_VISIBLE		0
220 #endif
221 #endif /* __STDC_WANT_LIB_EXT1__ */
222 
223 #endif /* !_SYS__VISIBLE_H_ */
224