tzfile.5, tzselect.8: sync from tzdb upstream
[man-pages.git] / man7 / feature_test_macros.7
blob6c0d70cd00f3416edb5437f70881958d3edd6612
1 .\" This manpage is Copyright (C) 2006, Michael Kerrisk
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH feature_test_macros 7 (date) "Linux man-pages (unreleased)"
6 .SH NAME
7 feature_test_macros \- feature test macros
8 .SH DESCRIPTION
9 Feature test macros allow the programmer to control the definitions that
10 are exposed by system header files when a program is compiled.
11 .PP
12 .B NOTE:
13 In order to be effective, a feature test macro
14 .IR "must be defined before including any header files" .
15 This can be done either in the compilation command
16 .RI ( "cc \-DMACRO=value" )
17 or by defining the macro within the source code before
18 including any headers.
19 The requirement that the macro must be defined before including any
20 header file exists because header files may freely include one another.
21 Thus, for example, in the following lines, defining the
22 .B _GNU_SOURCE
23 macro may have no effect because the header
24 .I <abc.h>
25 itself includes
26 .I <xyz.h>
27 (POSIX explicitly allows this):
28 .PP
29 .in +4n
30 .EX
31 #include <abc.h>
32 #define _GNU_SOURCE
33 #include <xyz.h>
34 .EE
35 .in
36 .PP
37 Some feature test macros are useful for creating portable applications,
38 by preventing nonstandard definitions from being exposed.
39 Other macros can be used to expose nonstandard definitions that
40 are not exposed by default.
41 .PP
42 The precise effects of each of the feature test macros described below
43 can be ascertained by inspecting the
44 .I <features.h>
45 header file.
46 .BR Note :
47 applications do
48 .I not
49 need to directly include
50 .IR <features.h> ;
51 indeed, doing so is actively discouraged.
52 See NOTES.
53 .SS Specification of feature test macro requirements in manual pages
54 When a function requires that a feature test macro is defined,
55 the manual page SYNOPSIS typically includes a note of the following form
56 (this example from the
57 .BR acct (2)
58 manual page):
59 .PP
60 .RS
61 .B #include <unistd.h>
62 .PP
63 .BI "int acct(const char *" filename );
64 .PP
65 .RS -4
66 .EX
67 Feature Test Macro Requirements for glibc (see
68 .BR feature_test_macros (7)):
69 .EE
70 .RE
71 .PP
72 .BR acct ():
73 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
74 .RE
75 .PP
76 The
77 .B ||
78 means that in order to obtain the declaration of
79 .BR acct (2)
80 from
81 .IR <unistd.h> ,
82 .I either
83 of the following macro
84 definitions must be made before including any header files:
85 .PP
86 .in +4n
87 .EX
88 #define _BSD_SOURCE
89 #define _XOPEN_SOURCE        /* or any value < 500 */
90 .EE
91 .in
92 .PP
93 Alternatively, equivalent definitions can be included in the
94 compilation command:
95 .PP
96 .in +4n
97 .EX
98 cc \-D_BSD_SOURCE
99 cc \-D_XOPEN_SOURCE           # Or any value < 500
103 Note that, as described below,
104 .BR "some feature test macros are defined by default" ,
105 so that it may not always be necessary to
106 explicitly specify the feature test macro(s) shown in the
107 SYNOPSIS.
109 In a few cases, manual pages use a shorthand for expressing the
110 feature test macro requirements (this example from
111 .BR readahead (2)):
113 .RS +4
115 .B #define _GNU_SOURCE
116 .B #include <fcntl.h>
118 .BI "ssize_t readahead(int " fd ", off64_t *" offset ", size_t " count );
122 This format is employed in cases where only a single
123 feature test macro can be used to expose the function
124 declaration, and that macro is not defined by default.
125 .SS Feature test macros understood by glibc
126 The paragraphs below explain how feature test macros are handled
127 in glibc 2.\fIx\fP,
128 .I x
129 > 0.
131 First, though, a summary of a few details for the impatient:
132 .IP \[bu] 3
133 The macros that you most likely need to use in modern source code are
134 .B _POSIX_C_SOURCE
135 (for definitions from various versions of POSIX.1),
136 .B _XOPEN_SOURCE
137 (for definitions from various versions of SUS),
138 .B _GNU_SOURCE
139 (for GNU and/or Linux specific stuff), and
140 .B _DEFAULT_SOURCE
141 (to get definitions that would normally be provided by default).
142 .IP \[bu]
143 Certain macros are defined with default values.
144 Thus, although one or more macros may be indicated as being
145 required in the SYNOPSIS of a man page,
146 it may not be necessary to define them explicitly.
147 Full details of the defaults are given later in this man page.
148 .IP \[bu]
149 Defining
150 .B _XOPEN_SOURCE
151 with a value of 600 or greater produces the same effects as defining
152 .B _POSIX_C_SOURCE
153 with a value of 200112L or greater.
154 Where one sees
156 .in +4n
158 _POSIX_C_SOURCE >= 200112L
162 in the feature test macro requirements in the SYNOPSIS of a man page,
163 it is implicit that the following has the same effect:
165 .in +4n
167 _XOPEN_SOURCE >= 600
170 .IP \[bu]
171 Defining
172 .B _XOPEN_SOURCE
173 with a value of 700 or greater produces the same effects as defining
174 .B _POSIX_C_SOURCE
175 with a value of 200809L or greater.
176 Where one sees
178 .in +4n
180 _POSIX_C_SOURCE >= 200809L
184 in the feature test macro requirements in the SYNOPSIS of a man page,
185 it is implicit that the following has the same effect:
187 .in +4n
189 _XOPEN_SOURCE >= 700
192 .\" The details in glibc 2.0 are simpler, but combining a
193 .\" a description of them with the details in later glibc versions
194 .\" would make for a complicated description.
196 glibc understands the following feature test macros:
198 .B __STRICT_ANSI__
199 ISO Standard C.
200 This macro is implicitly defined by
201 .BR gcc (1)
202 when invoked with, for example, the
203 .I \-std=c99
205 .I \-ansi
206 flag.
208 .B _POSIX_C_SOURCE
209 Defining this macro causes header files to expose definitions as follows:
211 .IP \[bu] 3
212 The value 1 exposes definitions conforming to POSIX.1-1990 and
213 ISO C (1990).
214 .IP \[bu]
215 The value 2 or greater additionally exposes
216 definitions for POSIX.2-1992.
217 .IP \[bu]
218 The value 199309L or greater additionally exposes
219 definitions for POSIX.1b (real-time extensions).
220 .\" 199506L functionality is available only since glibc 2.1
221 .IP \[bu]
222 The value 199506L or greater additionally exposes
223 definitions for POSIX.1c (threads).
224 .IP \[bu]
225 (Since glibc 2.3.3)
226 The value 200112L or greater additionally exposes definitions corresponding
227 to the POSIX.1-2001 base specification (excluding the XSI extension).
228 This value also causes C95 (since glibc 2.12) and
229 C99 (since glibc 2.10) features to be exposed
230 (in other words, the equivalent of defining
231 .BR _ISOC99_SOURCE ).
232 .IP \[bu]
233 (Since glibc 2.10)
234 The value 200809L or greater additionally exposes definitions corresponding
235 to the POSIX.1-2008 base specification (excluding the XSI extension).
238 .B _POSIX_SOURCE
239 Defining this obsolete macro with any value is equivalent to defining
240 .B _POSIX_C_SOURCE
241 with the value 1.
243 Since this macro is obsolete,
244 its usage is generally not documented when discussing
245 feature test macro requirements in the man pages.
247 .B _XOPEN_SOURCE
248 Defining this macro causes header files to expose definitions as follows:
250 .IP \[bu] 3
251 Defining with any value exposes
252 definitions conforming to POSIX.1, POSIX.2, and XPG4.
253 .IP \[bu]
254 The value 500 or greater additionally exposes
255 definitions for SUSv2 (UNIX 98).
256 .IP \[bu]
257 (Since glibc 2.2) The value 600 or greater additionally exposes
258 definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base specification
259 plus the XSI extension) and C99 definitions.
260 .IP \[bu]
261 (Since glibc 2.10) The value 700 or greater additionally exposes
262 definitions for SUSv4 (i.e., the POSIX.1-2008 base specification
263 plus the XSI extension).
267 .B __STRICT_ANSI__
268 is not defined, or
269 .B _XOPEN_SOURCE
270 is defined with a value greater than or equal to 500
271 .I and
272 neither
273 .B _POSIX_SOURCE
275 .B _POSIX_C_SOURCE
276 is explicitly defined, then
277 the following macros are implicitly defined:
279 .IP \[bu] 3
280 .B _POSIX_SOURCE
281 is defined with the value 1.
282 .IP \[bu]
283 .B _POSIX_C_SOURCE
284 is defined, according to the value of
285 .BR _XOPEN_SOURCE :
288 .BR _XOPEN_SOURCE " < 500"
289 .B _POSIX_C_SOURCE
290 is defined with the value 2.
292 .RB "500 <= " _XOPEN_SOURCE " < 600"
293 .B _POSIX_C_SOURCE
294 is defined with the value 199506L.
296 .RB "600 <= " _XOPEN_SOURCE " < 700"
297 .B _POSIX_C_SOURCE
298 is defined with the value 200112L.
300 .RB "700 <= " _XOPEN_SOURCE " (since glibc 2.10)"
301 .B _POSIX_C_SOURCE
302 is defined with the value 200809L.
306 In addition, defining
307 .B _XOPEN_SOURCE
308 with a value of 500 or greater produces the same effects as defining
309 .BR _XOPEN_SOURCE_EXTENDED .
311 .B _XOPEN_SOURCE_EXTENDED
312 If this macro is defined,
313 .I and
314 .B _XOPEN_SOURCE
315 is defined, then expose definitions corresponding to the XPG4v2
316 (SUSv1) UNIX extensions (UNIX 95).
317 Defining
318 .B _XOPEN_SOURCE
319 with a value of 500 or more also produces the same effect as defining
320 .BR _XOPEN_SOURCE_EXTENDED .
321 Use of
322 .B _XOPEN_SOURCE_EXTENDED
323 in new source code should be avoided.
325 Since defining
326 .B _XOPEN_SOURCE
327 with a value of 500 or more has the same effect as defining
328 .BR _XOPEN_SOURCE_EXTENDED ,
329 the latter (obsolete) feature test macro is generally not described in the
330 SYNOPSIS in man pages.
332 .BR _ISOC99_SOURCE " (since glibc 2.1.3)"
333 Exposes declarations consistent with the ISO C99 standard.
335 Earlier glibc 2.1.x versions recognized an equivalent macro named
336 .B _ISOC9X_SOURCE
337 (because the C99 standard had not then been finalized).
338 Although the use of this macro is obsolete, glibc continues
339 to recognize it for backward compatibility.
341 Defining
342 .B _ISOC99_SOURCE
343 also exposes ISO C (1990) Amendment 1 ("C95") definitions.
344 (The primary change in C95 was support for international character sets.)
346 Invoking the C compiler with the option
347 .I \-std=c99
348 produces the same effects as defining this macro.
350 .BR _ISOC11_SOURCE " (since glibc 2.16)"
351 Exposes declarations consistent with the ISO C11 standard.
352 Defining this macro also enables C99 and C95 features (like
353 .BR _ISOC99_SOURCE ).
355 Invoking the C compiler with the option
356 .I \-std=c11
357 produces the same effects as defining this macro.
359 .B _LARGEFILE64_SOURCE
360 Expose definitions for the alternative API specified by the
361 LFS (Large File Summit) as a "transitional extension" to the
362 Single UNIX Specification.
363 (See
364 .UR http:\:/\:/opengroup.org\:/platform\:/lfs.html
365 .UE .)
366 The alternative API consists of a set of new objects
367 (i.e., functions and types) whose names are suffixed with "64"
368 (e.g.,
369 .I off64_t
370 versus
371 .IR off_t ,
372 .BR lseek64 ()
373 versus
374 .BR lseek (),
375 etc.).
376 New programs should not employ this macro; instead
377 .I _FILE_OFFSET_BITS=64
378 should be employed.
380 .B _LARGEFILE_SOURCE
381 This macro was historically used to expose certain functions (specifically
382 .BR fseeko (3)
384 .BR ftello (3))
385 that address limitations of earlier APIs
386 .RB ( fseek (3)
388 .BR ftell (3))
389 that use
390 .I long
391 for file offsets.
392 This macro is implicitly defined if
393 .B _XOPEN_SOURCE
394 is defined with a value greater than or equal to 500.
395 New programs should not employ this macro;
396 defining
397 .B _XOPEN_SOURCE
398 as just described or defining
399 .B _FILE_OFFSET_BITS
400 with the value 64 is the preferred mechanism to achieve the same result.
402 .B _FILE_OFFSET_BITS
403 Defining this macro with the value 64
404 automatically converts references to 32-bit functions and data types
405 related to file I/O and filesystem operations into references to
406 their 64-bit counterparts.
407 This is useful for performing I/O on large files (> 2 Gigabytes)
408 on 32-bit systems.
409 (Defining this macro permits correctly written programs to use
410 large files with only a recompilation being required.)
412 64-bit systems naturally permit file sizes greater than 2 Gigabytes,
413 and on those systems this macro has no effect.
415 .B _TIME_BITS
416 Defining this macro with the value 64
417 changes the width of
418 .BR time_t (3type)
419 to 64-bit which allows handling of timestamps beyond
420 2038.
421 It is closely related to
422 .B _FILE_OFFSET_BITS
423 and depending on implementation, may require it set.
424 This macro is available as of glibc 2.34.
426 .BR _BSD_SOURCE " (deprecated since glibc 2.20)"
427 Defining this macro with any value causes header files to expose
428 BSD-derived definitions.
430 In glibc versions up to and including 2.18,
431 defining this macro also causes BSD definitions to be preferred in
432 some situations where standards conflict, unless one or more of
433 .BR _SVID_SOURCE ,
434 .BR _POSIX_SOURCE ,
435 .BR _POSIX_C_SOURCE ,
436 .BR _XOPEN_SOURCE ,
437 .BR _XOPEN_SOURCE_EXTENDED ,
439 .B _GNU_SOURCE
440 is defined, in which case BSD definitions are disfavored.
441 Since glibc 2.19,
442 .B _BSD_SOURCE
443 no longer causes BSD definitions to be preferred in case of conflicts.
445 Since glibc 2.20, this macro is deprecated.
446 .\" commit c941736c92fa3a319221f65f6755659b2a5e0a20
447 .\" commit 498afc54dfee41d33ba519f496e96480badace8e
448 .\" commit acd7f096d79c181866d56d4aaf3b043e741f1e2c
449 It now has the same effect as defining
450 .BR _DEFAULT_SOURCE ,
451 but generates a compile-time warning (unless
452 .B _DEFAULT_SOURCE
453 .\" commit ade40b10ff5fa59a318cf55b9d8414b758e8df78
454 is also defined).
456 .B _DEFAULT_SOURCE
457 instead.
458 To allow code that requires
459 .B _BSD_SOURCE
460 in glibc 2.19 and earlier and
461 .B _DEFAULT_SOURCE
462 in glibc 2.20 and later to compile without warnings, define
463 .I both
464 .B _BSD_SOURCE
466 .BR _DEFAULT_SOURCE .
468 .BR _SVID_SOURCE " (deprecated since glibc 2.20)"
469 Defining this macro with any value causes header files to expose
470 System V-derived definitions.
471 (SVID == System V Interface Definition; see
472 .BR standards (7).)
474 Since glibc 2.20, this macro is deprecated in the same fashion as
475 .BR _BSD_SOURCE .
477 .BR _DEFAULT_SOURCE " (since glibc 2.19)"
478 This macro can be defined to ensure that the "default"
479 definitions are provided even when the defaults would otherwise
480 be disabled,
481 as happens when individual macros are explicitly defined,
482 or the compiler is invoked in one of its "standard" modes (e.g.,
483 .IR cc\~\-std=c99 ).
484 Defining
485 .B _DEFAULT_SOURCE
486 without defining other individual macros
487 or invoking the compiler in one of its "standard" modes has no effect.
489 The "default" definitions comprise those required by POSIX.1-2008 and ISO C99,
490 as well as various definitions originally derived from BSD and System V.
491 On glibc 2.19 and earlier, these defaults were approximately equivalent
492 to explicitly defining the following:
494 .in +4n
496 cc \-D_BSD_SOURCE \-D_SVID_SOURCE \-D_POSIX_C_SOURCE=200809
500 .BR _ATFILE_SOURCE " (since glibc 2.4)"
501 Defining this macro with any value causes header files to expose
502 declarations of a range of functions with the suffix "at";
504 .BR openat (2).
505 Since glibc 2.10, this macro is also implicitly defined if
506 .B _POSIX_C_SOURCE
507 is defined with a value greater than or equal to 200809L.
509 .B _GNU_SOURCE
510 Defining this macro (with any value) implicitly defines
511 .BR _ATFILE_SOURCE ,
512 .BR _LARGEFILE64_SOURCE ,
513 .BR _ISOC99_SOURCE ,
514 .BR _XOPEN_SOURCE_EXTENDED ,
515 .BR _POSIX_SOURCE ,
516 .B _POSIX_C_SOURCE
517 with the value 200809L
518 (200112L before glibc 2.10;
519 199506L before glibc 2.5;
520 199309L before glibc 2.1)
522 .B _XOPEN_SOURCE
523 with the value 700
524 (600 before glibc 2.10;
525 500 before glibc 2.2).
526 In addition, various GNU-specific extensions are also exposed.
528 Since glibc 2.19, defining
529 .B _GNU_SOURCE
530 also has the effect of implicitly defining
531 .BR _DEFAULT_SOURCE .
532 Before glibc 2.20, defining
533 .B _GNU_SOURCE
534 also had the effect of implicitly defining
535 .B _BSD_SOURCE
537 .BR _SVID_SOURCE .
539 .B _REENTRANT
540 Historically, on various C libraries
541 it was necessary to define this macro in all
542 multithreaded code.
543 .\" Zack Weinberg
544 .\"     There did once exist C libraries where it was necessary. The ones
545 .\"     I remember were proprietary Unix vendor libcs from the mid-1990s
546 .\"     You would get completely unlocked stdio without _REENTRANT.
547 (Some C libraries may still require this.)
548 In glibc,
549 this macro also exposed definitions of certain reentrant functions.
551 However, glibc has been thread-safe by default for many years;
552 since glibc 2.3, the only effect of defining
553 .B _REENTRANT
554 has been to enable one or two of the same declarations that
555 are also enabled by defining
556 .B _POSIX_C_SOURCE
557 with a value of 199606L or greater.
559 .B _REENTRANT
560 is now obsolete.
561 In glibc 2.25 and later, defining
562 .B _REENTRANT
563 is equivalent to defining
564 .B _POSIX_C_SOURCE
565 with the value 199606L.
566 If a higher POSIX conformance level is
567 selected by any other means (such as
568 .B _POSIX_C_SOURCE
569 itself,
570 .BR _XOPEN_SOURCE ,
571 .BR _DEFAULT_SOURCE ,
573 .BR _GNU_SOURCE ),
574 then defining
575 .B _REENTRANT
576 has no effect.
578 This macro is automatically defined if one compiles with
579 .IR cc\~\-pthread .
581 .B _THREAD_SAFE
582 Synonym for the (deprecated)
583 .BR _REENTRANT ,
584 provided for compatibility with some other implementations.
586 .BR _FORTIFY_SOURCE " (since glibc 2.3.4)"
587 .\" For more detail, see:
588 .\" http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
589 .\" [PATCH] Object size checking to prevent (some) buffer overflows
590 .\" * From: Jakub Jelinek <jakub at redhat dot com>
591 .\" * To: gcc-patches at gcc dot gnu dot org
592 .\" * Date: Tue, 21 Sep 2004 04:16:40 -0400
593 Defining this macro causes some lightweight checks to be performed
594 to detect some buffer overflow errors when employing
595 various string and memory manipulation functions (for example,
596 .BR memcpy (3),
597 .BR memset (3),
598 .BR stpcpy (3),
599 .BR strcpy (3),
600 .BR strncpy (3),
601 .BR strcat (3),
602 .BR strncat (3),
603 .BR sprintf (3),
604 .BR snprintf (3),
605 .BR vsprintf (3),
606 .BR vsnprintf (3),
607 .BR gets (3),
608 and wide character variants thereof).
609 For some functions, argument consistency is checked;
610 for example, a check is made that
611 .BR open (2)
612 has been supplied with a
613 .I mode
614 argument when the specified flags include
615 .BR O_CREAT .
616 Not all problems are detected, just some common cases.
617 .\" Look for __USE_FORTIFY_LEVEL in the header files
620 .B _FORTIFY_SOURCE
621 is set to 1, with compiler optimization level 1
622 .RI ( "gcc\ \-O1" )
623 and above, checks that shouldn't change the behavior of
624 conforming programs are performed.
625 With
626 .B _FORTIFY_SOURCE
627 set to 2, some more checking is added, but
628 some conforming programs might fail.
629 .\" For example, given the following code
630 .\"        int d;
631 .\"        char buf[1000], buf[1000];
632 .\"        strcpy(fmt, "Hello world\n%n");
633 .\"        snprintf(buf, sizeof(buf), fmt, &d);
635 .\" Compiling with "gcc -D_FORTIFY_SOURCE=2 -O1" and then running will
636 .\" cause the following diagnostic at run time at the snprintf() call
638 .\"        *** %n in writable segment detected ***
639 .\"        Aborted (core dumped)
642 Some of the checks can be performed at compile time
643 (via macros logic implemented in header files),
644 and result in compiler warnings;
645 other checks take place at run time,
646 and result in a run-time error if the check fails.
648 With
649 .B _FORTIFY_SOURCE
650 set to 3, additional checking is added to intercept
651 some function calls used with an argument of variable size
652 where the compiler can deduce an upper bound for its value.
653 For example, a program where
654 .BR malloc (3)'s
655 size argument is variable
656 can now be fortified.
658 Use of this macro requires compiler support, available with
659 .BR gcc (1)
660 since glibc 4.0.
662 Use of
663 .B _FORTIFY_SOURCE
664 set to 3 requires
665 .BR gcc (1)
666 version 12.0 or later.
667 .SS Default definitions, implicit definitions, and combining definitions
668 If no feature test macros are explicitly defined,
669 then the following feature test macros are defined by default:
670 .B _BSD_SOURCE
671 (in glibc 2.19 and earlier),
672 .B _SVID_SOURCE
673 (in glibc 2.19 and earlier),
674 .B _DEFAULT_SOURCE
675 (since glibc 2.19),
676 .BR _POSIX_SOURCE ,
678 .BR _POSIX_C_SOURCE =200809L
679 (200112L before glibc 2.10;
680 199506L before glibc 2.4;
681 199309L before glibc 2.1).
683 If any of
684 .BR __STRICT_ANSI__ ,
685 .BR _ISOC99_SOURCE ,
686 .B _ISOC11_SOURCE
687 (since glibc 2.18),
688 .BR _POSIX_SOURCE ,
689 .BR _POSIX_C_SOURCE  ,
690 .BR _XOPEN_SOURCE ,
691 .B _XOPEN_SOURCE_EXTENDED
692 (in glibc 2.11 and earlier),
693 .B _BSD_SOURCE
694 (in glibc 2.19 and earlier),
696 .B _SVID_SOURCE
697 (in glibc 2.19 and earlier)
698 is explicitly defined, then
699 .BR _BSD_SOURCE ,
700 .BR _SVID_SOURCE ,
702 .B _DEFAULT_SOURCE
703 are not defined by default.
706 .B _POSIX_SOURCE
708 .B _POSIX_C_SOURCE
709 are not explicitly defined,
710 and either
711 .B __STRICT_ANSI__
712 is not defined or
713 .B _XOPEN_SOURCE
714 is defined with a value of 500 or more, then
715 .IP \[bu] 3
716 .B _POSIX_SOURCE
717 is defined with the value 1; and
718 .IP \[bu]
719 .B _POSIX_C_SOURCE
720 is defined with one of the following values:
721 .RS 3
722 .IP \[bu] 3
725 .B _XOPEN_SOURCE
726 is defined with a value less than 500;
727 .IP \[bu]
728 199506L,
730 .B _XOPEN_SOURCE
731 is defined with a value greater than or equal to 500 and less than 600;
733 .IP \[bu]
734 (since glibc 2.4) 200112L,
736 .B _XOPEN_SOURCE
737 is defined with a value greater than or equal to 600 and less than 700.
738 .IP \[bu]
739 (Since glibc 2.10)
740 200809L,
742 .B _XOPEN_SOURCE
743 is defined with a value greater than or equal to 700.
744 .IP \[bu]
745 Older versions of glibc do not know about the values
746 200112L and 200809L for
747 .BR _POSIX_C_SOURCE ,
748 and the setting of this macro will depend on the glibc version.
749 .IP \[bu]
751 .B _XOPEN_SOURCE
752 is undefined, then the setting of
753 .B _POSIX_C_SOURCE
754 depends on the glibc version:
755 199506L, before glibc 2.4;
756 200112L, since glibc 2.4 to glibc 2.9; and
757 200809L, since glibc 2.10.
760 Multiple macros can be defined; the results are additive.
761 .SH STANDARDS
762 POSIX.1 specifies
763 .BR _POSIX_C_SOURCE ,
764 .BR _POSIX_SOURCE ,
766 .BR _XOPEN_SOURCE .
768 .B _XOPEN_SOURCE_EXTENDED
769 was specified by XPG4v2 (aka SUSv1), but is not present in SUSv2 and later.
770 .B _FILE_OFFSET_BITS
771 is not specified by any standard,
772 but is employed on some other implementations.
774 .BR _BSD_SOURCE ,
775 .BR _SVID_SOURCE ,
776 .BR _DEFAULT_SOURCE ,
777 .BR _ATFILE_SOURCE ,
778 .BR _GNU_SOURCE ,
779 .BR _FORTIFY_SOURCE ,
780 .BR _REENTRANT ,
782 .B _THREAD_SAFE
783 are specific to Linux (glibc).
784 .SH NOTES
785 .I <features.h>
786 is a Linux/glibc-specific header file.
787 Other systems have an analogous file, but typically with a different name.
788 This header file is automatically included by other header files as
789 required: it is not necessary to explicitly include it in order to
790 employ feature test macros.
792 According to which of the above feature test macros are defined,
793 .I <features.h>
794 internally defines various other macros that are checked by
795 other glibc header files.
796 These macros have names prefixed by two underscores (e.g.,
797 .BR __USE_MISC ).
798 Programs should
799 .I never
800 define these macros directly:
801 instead, the appropriate feature test macro(s) from the
802 list above should be employed.
803 .SH EXAMPLES
804 The program below can be used to explore how the various
805 feature test macros are set depending on the glibc version
806 and what feature test macros are explicitly set.
807 The following shell session, on a system with glibc 2.10,
808 shows some examples of what we would see:
810 .in +4n
812 $ \fBcc ftm.c\fP
813 $ \fB./a.out\fP
814 _POSIX_SOURCE defined
815 _POSIX_C_SOURCE defined: 200809L
816 _BSD_SOURCE defined
817 _SVID_SOURCE defined
818 _ATFILE_SOURCE defined
819 $ \fBcc \-D_XOPEN_SOURCE=500 ftm.c\fP
820 $ \fB./a.out\fP
821 _POSIX_SOURCE defined
822 _POSIX_C_SOURCE defined: 199506L
823 _XOPEN_SOURCE defined: 500
824 $ \fBcc \-D_GNU_SOURCE ftm.c\fP
825 $ \fB./a.out\fP
826 _POSIX_SOURCE defined
827 _POSIX_C_SOURCE defined: 200809L
828 _ISOC99_SOURCE defined
829 _XOPEN_SOURCE defined: 700
830 _XOPEN_SOURCE_EXTENDED defined
831 _LARGEFILE64_SOURCE defined
832 _BSD_SOURCE defined
833 _SVID_SOURCE defined
834 _ATFILE_SOURCE defined
835 _GNU_SOURCE defined
838 .SS Program source
841 /* ftm.c */
843 #include <stdint.h>
844 #include <stdio.h>
845 #include <unistd.h>
846 #include <stdlib.h>
849 main(int argc, char *argv[])
851 #ifdef _POSIX_SOURCE
852     printf("_POSIX_SOURCE defined\en");
853 #endif
855 #ifdef _POSIX_C_SOURCE
856     printf("_POSIX_C_SOURCE defined: %jdL\en",
857             (intmax_t) _POSIX_C_SOURCE);
858 #endif
860 #ifdef _ISOC99_SOURCE
861     printf("_ISOC99_SOURCE defined\en");
862 #endif
864 #ifdef _ISOC11_SOURCE
865     printf("_ISOC11_SOURCE defined\en");
866 #endif
868 #ifdef _XOPEN_SOURCE
869     printf("_XOPEN_SOURCE defined: %d\en", _XOPEN_SOURCE);
870 #endif
872 #ifdef _XOPEN_SOURCE_EXTENDED
873     printf("_XOPEN_SOURCE_EXTENDED defined\en");
874 #endif
876 #ifdef _LARGEFILE64_SOURCE
877     printf("_LARGEFILE64_SOURCE defined\en");
878 #endif
880 #ifdef _FILE_OFFSET_BITS
881     printf("_FILE_OFFSET_BITS defined: %d\en", _FILE_OFFSET_BITS);
882 #endif
884 #ifdef _TIME_BITS
885     printf("_TIME_BITS defined: %d\en", _TIME_BITS);
886 #endif
888 #ifdef _BSD_SOURCE
889     printf("_BSD_SOURCE defined\en");
890 #endif
892 #ifdef _SVID_SOURCE
893     printf("_SVID_SOURCE defined\en");
894 #endif
896 #ifdef _DEFAULT_SOURCE
897     printf("_DEFAULT_SOURCE defined\en");
898 #endif
900 #ifdef _ATFILE_SOURCE
901     printf("_ATFILE_SOURCE defined\en");
902 #endif
904 #ifdef _GNU_SOURCE
905     printf("_GNU_SOURCE defined\en");
906 #endif
908 #ifdef _REENTRANT
909     printf("_REENTRANT defined\en");
910 #endif
912 #ifdef _THREAD_SAFE
913     printf("_THREAD_SAFE defined\en");
914 #endif
916 #ifdef _FORTIFY_SOURCE
917     printf("_FORTIFY_SOURCE defined\en");
918 #endif
920     exit(EXIT_SUCCESS);
923 .SH SEE ALSO
924 .BR libc (7),
925 .BR standards (7),
926 .BR system_data_types (7)
928 The section "Feature Test Macros" under
929 .IR "info libc" .
930 .\" But beware: the info libc document is out of date (Jul 07, mtk)
932 .I /usr/include/features.h