.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
-.TH FEATURE_TEST_MACROS 7 2012-08-05 "Linux" "Linux Programmer's Manual"
+.TH FEATURE_TEST_MACROS 7 2014-03-13 "Linux" "Linux Programmer's Manual"
.SH NAME
feature_test_macros \- feature test macros
.SH SYNOPSIS
definitions for POSIX.1c (threads).
.IP \(bu
(Since glibc 2.3.3)
-The value 200112L or greater exposes definitions corresponding
-to the POSIX.1-2001 base specification (excluding the XSI extension).
+The value 200112L or greater additionally exposes definitions corresponding
+to the POSIX.1-2001 base specification (excluding the XSI extension)
+and also causes C95 (since glibc 2.12) and
+C99 (since glibc 2.10) features to be exposed.
.IP \(bu
(Since glibc 2.10)
-The value 200809L or greater exposes definitions corresponding
+The value 200809L or greater additionally exposes definitions corresponding
to the POSIX.1-2008 base specification (excluding the XSI extension).
.RE
.TP
definitions for SUSv4 (i.e., the POSIX.1-2008 base specification
plus the XSI extension).
.RE
+.IP
+If
+.B __STRICT_ANSI__
+is not defined, or
+.BR _XOPEN_SOURCE
+is defined with a value greater than or equal to 500
+.I and
+neither
+.B _POSIX_SOURCE
+not
+.B _POSIX_C_SOURCE
+is explicitly defined, then
+the following macros are implicitly defined:
+.RS
+.IP \(bu 3
+.B _POSIX_SOURCE
+is defined with the value 1.
+.IP \(bu
+.B _POSIX_C_SOURCE
+is defined, according to the value of
+.BR _XOPEN_SOURCE :
+.RS 7
+.TP
+.BR _XOPEN_SOURCE " < 500"
+.B _POSIX_C_SOURCE
+is defined with the value 2.
+.TP
+.RB "500 <= " _XOPEN_SOURCE " < 600"
+.B _POSIX_C_SOURCE
+is defined with the value 199506L.
+.TP
+.RB "600 <= " _XOPEN_SOURCE " < 700"
+.B _POSIX_C_SOURCE
+is defined with the value 200112L.
+.TP
+.RB "700 <= " _XOPEN_SOURCE " (since glibc 2.10)"
+.B _POSIX_C_SOURCE
+is defined with the value 200809L.
+.RE
+.RE
.TP
.B _XOPEN_SOURCE_EXTENDED
If this macro is defined, and
.B _XOPEN_SOURCE
is defined with a value of 500 or more.
.TP
-.B _ISOC95_SOURCE
-Exposes ISO C (1990) Amendment 1 definitions (also known as C95).
-This macro is recognized since glibc 2.12.
-The primary change in C95 was support for international character sets.
-The C95 changes were included in the subsequent C99 standard
-(in other words,
-.B _ISOC99_SOURCE
-implies
-.BR _ISOC95_SOURCE ).
-.TP
-.B _ISOC99_SOURCE
-Exposes C99 extensions to ISO C (1990).
-This macro is recognized since glibc 2.1.3;
-earlier glibc 2.1.x versions recognized an equivalent macro named
+.BR _ISOC99_SOURCE " (since glibc 2.1.3)"
+Exposes declarations consistent with the ISO C99 standard.
+
+Earlier glibc 2.1.x versions recognized an equivalent macro named
.B _ISOC9X_SOURCE
(because the C99 standard had not then been finalized).
-Although the use of the latter macro is obsolete, glibc continues
+Although the use of this macro is obsolete, glibc continues
to recognize it for backward compatibility.
+
+Defining
+.B _ISOC99_SOURCE
+also exposes ISO C (1990) Amendment 1 ("C95") definitions.
+(The primary change in C95 was support for international character sets.)
.TP
-.B _ISOC11_SOURCE
+.BR _ISOC11_SOURCE " (since glibc 2.16)"
Exposes declarations consistent with the ISO C11 standard.
-This macro is recognized since glibc 2.16.
+Defining this macro also enables C99 and C95 features (like
+.BR _ISOC99_SOURCE ).
.TP
.B _LARGEFILE64_SOURCE
Expose definitions for the alternative API specified by the
on 32-bit systems.
(Defining this macro permits correctly written programs to use
large files with only a recompilation being required.)
+
64-bit systems naturally permit file sizes greater than 2 Gigabytes,
and on those systems this macro has no effect.
.TP
-.B _BSD_SOURCE
+.BR _BSD_SOURCE " (deprecated since glibc 2.20)"
Defining this macro with any value causes header files to expose
BSD-derived definitions.
-Defining this macro also causes BSD definitions to be preferred in
+
+In glibc versions up to and including 2.18,
+defining this macro also causes BSD definitions to be preferred in
some situations where standards conflict, unless one or more of
.BR _SVID_SOURCE ,
.BR _POSIX_SOURCE ,
or
.B _GNU_SOURCE
is defined, in which case BSD definitions are disfavored.
+Since glibc 2.19,
+.B _BSD_SOURCE
+no longer causes BSD definitions to be preferred in case of conflicts.
+
+Since glibc 2.20, this macro is deprecated.
+.\" commit c941736c92fa3a319221f65f6755659b2a5e0a20
+.\" commit 498afc54dfee41d33ba519f496e96480badace8e
+.\" commit acd7f096d79c181866d56d4aaf3b043e741f1e2c
+It now has the same effect as defining
+.BR _DEFAULT_SOURCE ,
+but generates a compile-time warning (unless
+.BR _DEFAULT_SOURCE
+.\" commit ade40b10ff5fa59a318cf55b9d8414b758e8df78
+is also defined).
+Use
+.B _DEFAULT_SOURCE
+instead.
+To allow code that requires
+.BR _BSD_SOURCE
+in glibc 2.19 and earlier and
+.BR _DEFAULT_SOURCE
+in glibc 2.20 and later to compile without warnings, define
+.I both
+.B _BSD_SOURCE
+and
+.BR _DEFAULT_SOURCE .
.TP
-.B _SVID_SOURCE
+.BR _SVID_SOURCE " (deprecated since glibc 2.20)"
Defining this macro with any value causes header files to expose
System V-derived definitions.
(SVID == System V Interface Definition; see
.BR standards (7).)
+
+Since glibc 2.20, this macro is deprecated in the same fashion as
+.BR _BSD_SOURCE .
+.TP
+.BR _DEFAULT_SOURCE " (since glibc 2.19)"
+This macro can be defined to ensure that the "default"
+definitions are provided even when the defaults would otherwise
+be disabled,
+as happens when individual macros are explicitly defined,
+or the compiler is invoked in one of its "standard" modes (e.g.,
+.IR "cc\ \-std=c99" ).
+Defining
+.B _DEFAULT_SOURCE
+without defining other individual macros
+or invoking the compiler in one of its "standard" modes has no effect.
+
+The "default" definitions comprise those required by POSIX.1-2008
+as well as various definitions derived from BSD and System V.
+On glibc 2.19 and earlier, these defaults were approximately equivalent
+to explicitly defining the following:
+
+ cc \-D_BSD_SOURCE \-D_SVID_SOURCE \-D_POSIX_C_SOURCE=200809
+
.TP
.BR _ATFILE_SOURCE " (since glibc 2.4)"
Defining this macro with any value causes header files to expose
is defined with a value greater than or equal to 200809L.
.TP
.B _GNU_SOURCE
-Defining this macro (with any value) is equivalent to defining
-.BR _BSD_SOURCE ,
-.BR _SVID_SOURCE ,
+Defining this macro (with any value) implicitly defines
.BR _ATFILE_SOURCE ,
.BR _LARGEFILE64_SOURCE ,
.BR _ISOC99_SOURCE ,
(600 in glibc versions before 2.10;
500 in glibc versions before 2.2).
In addition, various GNU-specific extensions are also exposed.
-Where standards conflict, BSD definitions are disfavored.
+
+Since glibc 2.19, defining
+.BR _GNU_SOURCE
+also has the effect of implicitly defining
+.BR _DEFAULT_SOURCE .
+In glibc versions before 2.20, defining
+.BR _GNU_SOURCE
+also had the effect of implicitly defining
+.BR _BSD_SOURCE
+and
+.BR _SVID_SOURCE .
.TP
.B _REENTRANT
Defining this macro exposes definitions of certain reentrant functions.
to detect some buffer overflow errors when employing
various string and memory manipulation functions.
Not all buffer overflows are detected, just some common cases.
+
In the current implementation, checks are added for
calls to
.BR memcpy (3),
.BR vsnprintf (3),
and
.BR gets (3).
+
If
.B _FORTIFY_SOURCE
is set to 1, with compiler optimization level 1
and result in compiler warnings;
other checks take place at run time,
and result in a run-time error if the check fails.
+
Use of this macro requires compiler support, available with
.BR gcc (1)
since version 4.0.
.PP
If no feature test macros are explicitly defined,
then the following feature test macros are defined by default:
-.BR _BSD_SOURCE ,
-.BR _SVID_SOURCE ,
+.BR _BSD_SOURCE
+(in glibc 2.19 and earlier),
+.BR _SVID_SOURCE
+(in glibc 2.19 and earlier),
+.BR _DEFAULT_SOURCE
+(since glibc 2.19),
.BR _POSIX_SOURCE ,
and
.BR _POSIX_C_SOURCE =200809L
.BR _POSIX_C_SOURCE ,
.BR _XOPEN_SOURCE ,
.BR _XOPEN_SOURCE_EXTENDED ,
-.BR _BSD_SOURCE ,
+.BR _BSD_SOURCE
+(in glibc 2.19 and earlier),
or
.B _SVID_SOURCE
+(in glibc 2.19 and earlier)
is explicitly defined, then
.BR _BSD_SOURCE ,
+.BR _SVID_SOURCE ,
and
-.B _SVID_SOURCE
+.BR _DEFAULT_SOURCE
are not defined by default.
If
is not defined or
.B _XOPEN_SOURCE
is defined with a value of 500 or more, then
-.RS 3
.IP * 3
.B _POSIX_SOURCE
is defined with the value 1; and
.IP *
.B _POSIX_C_SOURCE
is defined with one of the following values:
-.RS 6
+.RS 3
.IP \(bu 3
2,
if
-.B XOPEN_SOURCE
+.B _XOPEN_SOURCE
is defined with a value less than 500;
.IP \(bu
199506L,
if
-.B XOPEN_SOURCE
+.B _XOPEN_SOURCE
is defined with a value greater than or equal to 500 and less than 600;
or
.IP \(bu
(since glibc 2.4) 200112L,
if
-.B XOPEN_SOURCE
+.B _XOPEN_SOURCE
is defined with a value greater than or equal to 600 and less than 700.
.IP \(bu
(Since glibc 2.10)
200809L,
if
-.B XOPEN_SOURCE
+.B _XOPEN_SOURCE
is defined with a value greater than or equal to 700.
.IP \(bu
Older versions of glibc do not know about the values
200112L, in glibc 2.4 to 2.9; and
200809L, since glibc 2.10.
.RE
-.RE
.PP
Multiple macros can be defined; the results are additive.
.SH CONFORMING TO
.BR _BSD_SOURCE ,
.BR _SVID_SOURCE ,
+.BR _DEFAULT_SOURCE ,
.BR _ATFILE_SOURCE ,
.BR _GNU_SOURCE ,
.BR _FORTIFY_SOURCE ,
printf("_ISOC99_SOURCE defined\\n");
#endif
+#ifdef _ISOC11_SOURCE
+ printf("_ISOC11_SOURCE defined\\n");
+#endif
+
#ifdef _XOPEN_SOURCE
printf("_XOPEN_SOURCE defined: %d\\n", _XOPEN_SOURCE);
#endif
printf("_SVID_SOURCE defined\\n");
#endif
+#ifdef _DEFAULT_SOURCE
+ printf("_DEFAULT_SOURCE defined\\n");
+#endif
+
#ifdef _ATFILE_SOURCE
printf("_ATFILE_SOURCE defined\\n");
#endif