ioctl_userfaultfd.2: Update UFFDIO_API description
[man-pages.git] / man7 / feature_test_macros.7
blob0766f8bddaac5d1f2089d67e9d9d7df5ec376007
1 .\" This manpage is Copyright (C) 2006, Michael Kerrisk
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH FEATURE_TEST_MACROS 7 2016-12-12 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 feature_test_macros \- feature test macros
28 .SH DESCRIPTION
29 Feature test macros allow the programmer to control the definitions that
30 are exposed by system header files when a program is compiled.
32 .B NOTE:
33 In order to be effective, a feature test macro
34 .IR "must be defined before including any header files" .
35 This can be done either in the compilation command
36 .RI ( "cc \-DMACRO=value" )
37 or by defining the macro within the source code before
38 including any headers.
40 Some feature test macros are useful for creating portable applications,
41 by preventing nonstandard definitions from being exposed.
42 Other macros can be used to expose nonstandard definitions that
43 are not exposed by default.
45 The precise effects of each of the feature test macros described below
46 can be ascertained by inspecting the
47 .I <features.h>
48 header file.
49 .BR Note :
50 applications do
51 .I not
52 need to directly include
53 .IR <features.h> ;
54 indeed, doing so is actively discouraged.
55 See NOTES.
56 .SS Specification of feature test macro requirements in manual pages
57 When a function requires that a feature test macro is defined,
58 the manual page SYNOPSIS typically includes a note of the following form
59 (this example from the
60 .BR acct (2)
61 manual page):
62 .RS 8
63 .sp
64 .B #include <unistd.h>
65 .sp
66 .BI "int acct(const char *" filename );
67 .sp
68 .nf
69 .in -4n
70 Feature Test Macro Requirements for glibc (see
71 .BR feature_test_macros (7)):
72 .fi
73 .in
74 .sp
75 .BR acct ():
76 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
77 .RE
78 .PP
79 The
80 .B ||
81 means that in order to obtain the declaration of
82 .BR acct (2)
83 from
84 .IR <unistd.h> ,
85 .I either
86 of the following macro
87 definitions must be made before including any header files:
88 .RS
89 .nf
91 #define _BSD_SOURCE
92 #define _XOPEN_SOURCE        /* or any value < 500 */
93 .fi
94 .RE
95 .PP
96 Alternatively, equivalent definitions can be included in the
97 compilation command:
98 .RS
99 .nf
101 cc \-D_BSD_SOURCE
102 cc \-D_XOPEN_SOURCE           # Or any value < 500
106 Note that, as described below,
107 .BR "some feature test macros are defined by default" ,
108 so that it may not always be necessary to
109 explicitly specify the feature test macro(s) shown in the
110 SYNOPSIS.
112 In a few cases, manual pages use a shorthand for expressing the
113 feature test macro requirements (this example from
114 .BR readahead (2)):
118 .B #define _GNU_SOURCE
119 .B #include <fcntl.h>
121 .BI "ssize_t readahead(int " fd ", off64_t *" offset ", size_t " count );
125 This format is employed in cases where only a single
126 feature test macro can be used to expose the function
127 declaration, and that macro is not defined by default.
128 .SS Feature test macros understood by glibc
129 The paragraphs below explain how feature test macros are handled
130 in Linux glibc 2.\fIx\fP,
131 .I x
132 > 0.
134 First, though a summary of a few details for the impatient:
135 .IP * 3
136 The macros that you most likely need to use in modern source code are
137 .BR _POSIX_C_SOURCE
138 (for definitions from various versions of POSIX.1),
139 .BR _XOPEN_SOURCE
140 (for definitions from various versions of SUS),
141 .BR _GNU_SOURCE
142 (for GNU and/or Linux specific stuff), and
143 .BR _DEFAULT_SOURCE
144 (to get definitions that would normally be provided by default).
145 .IP *
146 Certain macros are defined with default values.
147 Thus, although one or more macros may be indicated as being
148 required in the SYNOPSIS of a man page,
149 it may not be necessary to define them explicitly.
150 Full details of the defaults are given later in this man page.
151 .IP *
152 Defining
153 .BR _XOPEN_SOURCE
154 with a value of 600 or greater produces the same effects as defining
155 .BR _POSIX_C_SOURCE
156 with a value of 200112L or greater.
157 Where one sees
161     _POSIX_C_SOURCE >= 200112L
166 in the feature test macro requirements in the SYNOPSIS of a man page,
167 it is implicit that the following has the same effect:
171     _XOPEN_SOURCE >= 600
175 .IP *
176 Defining
177 .BR _XOPEN_SOURCE
178 with a value of 700 or greater produces the same effects as defining
179 .BR _POSIX_C_SOURCE
180 with a value of 200809L or greater.
181 Where one sees
185     _POSIX_C_SOURCE >= 200809L
190 in the feature test macro requirements in the SYNOPSIS of a man page,
191 it is implicit that the following has the same effect:
195     _XOPEN_SOURCE >= 700
199 .\" The details in glibc 2.0 are simpler, but combining a
200 .\" a description of them with the details in later glibc versions
201 .\" would make for a complicated description.
203 Linux glibc understands the following feature test macros:
204 .TP 8
205 .B __STRICT_ANSI__
206 ISO Standard C.
207 This macro is implicitly defined by
208 .BR gcc (1)
209 when invoked with, for example, the
210 .I -std=c99
212 .I -ansi
213 flag.
215 .B _POSIX_C_SOURCE
216 Defining this macro causes header files to expose definitions as follows:
218 .IP \(bu 3
219 The value 1 exposes definitions conforming to POSIX.1-1990 and
220 ISO C (1990).
221 .IP \(bu
222 The value 2 or greater additionally exposes
223 definitions for POSIX.2-1992.
224 .IP \(bu
225 The value 199309L or greater additionally exposes
226 definitions for POSIX.1b (real-time extensions).
227 .\" 199506L functionality is available only since glibc 2.1
228 .IP \(bu
229 The value 199506L or greater additionally exposes
230 definitions for POSIX.1c (threads).
231 .IP \(bu
232 (Since glibc 2.3.3)
233 The value 200112L or greater additionally exposes definitions corresponding
234 to the POSIX.1-2001 base specification (excluding the XSI extension).
235 This value also causes C95 (since glibc 2.12) and
236 C99 (since glibc 2.10) features to be exposed
237 (in other words, the equivalent of defining
238 .BR _ISOC99_SOURCE ).
239 .IP \(bu
240 (Since glibc 2.10)
241 The value 200809L or greater additionally exposes definitions corresponding
242 to the POSIX.1-2008 base specification (excluding the XSI extension).
245 .B _POSIX_SOURCE
246 Defining this obsolete macro with any value is equivalent to defining
247 .B _POSIX_C_SOURCE
248 with the value 1.
250 Since this macro is obsolete,
251 its usage is generally not documented when discussing
252 feature test macro requirements in the man pages.
254 .B _XOPEN_SOURCE
255 Defining this macro causes header files to expose definitions as follows:
257 .IP \(bu 3
258 Defining with any value exposes
259 definitions conforming to POSIX.1, POSIX.2, and XPG4.
260 .IP \(bu
261 The value 500 or greater additionally exposes
262 definitions for SUSv2 (UNIX 98).
263 .IP \(bu
264 (Since glibc 2.2) The value 600 or greater additionally exposes
265 definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base specification
266 plus the XSI extension) and C99 definitions.
267 .IP \(bu
268 (Since glibc 2.10) The value 700 or greater additionally exposes
269 definitions for SUSv4 (i.e., the POSIX.1-2008 base specification
270 plus the XSI extension).
274 .B __STRICT_ANSI__
275 is not defined, or
276 .BR _XOPEN_SOURCE
277 is defined with a value greater than or equal to 500
278 .I and
279 neither
280 .B _POSIX_SOURCE
282 .B _POSIX_C_SOURCE
283 is explicitly defined, then
284 the following macros are implicitly defined:
286 .IP \(bu 3
287 .B _POSIX_SOURCE
288 is defined with the value 1.
289 .IP \(bu
290 .B _POSIX_C_SOURCE
291 is defined, according to the value of
292 .BR _XOPEN_SOURCE :
295 .BR _XOPEN_SOURCE " < 500"
296 .B _POSIX_C_SOURCE
297 is defined with the value 2.
299 .RB "500 <= " _XOPEN_SOURCE " < 600"
300 .B _POSIX_C_SOURCE
301 is defined with the value 199506L.
303 .RB "600 <= " _XOPEN_SOURCE " < 700"
304 .B _POSIX_C_SOURCE
305 is defined with the value 200112L.
307 .RB "700 <= " _XOPEN_SOURCE " (since glibc 2.10)"
308 .B _POSIX_C_SOURCE
309 is defined with the value 200809L.
313 In addition, defining
314 .BR _XOPEN_SOURCE
315 with a value of 500 or greater produces the same effects as defining
316 .BR _XOPEN_SOURCE_EXTENDED .
318 .B _XOPEN_SOURCE_EXTENDED
319 If this macro is defined,
320 .I and
321 .B _XOPEN_SOURCE
322 is defined, then expose definitions corresponding to the XPG4v2
323 (SUSv1) UNIX extensions (UNIX 95).
324 Defining
325 .B _XOPEN_SOURCE
326 with a value of 500 or more also produces the same effect as defining
327 .BR _XOPEN_SOURCE_EXTENDED .
328 Use of
329 .BR _XOPEN_SOURCE_EXTENDED
330 in new source code should be avoided.
332 Since defining
333 .B _XOPEN_SOURCE
334 with a value of 500 or more has the same effect as defining
335 .BR _XOPEN_SOURCE_EXTENDED ,
336 the latter (obsolete) feature test macro is generally not described in the
337 SYNOPSIS in man pages.
339 .BR _ISOC99_SOURCE " (since glibc 2.1.3)"
340 Exposes declarations consistent with the ISO C99 standard.
342 Earlier glibc 2.1.x versions recognized an equivalent macro named
343 .B _ISOC9X_SOURCE
344 (because the C99 standard had not then been finalized).
345 Although the use of this macro is obsolete, glibc continues
346 to recognize it for backward compatibility.
348 Defining
349 .B _ISOC99_SOURCE
350 also exposes ISO C (1990) Amendment 1 ("C95") definitions.
351 (The primary change in C95 was support for international character sets.)
353 Invoking the C compiler with the option
354 .IR \-std=c99
355 produces the same effects as defining this macro.
357 .BR _ISOC11_SOURCE " (since glibc 2.16)"
358 Exposes declarations consistent with the ISO C11 standard.
359 Defining this macro also enables C99 and C95 features (like
360 .BR _ISOC99_SOURCE ).
362 Invoking the C compiler with the option
363 .IR \-std=c11
364 produces the same effects as defining this macro.
366 .B _LARGEFILE64_SOURCE
367 Expose definitions for the alternative API specified by the
368 LFS (Large File Summit) as a "transitional extension" to the
369 Single UNIX Specification.
370 (See
371 .UR http:\:/\:/opengroup.org\:/platform\:/lfs.html
372 .UE .)
373 The alternative API consists of a set of new objects
374 (i.e., functions and types) whose names are suffixed with "64"
375 (e.g.,
376 .I off64_t
377 versus
378 .IR off_t ,
379 .BR lseek64 ()
380 versus
381 .BR lseek (),
382 etc.).
383 New programs should not employ this macro; instead
384 .I _FILE_OFFSET_BITS=64
385 should be employed.
387 .BR _LARGEFILE_SOURCE
388 This macro was historically used to expose certain functions (specifically
389 .BR fseeko (3)
391 .BR ftello (3))
392 that address limitations of earlier APIs
393 .RB ( fseek (3)
395 .BR ftell (3))
396 that use
397 .IR "long int"
398 for file offsets.
399 This macro is implicitly defined if
400 .BR _XOPEN_SOURCE
401 is defined with a value greater than or equal to 500.
402 New programs should not employ this macro;
403 defining
404 .BR _XOPEN_SOURCE
405 as just described or defining
406 .B _FILE_OFFSET_BITS
407 with the value 64 is the preferred mechanism to achieve the same result.
409 .B _FILE_OFFSET_BITS
410 Defining this macro with the value 64
411 automatically converts references to 32-bit functions and data types
412 related to file I/O and filesystem operations into references to
413 their 64-bit counterparts.
414 This is useful for performing I/O on large files (> 2 Gigabytes)
415 on 32-bit systems.
416 (Defining this macro permits correctly written programs to use
417 large files with only a recompilation being required.)
419 64-bit systems naturally permit file sizes greater than 2 Gigabytes,
420 and on those systems this macro has no effect.
422 .BR _BSD_SOURCE " (deprecated since glibc 2.20)"
423 Defining this macro with any value causes header files to expose
424 BSD-derived definitions.
426 In glibc versions up to and including 2.18,
427 defining this macro also causes BSD definitions to be preferred in
428 some situations where standards conflict, unless one or more of
429 .BR _SVID_SOURCE ,
430 .BR _POSIX_SOURCE ,
431 .BR _POSIX_C_SOURCE ,
432 .BR _XOPEN_SOURCE ,
433 .BR _XOPEN_SOURCE_EXTENDED ,
435 .B _GNU_SOURCE
436 is defined, in which case BSD definitions are disfavored.
437 Since glibc 2.19,
438 .B _BSD_SOURCE
439 no longer causes BSD definitions to be preferred in case of conflicts.
441 Since glibc 2.20, this macro is deprecated.
442 .\" commit c941736c92fa3a319221f65f6755659b2a5e0a20
443 .\" commit 498afc54dfee41d33ba519f496e96480badace8e
444 .\" commit acd7f096d79c181866d56d4aaf3b043e741f1e2c
445 It now has the same effect as defining
446 .BR _DEFAULT_SOURCE ,
447 but generates a compile-time warning (unless
448 .BR _DEFAULT_SOURCE
449 .\" commit ade40b10ff5fa59a318cf55b9d8414b758e8df78
450 is also defined).
452 .B _DEFAULT_SOURCE
453 instead.
454 To allow code that requires
455 .BR _BSD_SOURCE
456 in glibc 2.19 and earlier and
457 .BR _DEFAULT_SOURCE
458 in glibc 2.20 and later to compile without warnings, define
459 .I both
460 .B _BSD_SOURCE
462 .BR _DEFAULT_SOURCE .
464 .BR _SVID_SOURCE " (deprecated since glibc 2.20)"
465 Defining this macro with any value causes header files to expose
466 System V-derived definitions.
467 (SVID == System V Interface Definition; see
468 .BR standards (7).)
470 Since glibc 2.20, this macro is deprecated in the same fashion as
471 .BR _BSD_SOURCE .
473 .BR _DEFAULT_SOURCE " (since glibc 2.19)"
474 This macro can be defined to ensure that the "default"
475 definitions are provided even when the defaults would otherwise
476 be disabled,
477 as happens when individual macros are explicitly defined,
478 or the compiler is invoked in one of its "standard" modes (e.g.,
479 .IR "cc\ \-std=c99" ).
480 Defining
481 .B _DEFAULT_SOURCE
482 without defining other individual macros
483 or invoking the compiler in one of its "standard" modes has no effect.
485 The "default" definitions comprise those required by POSIX.1-2008 and ISO C99,
486 as well as various definitions originally derived from BSD and System V.
487 On glibc 2.19 and earlier, these defaults were approximately equivalent
488 to explicitly defining the following:
490     cc \-D_BSD_SOURCE \-D_SVID_SOURCE \-D_POSIX_C_SOURCE=200809
492 .BR _ATFILE_SOURCE " (since glibc 2.4)"
493 Defining this macro with any value causes header files to expose
494 declarations of a range of functions with the suffix "at";
496 .BR openat (2).
497 Since glibc 2.10, this macro is also implicitly defined if
498 .BR _POSIX_C_SOURCE
499 is defined with a value greater than or equal to 200809L.
501 .B _GNU_SOURCE
502 Defining this macro (with any value) implicitly defines
503 .BR _ATFILE_SOURCE ,
504 .BR _LARGEFILE64_SOURCE ,
505 .BR _ISOC99_SOURCE ,
506 .BR _XOPEN_SOURCE_EXTENDED ,
507 .BR _POSIX_SOURCE ,
508 .B _POSIX_C_SOURCE
509 with the value 200809L
510 (200112L in glibc versions before 2.10;
511 199506L in glibc versions before 2.5;
512 199309L in glibc versions before 2.1)
514 .B _XOPEN_SOURCE
515 with the value 700
516 (600 in glibc versions before 2.10;
517 500 in glibc versions before 2.2).
518 In addition, various GNU-specific extensions are also exposed.
520 Since glibc 2.19, defining
521 .BR _GNU_SOURCE
522 also has the effect of implicitly defining
523 .BR _DEFAULT_SOURCE .
524 In glibc versions before 2.20, defining
525 .BR _GNU_SOURCE
526 also had the effect of implicitly defining
527 .BR _BSD_SOURCE
529 .BR _SVID_SOURCE .
531 .B _REENTRANT
532 Historically, on various C libraries
533 it was necessary to define this macro in all
534 multithreaded code.
535 .\" Zack Weinberg
536 .\"     There did once exist C libraries where it was necessary. The ones
537 .\"     I remember were proprietary Unix vendor libcs from the mid-1990s
538 .\"     You would get completely unlocked stdio without _REENTRANT.
539 (Some C libraries may still require this.)
540 In glibc,
541 this macro also exposed definitions of certain reentrant functions.
543 However, glibc has been thread-safe by default for many years;
544 since glibc 2.3, the only effect of defining
545 .BR _REENTRANT
546 has been to enable one or two of the same declarations that
547 are also enabled by defining
548 .BR _POSIX_C_SOURCE
549 with a value of 199606L or greater.
551 .B _REENTRANT
552 is now obsolete.
553 In glibc 2.25 and later, defining
554 .B _REENTRANT
555 is equivalent to defining
556 .B _POSIX_C_SOURCE
557 with the value 199606L.
558 If a higher POSIX conformance level is
559 selected by any other means (such as
560 .B _POSIX_C_SOURCE
561 itself,
562 .BR _XOPEN_SOURCE ,
563 .BR _DEFAULT_SOURCE ,
565 .BR _GNU_SOURCE ),
566 then defining
567 .B _REENTRANT
568 has no effect.
570 This macro is automatically defined if one compiles with
571 .IR "cc\ \-pthread" .
573 .B _THREAD_SAFE
574 Synonym for the (deprecated)
575 .BR _REENTRANT ,
576 provided for compatibility with some other implementations.
578 .BR _FORTIFY_SOURCE " (since glibc 2.3.4)"
579 .\" For more detail, see:
580 .\" http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
581 .\" [PATCH] Object size checking to prevent (some) buffer overflows
582 .\" * From: Jakub Jelinek <jakub at redhat dot com>
583 .\" * To: gcc-patches at gcc dot gnu dot org
584 .\" * Date: Tue, 21 Sep 2004 04:16:40 -0400
585 Defining this macro causes some lightweight checks to be performed
586 to detect some buffer overflow errors when employing
587 various string and memory manipulation functions (for example,
588 .BR memcpy (3),
589 .BR memset (3),
590 .BR stpcpy (3),
591 .BR strcpy (3),
592 .BR strncpy (3),
593 .BR strcat (3),
594 .BR strncat (3),
595 .BR sprintf (3),
596 .BR snprintf (3),
597 .BR vsprintf (3),
598 .BR vsnprintf (3),
599 .BR gets (3),
600 and wide character variants thereof).
601 For some functions, argument consistency is checked;
602 for example, a check is made that
603 .BR open (2)
604 has been supplied with a
605 .I mode
606 argument when the specified flags include
607 .BR O_CREAT .
608 Not all problems are detected, just some common cases.
609 .\" Look for __USE_FORTIFY_LEVEL in the header files
612 .B _FORTIFY_SOURCE
613 is set to 1, with compiler optimization level 1
614 .RI ( "gcc\ \-O1" )
615 and above, checks that shouldn't change the behavior of
616 conforming programs are performed.
617 With
618 .B _FORTIFY_SOURCE
619 set to 2, some more checking is added, but
620 some conforming programs might fail.
621 .\" For example, given the following code
622 .\"        int d;
623 .\"        char buf[1000], buf[1000];
624 .\"        strcpy(fmt, "Hello world\n%n");
625 .\"        snprintf(buf, sizeof(buf), fmt, &d);
627 .\" Compiling with "gcc -D_FORTIFY_SOURCE=2 -O1" and then running will
628 .\" cause the following diagnostic at runtime at the snprintf() call
630 .\"        *** %n in writable segment detected ***
631 .\"        Aborted (core dumped)
634 Some of the checks can be performed at compile time
635 (via macros logic implemented in header files),
636 and result in compiler warnings;
637 other checks take place at run time,
638 and result in a run-time error if the check fails.
640 Use of this macro requires compiler support, available with
641 .BR gcc (1)
642 since version 4.0.
643 .SS Default definitions, implicit definitions, and combining definitions
645 If no feature test macros are explicitly defined,
646 then the following feature test macros are defined by default:
647 .BR _BSD_SOURCE
648 (in glibc 2.19 and earlier),
649 .BR _SVID_SOURCE
650 (in glibc 2.19 and earlier),
651 .BR _DEFAULT_SOURCE
652 (since glibc 2.19),
653 .BR _POSIX_SOURCE ,
655 .BR _POSIX_C_SOURCE =200809L
656 (200112L in glibc versions before 2.10;
657 199506L in glibc versions before 2.4;
658 199309L in glibc versions before 2.1).
660 If any of
661 .BR __STRICT_ANSI__ ,
662 .BR _ISOC99_SOURCE ,
663 .BR _POSIX_SOURCE ,
664 .BR _POSIX_C_SOURCE  ,
665 .BR _XOPEN_SOURCE ,
666 .BR _XOPEN_SOURCE_EXTENDED ,
667 .BR _BSD_SOURCE
668 (in glibc 2.19 and earlier),
670 .B _SVID_SOURCE
671 (in glibc 2.19 and earlier)
672 is explicitly defined, then
673 .BR _BSD_SOURCE ,
674 .BR _SVID_SOURCE ,
676 .BR _DEFAULT_SOURCE
677 are not defined by default.
680 .B _POSIX_SOURCE
682 .B _POSIX_C_SOURCE
683 are not explicitly defined,
684 and either
685 .B __STRICT_ANSI__
686 is not defined or
687 .B _XOPEN_SOURCE
688 is defined with a value of 500 or more, then
689 .IP * 3
690 .B _POSIX_SOURCE
691 is defined with the value 1; and
692 .IP *
693 .B _POSIX_C_SOURCE
694 is defined with one of the following values:
695 .RS 3
696 .IP \(bu 3
699 .B _XOPEN_SOURCE
700 is defined with a value less than 500;
701 .IP \(bu
702 199506L,
704 .B _XOPEN_SOURCE
705 is defined with a value greater than or equal to 500 and less than 600;
707 .IP \(bu
708 (since glibc 2.4) 200112L,
710 .B _XOPEN_SOURCE
711 is defined with a value greater than or equal to 600 and less than 700.
712 .IP \(bu
713 (Since glibc 2.10)
714 200809L,
716 .B _XOPEN_SOURCE
717 is defined with a value greater than or equal to 700.
718 .IP \(bu
719 Older versions of glibc do not know about the values
720 200112L and 200809L for
721 .BR _POSIX_C_SOURCE ,
722 and the setting of this macro will depend on the glibc version.
723 .IP \(bu
725 .B _XOPEN_SOURCE
726 is undefined, then the setting of
727 .B _POSIX_C_SOURCE
728 depends on the glibc version:
729 199506L, in glibc versions before 2.4;
730 200112L, in glibc 2.4 to 2.9; and
731 200809L, since glibc 2.10.
734 Multiple macros can be defined; the results are additive.
735 .SH CONFORMING TO
736 POSIX.1 specifies
737 .BR _POSIX_C_SOURCE ,
738 .BR _POSIX_SOURCE ,
740 .BR _XOPEN_SOURCE .
742 .B _XOPEN_SOURCE_EXTENDED
743 was specified by XPG4v2 (aka SUSv1), but is not present in SUSv2 and later.
744 .B _FILE_OFFSET_BITS
745 is not specified by any standard,
746 but is employed on some other implementations.
748 .BR _BSD_SOURCE ,
749 .BR _SVID_SOURCE ,
750 .BR _DEFAULT_SOURCE ,
751 .BR _ATFILE_SOURCE ,
752 .BR _GNU_SOURCE ,
753 .BR _FORTIFY_SOURCE ,
754 .BR _REENTRANT ,
756 .B _THREAD_SAFE
757 are specific to Linux (glibc).
758 .SH NOTES
759 .I <features.h>
760 is a Linux/glibc-specific header file.
761 Other systems have an analogous file, but typically with a different name.
762 This header file is automatically included by other header files as
763 required: it is not necessary to explicitly include it in order to
764 employ feature test macros.
766 According to which of the above feature test macros are defined,
767 .I <features.h>
768 internally defines various other macros that are checked by
769 other glibc header files.
770 These macros have names prefixed by two underscores (e.g.,
771 .BR __USE_MISC ).
772 Programs should
773 .I never
774 define these macros directly:
775 instead, the appropriate feature test macro(s) from the
776 list above should be employed.
777 .SH EXAMPLE
778 The program below can be used to explore how the various
779 feature test macros are set depending on the glibc version
780 and what feature test macros are explicitly set.
781 The following shell session, on a system with glibc 2.10,
782 shows some examples of what we would see:
783 .in +4n
786 $ \fBcc ftm.c\fP
787 $ \fB./a.out\fP
788 _POSIX_SOURCE defined
789 _POSIX_C_SOURCE defined: 200809L
790 _BSD_SOURCE defined
791 _SVID_SOURCE defined
792 _ATFILE_SOURCE defined
793 $ \fBcc \-D_XOPEN_SOURCE=500 ftm.c\fP
794 $ \fB./a.out\fP
795 _POSIX_SOURCE defined
796 _POSIX_C_SOURCE defined: 199506L
797 _XOPEN_SOURCE defined: 500
798 $ \fBcc \-D_GNU_SOURCE ftm.c\fP
799 $ \fB./a.out\fP
800 _POSIX_SOURCE defined
801 _POSIX_C_SOURCE defined: 200809L
802 _ISOC99_SOURCE defined
803 _XOPEN_SOURCE defined: 700
804 _XOPEN_SOURCE_EXTENDED defined
805 _LARGEFILE64_SOURCE defined
806 _BSD_SOURCE defined
807 _SVID_SOURCE defined
808 _ATFILE_SOURCE defined
809 _GNU_SOURCE defined
812 .SS Program source
815 /* ftm.c */
817 #include <stdio.h>
818 #include <unistd.h>
819 #include <stdlib.h>
822 main(int argc, char *argv[])
824 #ifdef _POSIX_SOURCE
825     printf("_POSIX_SOURCE defined\\n");
826 #endif
828 #ifdef _POSIX_C_SOURCE
829     printf("_POSIX_C_SOURCE defined: %ldL\\n", (long) _POSIX_C_SOURCE);
830 #endif
832 #ifdef _ISOC99_SOURCE
833     printf("_ISOC99_SOURCE defined\\n");
834 #endif
836 #ifdef _ISOC11_SOURCE
837     printf("_ISOC11_SOURCE defined\\n");
838 #endif
840 #ifdef _XOPEN_SOURCE
841     printf("_XOPEN_SOURCE defined: %d\\n", _XOPEN_SOURCE);
842 #endif
844 #ifdef _XOPEN_SOURCE_EXTENDED
845     printf("_XOPEN_SOURCE_EXTENDED defined\\n");
846 #endif
848 #ifdef _LARGEFILE64_SOURCE
849     printf("_LARGEFILE64_SOURCE defined\\n");
850 #endif
852 #ifdef _FILE_OFFSET_BITS
853     printf("_FILE_OFFSET_BITS defined: %d\\n", _FILE_OFFSET_BITS);
854 #endif
856 #ifdef _BSD_SOURCE
857     printf("_BSD_SOURCE defined\\n");
858 #endif
860 #ifdef _SVID_SOURCE
861     printf("_SVID_SOURCE defined\\n");
862 #endif
864 #ifdef _DEFAULT_SOURCE
865     printf("_DEFAULT_SOURCE defined\\n");
866 #endif
868 #ifdef _ATFILE_SOURCE
869     printf("_ATFILE_SOURCE defined\\n");
870 #endif
872 #ifdef _GNU_SOURCE
873     printf("_GNU_SOURCE defined\\n");
874 #endif
876 #ifdef _REENTRANT
877     printf("_REENTRANT defined\\n");
878 #endif
880 #ifdef _THREAD_SAFE
881     printf("_THREAD_SAFE defined\\n");
882 #endif
884 #ifdef _FORTIFY_SOURCE
885     printf("_FORTIFY_SOURCE defined\\n");
886 #endif
888     exit(EXIT_SUCCESS);
891 .SH SEE ALSO
892 .BR libc (7),
893 .BR standards (7)
895 The section "Feature Test Macros" under
896 .IR "info libc" .
897 .\" But beware: the info libc document is out of date (Jul 07, mtk)
899 .I /usr/include/features.h