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
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/feature_tests.h
+++ new/usr/src/uts/common/sys/feature_tests.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #ifndef _SYS_FEATURE_TESTS_H
28 28 #define _SYS_FEATURE_TESTS_H
29 29
30 30 #include <sys/ccompile.h>
31 31 #include <sys/isa_defs.h>
32 32
33 33 #ifdef __cplusplus
34 34 extern "C" {
35 35 #endif
36 36
37 37 /*
38 38 * Values of _POSIX_C_SOURCE
39 39 *
40 40 * undefined not a POSIX compilation
41 41 * 1 POSIX.1-1990 compilation
42 42 * 2 POSIX.2-1992 compilation
43 43 * 199309L POSIX.1b-1993 compilation (Real Time)
44 44 * 199506L POSIX.1c-1995 compilation (POSIX Threads)
45 45 * 200112L POSIX.1-2001 compilation (Austin Group Revision)
46 46 */
47 47 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
48 48 #define _POSIX_C_SOURCE 1
49 49 #endif
50 50
51 51 /*
52 52 * The feature test macros __XOPEN_OR_POSIX, _STRICT_STDC, and _STDC_C99
53 53 * are Sun implementation specific macros created in order to compress
54 54 * common standards specified feature test macros for easier reading.
55 55 * These macros should not be used by the application developer as
56 56 * unexpected results may occur. Instead, the user should reference
57 57 * standards(5) for correct usage of the standards feature test macros.
58 58 *
59 59 * __XOPEN_OR_POSIX Used in cases where a symbol is defined by both
60 60 * X/Open or POSIX or in the negative, when neither
61 61 * X/Open or POSIX defines a symbol.
62 62 *
63 63 * _STRICT_STDC __STDC__ is specified by the C Standards and defined
64 64 * by the compiler. For Sun compilers the value of
65 65 * __STDC__ is either 1, 0, or not defined based on the
66 66 * compilation mode (see cc(1)). When the value of
67 67 * __STDC__ is 1 and in the absence of any other feature
68 68 * test macros, the namespace available to the application
69 69 * is limited to only those symbols defined by the C
70 70 * Standard. _STRICT_STDC provides a more readable means
71 71 * of identifying symbols defined by the standard, or in
72 72 * the negative, symbols that are extensions to the C
73 73 * Standard. See additional comments for GNU C differences.
74 74 *
75 75 * _STDC_C99 __STDC_VERSION__ is specified by the C standards and
76 76 * defined by the compiler and indicates the version of
77 77 * the C standard. A value of 199901L indicates a
78 78 * compiler that complies with ISO/IEC 9899:1999, other-
79 79 * wise known as the C99 standard.
80 80 */
81 81
82 82 #if defined(_XOPEN_SOURCE) || defined(_POSIX_C_SOURCE)
83 83 #define __XOPEN_OR_POSIX
84 84 #endif
85 85
86 86 /*
87 87 * ISO/IEC 9899:1990 and it's revision, ISO/IEC 9899:1999 specify the
88 88 * following predefined macro name:
89 89 *
90 90 * __STDC__ The integer constant 1, intended to indicate a conforming
91 91 * implementation.
92 92 *
93 93 * Furthermore, a strictly conforming program shall use only those features
94 94 * of the language and library specified in these standards. A conforming
95 95 * implementation shall accept any strictly conforming program.
96 96 *
97 97 * Based on these requirements, Sun's C compiler defines __STDC__ to 1 for
98 98 * strictly conforming environments and __STDC__ to 0 for environments that
99 99 * use ANSI C semantics but allow extensions to the C standard. For non-ANSI
100 100 * C semantics, Sun's C compiler does not define __STDC__.
101 101 *
102 102 * The GNU C project interpretation is that __STDC__ should always be defined
103 103 * to 1 for compilation modes that accept ANSI C syntax regardless of whether
104 104 * or not extensions to the C standard are used. Violations of conforming
105 105 * behavior are conditionally flagged as warnings via the use of the
106 106 * -pedantic option. In addition to defining __STDC__ to 1, the GNU C
107 107 * compiler also defines __STRICT_ANSI__ as a means of specifying strictly
108 108 * conforming environments using the -ansi or -std=<standard> options.
109 109 *
110 110 * In the absence of any other compiler options, Sun and GNU set the value
111 111 * of __STDC__ as follows when using the following options:
112 112 *
113 113 * Value of __STDC__ __STRICT_ANSI__
114 114 *
115 115 * cc -Xa (default) 0 undefined
116 116 * cc -Xt (transitional) 0 undefined
117 117 * cc -Xc (strictly conforming) 1 undefined
118 118 * cc -Xs (K&R C) undefined undefined
119 119 *
120 120 * gcc (default) 1 undefined
121 121 * gcc -ansi, -std={c89, c99,...) 1 defined
122 122 * gcc -traditional (K&R) undefined undefined
123 123 *
124 124 * The default compilation modes for Sun C compilers versus GNU C compilers
125 125 * results in a differing value for __STDC__ which results in a more
126 126 * restricted namespace when using Sun compilers. To allow both GNU and Sun
127 127 * interpretations to peacefully co-exist, we use the following Sun
128 128 * implementation _STRICT_STDC_ macro:
129 129 */
130 130
131 131 #if (__STDC__ - 0 == 1 && !defined(__GNUC__)) || \
132 132 (defined(__GNUC__) && defined(__STRICT_ANSI__))
133 133 #define _STRICT_STDC
134 134 #else
135 135 #undef _STRICT_STDC
136 136 #endif
137 137
138 138 /*
139 139 * Compiler complies with ISO/IEC 9899:1999
140 140 */
141 141
142 142 #if __STDC_VERSION__ - 0 >= 199901L
143 143 #define _STDC_C99
144 144 #endif
145 145
146 146 /*
147 147 * Large file interfaces:
148 148 *
149 149 * _LARGEFILE_SOURCE
150 150 * 1 large file-related additions to POSIX
151 151 * interfaces requested (fseeko, etc.)
152 152 * _LARGEFILE64_SOURCE
153 153 * 1 transitional large-file-related interfaces
154 154 * requested (seek64, stat64, etc.)
155 155 *
156 156 * The corresponding announcement macros are respectively:
157 157 * _LFS_LARGEFILE
158 158 * _LFS64_LARGEFILE
159 159 * (These are set in <unistd.h>.)
160 160 *
161 161 * Requesting _LARGEFILE64_SOURCE implies requesting _LARGEFILE_SOURCE as
162 162 * well.
163 163 *
164 164 * The large file interfaces are made visible regardless of the initial values
165 165 * of the feature test macros under certain circumstances:
166 166 * - If no explicit standards-conforming environment is requested (neither
167 167 * of _POSIX_SOURCE nor _XOPEN_SOURCE is defined and the value of
168 168 * __STDC__ does not imply standards conformance).
169 169 * - Extended system interfaces are explicitly requested (__EXTENSIONS__
170 170 * is defined).
171 171 * - Access to in-kernel interfaces is requested (_KERNEL or _KMEMUSER is
172 172 * defined). (Note that this dependency is an artifact of the current
173 173 * kernel implementation and may change in future releases.)
174 174 */
175 175 #if (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
176 176 defined(_KERNEL) || defined(_KMEMUSER) || \
177 177 defined(__EXTENSIONS__)
178 178 #undef _LARGEFILE64_SOURCE
179 179 #define _LARGEFILE64_SOURCE 1
180 180 #endif
181 181 #if _LARGEFILE64_SOURCE - 0 == 1
182 182 #undef _LARGEFILE_SOURCE
183 183 #define _LARGEFILE_SOURCE 1
184 184 #endif
185 185
186 186 /*
187 187 * Large file compilation environment control:
188 188 *
189 189 * The setting of _FILE_OFFSET_BITS controls the size of various file-related
190 190 * types and governs the mapping between file-related source function symbol
191 191 * names and the corresponding binary entry points.
192 192 *
193 193 * In the 32-bit environment, the default value is 32; if not set, set it to
194 194 * the default here, to simplify tests in other headers.
195 195 *
196 196 * In the 64-bit compilation environment, the only value allowed is 64.
197 197 */
198 198 #if defined(_LP64)
199 199 #ifndef _FILE_OFFSET_BITS
200 200 #define _FILE_OFFSET_BITS 64
201 201 #endif
202 202 #if _FILE_OFFSET_BITS - 0 != 64
203 203 #error "invalid _FILE_OFFSET_BITS value specified"
204 204 #endif
205 205 #else /* _LP64 */
206 206 #ifndef _FILE_OFFSET_BITS
207 207 #define _FILE_OFFSET_BITS 32
208 208 #endif
209 209 #if _FILE_OFFSET_BITS - 0 != 32 && _FILE_OFFSET_BITS - 0 != 64
210 210 #error "invalid _FILE_OFFSET_BITS value specified"
211 211 #endif
212 212 #endif /* _LP64 */
213 213
214 214 /*
215 215 * Use of _XOPEN_SOURCE
216 216 *
217 217 * The following X/Open specifications are supported:
218 218 *
219 219 * X/Open Portability Guide, Issue 3 (XPG3)
220 220 * X/Open CAE Specification, Issue 4 (XPG4)
221 221 * X/Open CAE Specification, Issue 4, Version 2 (XPG4v2)
222 222 * X/Open CAE Specification, Issue 5 (XPG5)
223 223 * Open Group Technical Standard, Issue 6 (XPG6), also referred to as
224 224 * IEEE Std. 1003.1-2001 and ISO/IEC 9945:2002.
225 225 *
226 226 * XPG4v2 is also referred to as UNIX 95 (SUS or SUSv1).
227 227 * XPG5 is also referred to as UNIX 98 or the Single Unix Specification,
228 228 * Version 2 (SUSv2)
↓ open down ↓ |
228 lines elided |
↑ open up ↑ |
229 229 * XPG6 is the result of a merge of the X/Open and POSIX specifications
230 230 * and as such is also referred to as IEEE Std. 1003.1-2001 in
231 231 * addition to UNIX 03 and SUSv3.
232 232 *
233 233 * When writing a conforming X/Open application, as per the specification
234 234 * requirements, the appropriate feature test macros must be defined at
235 235 * compile time. These are as follows. For more info, see standards(5).
236 236 *
237 237 * Feature Test Macro Specification
238 238 * ------------------------------------------------ -------------
239 - * _XOPEN_SOURCE XPG3
240 - * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
239 + * _XOPEN_SOURCE >= 600 (or POSIX_C_SOURCE>=200112L) XPG6
240 + * _XOPEN_SOURCE >= 500 XPG5
241 241 * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2
242 - * _XOPEN_SOURCE = 500 XPG5
243 - * _XOPEN_SOURCE = 600 (or POSIX_C_SOURCE=200112L) XPG6
242 + * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
243 + * _XOPEN_SOURCE XPG3
244 244 *
245 245 * In order to simplify the guards within the headers, the following
246 246 * implementation private test macros have been created. Applications
247 247 * must NOT use these private test macros as unexpected results will
248 248 * occur.
249 249 *
250 250 * Note that in general, the use of these private macros is cumulative.
251 251 * For example, the use of _XPG3 with no other restrictions on the X/Open
252 252 * namespace will make the symbols visible for XPG3 through XPG6
253 253 * compilation environments. The use of _XPG4_2 with no other X/Open
254 254 * namespace restrictions indicates that the symbols were introduced in
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
255 255 * XPG4v2 and are therefore visible for XPG4v2 through XPG6 compilation
256 256 * environments, but not for XPG3 or XPG4 compilation environments.
257 257 *
258 258 * _XPG3 X/Open Portability Guide, Issue 3 (XPG3)
259 259 * _XPG4 X/Open CAE Specification, Issue 4 (XPG4)
260 260 * _XPG4_2 X/Open CAE Specification, Issue 4, Version 2 (XPG4v2/UNIX 95/SUS)
261 261 * _XPG5 X/Open CAE Specification, Issue 5 (XPG5/UNIX 98/SUSv2)
262 262 * _XPG6 Open Group Technical Standard, Issue 6 (XPG6/UNIX 03/SUSv3)
263 263 */
264 264
265 -/* X/Open Portability Guide, Issue 3 */
266 -#if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0 < 500) && \
267 - (_XOPEN_VERSION - 0 < 4) && !defined(_XOPEN_SOURCE_EXTENDED)
268 -#define _XPG3
269 -/* X/Open CAE Specification, Issue 4 */
270 -#elif (defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
271 -#define _XPG4
272 -#define _XPG3
273 -/* X/Open CAE Specification, Issue 4, Version 2 */
274 -#elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
265 +/* Open Group Technical Standard , Issue 6 */
266 +#if (_XOPEN_SOURCE - 0 >= 600) || (_POSIX_C_SOURCE - 0 >= 200112L)
267 +#define _XPG6
268 +#define _XPG5
275 269 #define _XPG4_2
276 270 #define _XPG4
277 271 #define _XPG3
272 +#undef _POSIX_C_SOURCE
273 +#define _POSIX_C_SOURCE 200112L
274 +#undef _XOPEN_SOURCE
275 +#define _XOPEN_SOURCE 600
278 276 /* X/Open CAE Specification, Issue 5 */
279 -#elif (_XOPEN_SOURCE - 0 == 500)
277 +#elif (_XOPEN_SOURCE - 0 >= 500)
280 278 #define _XPG5
281 279 #define _XPG4_2
282 280 #define _XPG4
283 281 #define _XPG3
284 282 #undef _POSIX_C_SOURCE
285 283 #define _POSIX_C_SOURCE 199506L
286 -/* Open Group Technical Standard , Issue 6 */
287 -#elif (_XOPEN_SOURCE - 0 == 600) || (_POSIX_C_SOURCE - 0 == 200112L)
288 -#define _XPG6
289 -#define _XPG5
284 +/* X/Open CAE Specification, Issue 4, Version 2 */
285 +#elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE_EXTENDED - 0 == 1)
290 286 #define _XPG4_2
291 287 #define _XPG4
292 288 #define _XPG3
293 -#undef _POSIX_C_SOURCE
294 -#define _POSIX_C_SOURCE 200112L
295 -#undef _XOPEN_SOURCE
296 -#define _XOPEN_SOURCE 600
289 +/* X/Open CAE Specification, Issue 4 */
290 +#elif (defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 == 4)
291 +#define _XPG4
292 +#define _XPG3
293 +/* X/Open Portability Guide, Issue 3 */
294 +#elif defined(_XOPEN_SOURCE) && (_XOPEN_VERSION - 0 < 4)
295 +#define _XPG3
297 296 #endif
298 297
299 298 /*
300 299 * _XOPEN_VERSION is defined by the X/Open specifications and is not
301 300 * normally defined by the application, except in the case of an XPG4
302 301 * application. On the implementation side, _XOPEN_VERSION defined with
303 302 * the value of 3 indicates an XPG3 application. _XOPEN_VERSION defined
304 303 * with the value of 4 indicates an XPG4 or XPG4v2 (UNIX 95) application.
305 304 * _XOPEN_VERSION defined with a value of 500 indicates an XPG5 (UNIX 98)
306 305 * application and with a value of 600 indicates an XPG6 (UNIX 03)
307 306 * application. The appropriate version is determined by the use of the
308 307 * feature test macros described earlier. The value of _XOPEN_VERSION
309 308 * defaults to 3 otherwise indicating support for XPG3 applications.
310 309 */
311 310 #ifndef _XOPEN_VERSION
312 311 #ifdef _XPG6
313 312 #define _XOPEN_VERSION 600
314 313 #elif defined(_XPG5)
315 314 #define _XOPEN_VERSION 500
316 315 #elif defined(_XPG4_2)
317 316 #define _XOPEN_VERSION 4
318 317 #else
319 318 #define _XOPEN_VERSION 3
320 319 #endif
321 320 #endif
322 321
323 322 /*
324 323 * ANSI C and ISO 9899:1990 say the type long long doesn't exist in strictly
325 324 * conforming environments. ISO 9899:1999 says it does.
326 325 *
327 326 * The presence of _LONGLONG_TYPE says "long long exists" which is therefore
328 327 * defined in all but strictly conforming environments that disallow it.
329 328 */
330 329 #if !defined(_STDC_C99) && defined(_STRICT_STDC) && !defined(__GNUC__)
331 330 /*
332 331 * Resist attempts to force the definition of long long in this case.
333 332 */
334 333 #if defined(_LONGLONG_TYPE)
335 334 #error "No long long in strictly conforming ANSI C & 1990 ISO C environments"
336 335 #endif
337 336 #else
338 337 #if !defined(_LONGLONG_TYPE)
339 338 #define _LONGLONG_TYPE
340 339 #endif
341 340 #endif
342 341
343 342 /*
344 343 * It is invalid to compile an XPG3, XPG4, XPG4v2, or XPG5 application
345 344 * using c99. The same is true for POSIX.1-1990, POSIX.2-1992, POSIX.1b,
346 345 * and POSIX.1c applications. Likewise, it is invalid to compile an XPG6
347 346 * or a POSIX.1-2001 application with anything other than a c99 or later
348 347 * compiler. Therefore, we force an error in both cases.
349 348 */
350 349 #if defined(_STDC_C99) && (defined(__XOPEN_OR_POSIX) && !defined(_XPG6))
351 350 #error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
352 351 and pre-2001 POSIX applications"
353 352 #elif !defined(_STDC_C99) && \
354 353 (defined(__XOPEN_OR_POSIX) && defined(_XPG6))
355 354 #error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications \
356 355 require the use of c99"
357 356 #endif
358 357
359 358 /*
360 359 * The following macro defines a value for the ISO C99 restrict
361 360 * keyword so that _RESTRICT_KYWD resolves to "restrict" if
362 361 * an ISO C99 compiler is used and "" (null string) if any other
363 362 * compiler is used. This allows for the use of single prototype
364 363 * declarations regardless of compiler version.
365 364 */
366 365 #if (defined(__STDC__) && defined(_STDC_C99)) && !defined(__cplusplus)
367 366 #define _RESTRICT_KYWD restrict
368 367 #else
369 368 #define _RESTRICT_KYWD
370 369 #endif
371 370
372 371 /*
373 372 * The following macro indicates header support for the ANSI C++
374 373 * standard. The ISO/IEC designation for this is ISO/IEC FDIS 14882.
375 374 */
376 375 #define _ISO_CPP_14882_1998
377 376
378 377 /*
379 378 * The following macro indicates header support for the C99 standard,
380 379 * ISO/IEC 9899:1999, Programming Languages - C.
381 380 */
382 381 #define _ISO_C_9899_1999
383 382
384 383 /*
385 384 * The following macro indicates header support for DTrace. The value is an
386 385 * integer that corresponds to the major version number for DTrace.
387 386 */
388 387 #define _DTRACE_VERSION 1
389 388
390 389 #ifdef __cplusplus
391 390 }
392 391 #endif
393 392
394 393 #endif /* _SYS_FEATURE_TESTS_H */
↓ open down ↓ |
88 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX