man/: ffix
[man-pages.git] / man / man7 / feature_test_macros.7
blob5dbc3c2fc019862a0a656cb4a4a5acccfcf6588c
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.
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):
29 .in +4n
30 .EX
31 #include <abc.h>
32 #define _GNU_SOURCE
33 #include <xyz.h>
34 .EE
35 .in
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.
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):
60 .RS
61 .B #include <unistd.h>
63 .BI "int acct(const char *" filename );
65 .RS -4
66 .EX
67 Feature Test Macro Requirements for glibc (see
68 .BR feature_test_macros (7)):
69 .EE
70 .RE
72 .BR acct ():
73 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
74 .RE
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:
86 .in +4n
87 .EX
88 #define _BSD_SOURCE
89 #define _XOPEN_SOURCE        /* or any value < 500 */
90 .EE
91 .in
93 Alternatively, equivalent definitions can be included in the
94 compilation command:
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 #define _FILE_OFFSET_BITS 64
117 .B #include <fcntl.h>
119 .BI "ssize_t readahead(int " fd ", off_t *" offset ", size_t " count );
123 This format is employed when the feature test macros ensure
124 that the proper function declarations are visible,
125 and the macros are not defined by default.
126 .SS Feature test macros understood by glibc
127 The paragraphs below explain how feature test macros are handled
128 in glibc 2.\fIx\fP,
129 .I x
130 > 0.
132 First, though, a summary of a few details for the impatient:
133 .IP \[bu] 3
134 The macros that you most likely need to use in modern source code are
135 .B _POSIX_C_SOURCE
136 (for definitions from various versions of POSIX.1),
137 .B _XOPEN_SOURCE
138 (for definitions from various versions of SUS),
139 .B _GNU_SOURCE
140 (for GNU and/or Linux specific stuff), and
141 .B _DEFAULT_SOURCE
142 (to get definitions that would normally be provided by default).
143 .IP \[bu]
144 Certain macros are defined with default values.
145 Thus, although one or more macros may be indicated as being
146 required in the SYNOPSIS of a man page,
147 it may not be necessary to define them explicitly.
148 Full details of the defaults are given later in this man page.
149 .IP \[bu]
150 Defining
151 .B _XOPEN_SOURCE
152 with a value of 600 or greater produces the same effects as defining
153 .B _POSIX_C_SOURCE
154 with a value of 200112L or greater.
155 Where one sees
157 .in +4n
159 _POSIX_C_SOURCE >= 200112L
163 in the feature test macro requirements in the SYNOPSIS of a man page,
164 it is implicit that the following has the same effect:
166 .in +4n
168 _XOPEN_SOURCE >= 600
171 .IP \[bu]
172 Defining
173 .B _XOPEN_SOURCE
174 with a value of 700 or greater produces the same effects as defining
175 .B _POSIX_C_SOURCE
176 with a value of 200809L or greater.
177 Where one sees
179 .in +4n
181 _POSIX_C_SOURCE >= 200809L
185 in the feature test macro requirements in the SYNOPSIS of a man page,
186 it is implicit that the following has the same effect:
188 .in +4n
190 _XOPEN_SOURCE >= 700
193 .\" The details in glibc 2.0 are simpler, but combining a
194 .\" a description of them with the details in later glibc versions
195 .\" would make for a complicated description.
197 glibc understands the following feature test macros:
199 .B __STRICT_ANSI__
200 ISO Standard C.
201 This macro is implicitly defined by
202 .BR gcc (1)
203 when invoked with, for example, the
204 .I \-std=c99
206 .I \-ansi
207 flag.
209 .B _POSIX_C_SOURCE
210 Defining this macro causes header files to expose definitions as follows:
212 .IP \[bu] 3
213 The value 1 exposes definitions conforming to POSIX.1-1990 and
214 ISO C (1990).
215 .IP \[bu]
216 The value 2 or greater additionally exposes
217 definitions for POSIX.2-1992.
218 .IP \[bu]
219 The value 199309L or greater additionally exposes
220 definitions for POSIX.1b (real-time extensions).
221 .\" 199506L functionality is available only since glibc 2.1
222 .IP \[bu]
223 The value 199506L or greater additionally exposes
224 definitions for POSIX.1c (threads).
225 .IP \[bu]
226 (Since glibc 2.3.3)
227 The value 200112L or greater additionally exposes definitions corresponding
228 to the POSIX.1-2001 base specification (excluding the XSI extension).
229 This value also causes C95 (since glibc 2.12) and
230 C99 (since glibc 2.10) features to be exposed
231 (in other words, the equivalent of defining
232 .BR _ISOC99_SOURCE ).
233 .IP \[bu]
234 (Since glibc 2.10)
235 The value 200809L or greater additionally exposes definitions corresponding
236 to the POSIX.1-2008 base specification (excluding the XSI extension).
239 .B _POSIX_SOURCE
240 Defining this obsolete macro with any value is equivalent to defining
241 .B _POSIX_C_SOURCE
242 with the value 1.
244 Since this macro is obsolete,
245 its usage is generally not documented when discussing
246 feature test macro requirements in the man pages.
248 .B _XOPEN_SOURCE
249 Defining this macro causes header files to expose definitions as follows:
251 .IP \[bu] 3
252 Defining with any value exposes
253 definitions conforming to POSIX.1, POSIX.2, and XPG4.
254 .IP \[bu]
255 The value 500 or greater additionally exposes
256 definitions for SUSv2 (UNIX 98).
257 .IP \[bu]
258 (Since glibc 2.2) The value 600 or greater additionally exposes
259 definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base specification
260 plus the XSI extension) and C99 definitions.
261 .IP \[bu]
262 (Since glibc 2.10) The value 700 or greater additionally exposes
263 definitions for SUSv4 (i.e., the POSIX.1-2008 base specification
264 plus the XSI extension).
268 .B __STRICT_ANSI__
269 is not defined, or
270 .B _XOPEN_SOURCE
271 is defined with a value greater than or equal to 500
272 .I and
273 neither
274 .B _POSIX_SOURCE
276 .B _POSIX_C_SOURCE
277 is explicitly defined, then
278 the following macros are implicitly defined:
280 .IP \[bu] 3
281 .B _POSIX_SOURCE
282 is defined with the value 1.
283 .IP \[bu]
284 .B _POSIX_C_SOURCE
285 is defined, according to the value of
286 .BR _XOPEN_SOURCE :
289 .BR _XOPEN_SOURCE " < 500"
290 .B _POSIX_C_SOURCE
291 is defined with the value 2.
293 .RB "500 <= " _XOPEN_SOURCE " < 600"
294 .B _POSIX_C_SOURCE
295 is defined with the value 199506L.
297 .RB "600 <= " _XOPEN_SOURCE " < 700"
298 .B _POSIX_C_SOURCE
299 is defined with the value 200112L.
301 .RB "700 <= " _XOPEN_SOURCE " (since glibc 2.10)"
302 .B _POSIX_C_SOURCE
303 is defined with the value 200809L.
307 In addition, defining
308 .B _XOPEN_SOURCE
309 with a value of 500 or greater produces the same effects as defining
310 .BR _XOPEN_SOURCE_EXTENDED .
312 .B _XOPEN_SOURCE_EXTENDED
313 If this macro is defined,
314 .I and
315 .B _XOPEN_SOURCE
316 is defined, then expose definitions corresponding to the XPG4v2
317 (SUSv1) UNIX extensions (UNIX 95).
318 Defining
319 .B _XOPEN_SOURCE
320 with a value of 500 or more also produces the same effect as defining
321 .BR _XOPEN_SOURCE_EXTENDED .
322 Use of
323 .B _XOPEN_SOURCE_EXTENDED
324 in new source code should be avoided.
326 Since defining
327 .B _XOPEN_SOURCE
328 with a value of 500 or more has the same effect as defining
329 .BR _XOPEN_SOURCE_EXTENDED ,
330 the latter (obsolete) feature test macro is generally not described in the
331 SYNOPSIS in man pages.
333 .BR _ISOC99_SOURCE " (since glibc 2.1.3)"
334 Exposes declarations consistent with the ISO C99 standard.
336 Earlier glibc 2.1.x versions recognized an equivalent macro named
337 .B _ISOC9X_SOURCE
338 (because the C99 standard had not then been finalized).
339 Although the use of this macro is obsolete, glibc continues
340 to recognize it for backward compatibility.
342 Defining
343 .B _ISOC99_SOURCE
344 also exposes ISO C (1990) Amendment 1 ("C95") definitions.
345 (The primary change in C95 was support for international character sets.)
347 Invoking the C compiler with the option
348 .I \-std=c99
349 produces the same effects as defining this macro.
351 .BR _ISOC11_SOURCE " (since glibc 2.16)"
352 Exposes declarations consistent with the ISO C11 standard.
353 Defining this macro also enables C99 and C95 features (like
354 .BR _ISOC99_SOURCE ).
356 Invoking the C compiler with the option
357 .I \-std=c11
358 produces the same effects as defining this macro.
360 .B _LARGEFILE64_SOURCE
361 Expose definitions for the alternative API specified by the
362 LFS (Large File Summit) as a "transitional extension" to the
363 Single UNIX Specification.
364 (See
365 .UR http:\:/\:/opengroup.org\:/platform\:/lfs.html
366 .UE .)
367 The alternative API consists of a set of new objects
368 (i.e., functions and types) whose names are suffixed with "64"
369 (e.g.,
370 .I off64_t
371 versus
372 .IR off_t ,
373 .BR lseek64 ()
374 versus
375 .BR lseek (),
376 etc.).
377 New programs should not employ this macro; instead
378 .I _FILE_OFFSET_BITS=64
379 should be employed.
381 .B _LARGEFILE_SOURCE
382 This macro was historically used to expose certain functions (specifically
383 .BR fseeko (3)
385 .BR ftello (3))
386 that address limitations of earlier APIs
387 .RB ( fseek (3)
389 .BR ftell (3))
390 that use
391 .I long
392 for file offsets.
393 This macro is implicitly defined if
394 .B _XOPEN_SOURCE
395 is defined with a value greater than or equal to 500.
396 New programs should not employ this macro;
397 defining
398 .B _XOPEN_SOURCE
399 as just described or defining
400 .B _FILE_OFFSET_BITS
401 with the value 64 is the preferred mechanism to achieve the same result.
403 .B _FILE_OFFSET_BITS
404 Defining this macro with the value 64
405 automatically converts references to 32-bit functions and data types
406 related to file I/O and filesystem operations into references to
407 their 64-bit counterparts.
408 This is useful for performing I/O on large files (> 2 Gigabytes)
409 on 32-bit systems.
410 It is also useful when calling functions like
411 .BR copy_file_range (2)
412 that were added more recently and that come only in 64-bit flavors.
413 (Defining this macro permits correctly written programs to use
414 large files with only a recompilation being required.)
416 64-bit systems naturally permit file sizes greater than 2 Gigabytes,
417 and on those systems this macro has no effect.
419 .B _TIME_BITS
420 Defining this macro with the value 64
421 changes the width of
422 .BR time_t (3type)
423 to 64-bit which allows handling of timestamps beyond
424 2038.
425 It is closely related to
426 .B _FILE_OFFSET_BITS
427 and depending on implementation, may require it set.
428 This macro is available as of glibc 2.34.
430 .BR _BSD_SOURCE " (deprecated since glibc 2.20)"
431 Defining this macro with any value causes header files to expose
432 BSD-derived definitions.
434 In glibc versions up to and including 2.18,
435 defining this macro also causes BSD definitions to be preferred in
436 some situations where standards conflict, unless one or more of
437 .BR _SVID_SOURCE ,
438 .BR _POSIX_SOURCE ,
439 .BR _POSIX_C_SOURCE ,
440 .BR _XOPEN_SOURCE ,
441 .BR _XOPEN_SOURCE_EXTENDED ,
443 .B _GNU_SOURCE
444 is defined, in which case BSD definitions are disfavored.
445 Since glibc 2.19,
446 .B _BSD_SOURCE
447 no longer causes BSD definitions to be preferred in case of conflicts.
449 Since glibc 2.20, this macro is deprecated.
450 .\" commit c941736c92fa3a319221f65f6755659b2a5e0a20
451 .\" commit 498afc54dfee41d33ba519f496e96480badace8e
452 .\" commit acd7f096d79c181866d56d4aaf3b043e741f1e2c
453 It now has the same effect as defining
454 .BR _DEFAULT_SOURCE ,
455 but generates a compile-time warning (unless
456 .B _DEFAULT_SOURCE
457 .\" commit ade40b10ff5fa59a318cf55b9d8414b758e8df78
458 is also defined).
460 .B _DEFAULT_SOURCE
461 instead.
462 To allow code that requires
463 .B _BSD_SOURCE
464 in glibc 2.19 and earlier and
465 .B _DEFAULT_SOURCE
466 in glibc 2.20 and later to compile without warnings, define
467 .I both
468 .B _BSD_SOURCE
470 .BR _DEFAULT_SOURCE .
472 .BR _SVID_SOURCE " (deprecated since glibc 2.20)"
473 Defining this macro with any value causes header files to expose
474 System V-derived definitions.
475 (SVID == System V Interface Definition; see
476 .BR standards (7).)
478 Since glibc 2.20, this macro is deprecated in the same fashion as
479 .BR _BSD_SOURCE .
481 .BR _DEFAULT_SOURCE " (since glibc 2.19)"
482 This macro can be defined to ensure that the "default"
483 definitions are provided even when the defaults would otherwise
484 be disabled,
485 as happens when individual macros are explicitly defined,
486 or the compiler is invoked in one of its "standard" modes (e.g.,
487 .IR cc\~\-std=c99 ).
488 Defining
489 .B _DEFAULT_SOURCE
490 without defining other individual macros
491 or invoking the compiler in one of its "standard" modes has no effect.
493 The "default" definitions comprise those required by POSIX.1-2008 and ISO C99,
494 as well as various definitions originally derived from BSD and System V.
495 On glibc 2.19 and earlier, these defaults were approximately equivalent
496 to explicitly defining the following:
498 .in +4n
500 cc \-D_BSD_SOURCE \-D_SVID_SOURCE \-D_POSIX_C_SOURCE=200809
504 .BR _ATFILE_SOURCE " (since glibc 2.4)"
505 Defining this macro with any value causes header files to expose
506 declarations of a range of functions with the suffix "at";
508 .BR openat (2).
509 Since glibc 2.10, this macro is also implicitly defined if
510 .B _POSIX_C_SOURCE
511 is defined with a value greater than or equal to 200809L.
513 .B _GNU_SOURCE
514 Defining this macro (with any value) implicitly defines
515 .BR _ATFILE_SOURCE ,
516 .BR _LARGEFILE64_SOURCE ,
517 .BR _ISOC99_SOURCE ,
518 .BR _XOPEN_SOURCE_EXTENDED ,
519 .BR _POSIX_SOURCE ,
520 .B _POSIX_C_SOURCE
521 with the value 200809L
522 (200112L before glibc 2.10;
523 199506L before glibc 2.5;
524 199309L before glibc 2.1)
526 .B _XOPEN_SOURCE
527 with the value 700
528 (600 before glibc 2.10;
529 500 before glibc 2.2).
530 In addition, various GNU-specific extensions are also exposed.
532 Since glibc 2.19, defining
533 .B _GNU_SOURCE
534 also has the effect of implicitly defining
535 .BR _DEFAULT_SOURCE .
536 Before glibc 2.20, defining
537 .B _GNU_SOURCE
538 also had the effect of implicitly defining
539 .B _BSD_SOURCE
541 .BR _SVID_SOURCE .
543 .B _REENTRANT
544 Historically, on various C libraries
545 it was necessary to define this macro in all
546 multithreaded code.
547 .\" Zack Weinberg
548 .\"     There did once exist C libraries where it was necessary. The ones
549 .\"     I remember were proprietary Unix vendor libcs from the mid-1990s
550 .\"     You would get completely unlocked stdio without _REENTRANT.
551 (Some C libraries may still require this.)
552 In glibc,
553 this macro also exposed definitions of certain reentrant functions.
555 However, glibc has been thread-safe by default for many years;
556 since glibc 2.3, the only effect of defining
557 .B _REENTRANT
558 has been to enable one or two of the same declarations that
559 are also enabled by defining
560 .B _POSIX_C_SOURCE
561 with a value of 199606L or greater.
563 .B _REENTRANT
564 is now obsolete.
565 In glibc 2.25 and later, defining
566 .B _REENTRANT
567 is equivalent to defining
568 .B _POSIX_C_SOURCE
569 with the value 199606L.
570 If a higher POSIX conformance level is
571 selected by any other means (such as
572 .B _POSIX_C_SOURCE
573 itself,
574 .BR _XOPEN_SOURCE ,
575 .BR _DEFAULT_SOURCE ,
577 .BR _GNU_SOURCE ),
578 then defining
579 .B _REENTRANT
580 has no effect.
582 This macro is automatically defined if one compiles with
583 .IR cc\~\-pthread .
585 .B _THREAD_SAFE
586 Synonym for the (deprecated)
587 .BR _REENTRANT ,
588 provided for compatibility with some other implementations.
590 .BR _FORTIFY_SOURCE " (since glibc 2.3.4)"
591 .\" For more detail, see:
592 .\" http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
593 .\" [PATCH] Object size checking to prevent (some) buffer overflows
594 .\" * From: Jakub Jelinek <jakub at redhat dot com>
595 .\" * To: gcc-patches at gcc dot gnu dot org
596 .\" * Date: Tue, 21 Sep 2004 04:16:40 -0400
597 Defining this macro causes some lightweight checks to be performed
598 to detect some buffer overflow errors when employing
599 various string and memory manipulation functions (for example,
600 .BR memcpy (3),
601 .BR memset (3),
602 .BR stpcpy (3),
603 .BR strcpy (3),
604 .BR strncpy (3),
605 .BR strcat (3),
606 .BR strncat (3),
607 .BR sprintf (3),
608 .BR snprintf (3),
609 .BR vsprintf (3),
610 .BR vsnprintf (3),
611 .BR gets (3),
612 and wide character variants thereof).
613 For some functions, argument consistency is checked;
614 for example, a check is made that
615 .BR open (2)
616 has been supplied with a
617 .I mode
618 argument when the specified flags include
619 .BR O_CREAT .
620 Not all problems are detected, just some common cases.
621 .\" Look for __USE_FORTIFY_LEVEL in the header files
624 .B _FORTIFY_SOURCE
625 is set to 1, with compiler optimization level 1
626 .RI ( "gcc\ \-O1" )
627 and above, checks that shouldn't change the behavior of
628 conforming programs are performed.
629 With
630 .B _FORTIFY_SOURCE
631 set to 2, some more checking is added, but
632 some conforming programs might fail.
633 .\" For example, given the following code
634 .\"        int d;
635 .\"        char buf[1000], buf[1000];
636 .\"        strcpy(fmt, "Hello world\n%n");
637 .\"        snprintf(buf, sizeof(buf), fmt, &d);
639 .\" Compiling with "gcc -D_FORTIFY_SOURCE=2 -O1" and then running will
640 .\" cause the following diagnostic at run time at the snprintf() call
642 .\"        *** %n in writable segment detected ***
643 .\"        Aborted (core dumped)
646 Some of the checks can be performed at compile time
647 (via macros logic implemented in header files),
648 and result in compiler warnings;
649 other checks take place at run time,
650 and result in a run-time error if the check fails.
652 With
653 .B _FORTIFY_SOURCE
654 set to 3, additional checking is added to intercept
655 some function calls used with an argument of variable size
656 where the compiler can deduce an upper bound for its value.
657 For example, a program where
658 .BR malloc (3)'s
659 size argument is variable
660 can now be fortified.
662 Use of this macro requires compiler support, available since
663 gcc 4.0 and clang 2.6.
664 Use of
665 .B _FORTIFY_SOURCE
666 set to 3 requires gcc 12.0 or later, or clang 9.0 or later,
667 in conjunction with glibc 2.33 or later.
668 .\" glibc is not an absolute requirement (gcc has libssp; NetBSD/newlib
669 .\" and Darwin each have their own implementation), but let's keep it
670 .\" simple.
671 .SS Default definitions, implicit definitions, and combining definitions
672 If no feature test macros are explicitly defined,
673 then the following feature test macros are defined by default:
674 .B _BSD_SOURCE
675 (in glibc 2.19 and earlier),
676 .B _SVID_SOURCE
677 (in glibc 2.19 and earlier),
678 .B _DEFAULT_SOURCE
679 (since glibc 2.19),
680 .BR _POSIX_SOURCE ,
682 .BR _POSIX_C_SOURCE =200809L
683 (200112L before glibc 2.10;
684 199506L before glibc 2.4;
685 199309L before glibc 2.1).
687 If any of
688 .BR __STRICT_ANSI__ ,
689 .BR _ISOC99_SOURCE ,
690 .B _ISOC11_SOURCE
691 (since glibc 2.18),
692 .BR _POSIX_SOURCE ,
693 .BR _POSIX_C_SOURCE  ,
694 .BR _XOPEN_SOURCE ,
695 .B _XOPEN_SOURCE_EXTENDED
696 (in glibc 2.11 and earlier),
697 .B _BSD_SOURCE
698 (in glibc 2.19 and earlier),
700 .B _SVID_SOURCE
701 (in glibc 2.19 and earlier)
702 is explicitly defined, then
703 .BR _BSD_SOURCE ,
704 .BR _SVID_SOURCE ,
706 .B _DEFAULT_SOURCE
707 are not defined by default.
710 .B _POSIX_SOURCE
712 .B _POSIX_C_SOURCE
713 are not explicitly defined,
714 and either
715 .B __STRICT_ANSI__
716 is not defined or
717 .B _XOPEN_SOURCE
718 is defined with a value of 500 or more, then
719 .IP \[bu] 3
720 .B _POSIX_SOURCE
721 is defined with the value 1; and
722 .IP \[bu]
723 .B _POSIX_C_SOURCE
724 is defined with one of the following values:
726 .IP \[bu] 3
729 .B _XOPEN_SOURCE
730 is defined with a value less than 500;
731 .IP \[bu]
732 199506L,
734 .B _XOPEN_SOURCE
735 is defined with a value greater than or equal to 500 and less than 600;
737 .IP \[bu]
738 (since glibc 2.4) 200112L,
740 .B _XOPEN_SOURCE
741 is defined with a value greater than or equal to 600 and less than 700.
742 .IP \[bu]
743 (Since glibc 2.10)
744 200809L,
746 .B _XOPEN_SOURCE
747 is defined with a value greater than or equal to 700.
748 .IP \[bu]
749 Older versions of glibc do not know about the values
750 200112L and 200809L for
751 .BR _POSIX_C_SOURCE ,
752 and the setting of this macro will depend on the glibc version.
753 .IP \[bu]
755 .B _XOPEN_SOURCE
756 is undefined, then the setting of
757 .B _POSIX_C_SOURCE
758 depends on the glibc version:
759 199506L, before glibc 2.4;
760 200112L, since glibc 2.4 to glibc 2.9; and
761 200809L, since glibc 2.10.
764 Multiple macros can be defined; the results are additive.
765 .SH STANDARDS
766 POSIX.1 specifies
767 .BR _POSIX_C_SOURCE ,
768 .BR _POSIX_SOURCE ,
770 .BR _XOPEN_SOURCE .
772 .B _FILE_OFFSET_BITS
773 is not specified by any standard,
774 but is employed on some other implementations.
776 .BR _BSD_SOURCE ,
777 .BR _SVID_SOURCE ,
778 .BR _DEFAULT_SOURCE ,
779 .BR _ATFILE_SOURCE ,
780 .BR _GNU_SOURCE ,
781 .BR _FORTIFY_SOURCE ,
782 .BR _REENTRANT ,
784 .B _THREAD_SAFE
785 are specific to glibc.
786 .SH HISTORY
787 .B _XOPEN_SOURCE_EXTENDED
788 was specified by XPG4v2 (aka SUSv1), but is not present in SUSv2 and later.
789 .SH NOTES
790 .I <features.h>
791 is a Linux/glibc-specific header file.
792 Other systems have an analogous file, but typically with a different name.
793 This header file is automatically included by other header files as
794 required: it is not necessary to explicitly include it in order to
795 employ feature test macros.
797 According to which of the above feature test macros are defined,
798 .I <features.h>
799 internally defines various other macros that are checked by
800 other glibc header files.
801 These macros have names prefixed by two underscores (e.g.,
802 .BR __USE_MISC ).
803 Programs should
804 .I never
805 define these macros directly:
806 instead, the appropriate feature test macro(s) from the
807 list above should be employed.
808 .SH EXAMPLES
809 The program below can be used to explore how the various
810 feature test macros are set depending on the glibc version
811 and what feature test macros are explicitly set.
812 The following shell session, on a system with glibc 2.10,
813 shows some examples of what we would see:
815 .in +4n
817 $ \fBcc ftm.c\fP
818 $ \fB./a.out\fP
819 _POSIX_SOURCE defined
820 _POSIX_C_SOURCE defined: 200809L
821 _BSD_SOURCE defined
822 _SVID_SOURCE defined
823 _ATFILE_SOURCE defined
824 $ \fBcc \-D_XOPEN_SOURCE=500 ftm.c\fP
825 $ \fB./a.out\fP
826 _POSIX_SOURCE defined
827 _POSIX_C_SOURCE defined: 199506L
828 _XOPEN_SOURCE defined: 500
829 $ \fBcc \-D_GNU_SOURCE ftm.c\fP
830 $ \fB./a.out\fP
831 _POSIX_SOURCE defined
832 _POSIX_C_SOURCE defined: 200809L
833 _ISOC99_SOURCE defined
834 _XOPEN_SOURCE defined: 700
835 _XOPEN_SOURCE_EXTENDED defined
836 _LARGEFILE64_SOURCE defined
837 _BSD_SOURCE defined
838 _SVID_SOURCE defined
839 _ATFILE_SOURCE defined
840 _GNU_SOURCE defined
843 .SS Program source
846 /* ftm.c */
848 #include <stdint.h>
849 #include <stdio.h>
850 #include <unistd.h>
851 #include <stdlib.h>
854 main(int argc, char *argv[])
856 #ifdef _POSIX_SOURCE
857     printf("_POSIX_SOURCE defined\[rs]n");
858 #endif
860 #ifdef _POSIX_C_SOURCE
861     printf("_POSIX_C_SOURCE defined: %jdL\[rs]n",
862             (intmax_t) _POSIX_C_SOURCE);
863 #endif
865 #ifdef _ISOC99_SOURCE
866     printf("_ISOC99_SOURCE defined\[rs]n");
867 #endif
869 #ifdef _ISOC11_SOURCE
870     printf("_ISOC11_SOURCE defined\[rs]n");
871 #endif
873 #ifdef _XOPEN_SOURCE
874     printf("_XOPEN_SOURCE defined: %d\[rs]n", _XOPEN_SOURCE);
875 #endif
877 #ifdef _XOPEN_SOURCE_EXTENDED
878     printf("_XOPEN_SOURCE_EXTENDED defined\[rs]n");
879 #endif
881 #ifdef _LARGEFILE64_SOURCE
882     printf("_LARGEFILE64_SOURCE defined\[rs]n");
883 #endif
885 #ifdef _FILE_OFFSET_BITS
886     printf("_FILE_OFFSET_BITS defined: %d\[rs]n", _FILE_OFFSET_BITS);
887 #endif
889 #ifdef _TIME_BITS
890     printf("_TIME_BITS defined: %d\[rs]n", _TIME_BITS);
891 #endif
893 #ifdef _BSD_SOURCE
894     printf("_BSD_SOURCE defined\[rs]n");
895 #endif
897 #ifdef _SVID_SOURCE
898     printf("_SVID_SOURCE defined\[rs]n");
899 #endif
901 #ifdef _DEFAULT_SOURCE
902     printf("_DEFAULT_SOURCE defined\[rs]n");
903 #endif
905 #ifdef _ATFILE_SOURCE
906     printf("_ATFILE_SOURCE defined\[rs]n");
907 #endif
909 #ifdef _GNU_SOURCE
910     printf("_GNU_SOURCE defined\[rs]n");
911 #endif
913 #ifdef _REENTRANT
914     printf("_REENTRANT defined\[rs]n");
915 #endif
917 #ifdef _THREAD_SAFE
918     printf("_THREAD_SAFE defined\[rs]n");
919 #endif
921 #ifdef _FORTIFY_SOURCE
922     printf("_FORTIFY_SOURCE defined\[rs]n");
923 #endif
925     exit(EXIT_SUCCESS);
928 .SH SEE ALSO
929 .BR libc (7),
930 .BR standards (7),
931 .BR system_data_types (7)
933 The section "Feature Test Macros" under
934 .IR "info libc" .
935 .\" But beware: the info libc document is out of date (Jul 07, mtk)
937 .I /usr/include/features.h