features.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /* Copyright (C) 1991-2017 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #ifndef _FEATURES_H
  15. #define _FEATURES_H 1
  16. /* These are defined by the user (or the compiler)
  17. to specify the desired environment:
  18. __STRICT_ANSI__ ISO Standard C.
  19. _ISOC99_SOURCE Extensions to ISO C89 from ISO C99.
  20. _ISOC11_SOURCE Extensions to ISO C99 from ISO C11.
  21. __STDC_WANT_LIB_EXT2__
  22. Extensions to ISO C99 from TR 27431-2:2010.
  23. __STDC_WANT_IEC_60559_BFP_EXT__
  24. Extensions to ISO C11 from TS 18661-1:2014.
  25. __STDC_WANT_IEC_60559_FUNCS_EXT__
  26. Extensions to ISO C11 from TS 18661-4:2015.
  27. _POSIX_SOURCE IEEE Std 1003.1.
  28. _POSIX_C_SOURCE If ==1, like _POSIX_SOURCE; if >=2 add IEEE Std 1003.2;
  29. if >=199309L, add IEEE Std 1003.1b-1993;
  30. if >=199506L, add IEEE Std 1003.1c-1995;
  31. if >=200112L, all of IEEE 1003.1-2004
  32. if >=200809L, all of IEEE 1003.1-2008
  33. _XOPEN_SOURCE Includes POSIX and XPG things. Set to 500 if
  34. Single Unix conformance is wanted, to 600 for the
  35. sixth revision, to 700 for the seventh revision.
  36. _XOPEN_SOURCE_EXTENDED XPG things and X/Open Unix extensions.
  37. _LARGEFILE_SOURCE Some more functions for correct standard I/O.
  38. _LARGEFILE64_SOURCE Additional functionality from LFS for large files.
  39. _FILE_OFFSET_BITS=N Select default filesystem interface.
  40. _ATFILE_SOURCE Additional *at interfaces.
  41. _GNU_SOURCE All of the above, plus GNU extensions.
  42. _DEFAULT_SOURCE The default set of features (taking precedence over
  43. __STRICT_ANSI__).
  44. _FORTIFY_SOURCE Add security hardening to many library functions.
  45. Set to 1 or 2; 2 performs stricter checks than 1.
  46. _REENTRANT, _THREAD_SAFE
  47. Obsolete; equivalent to _POSIX_C_SOURCE=199506L.
  48. The `-ansi' switch to the GNU C compiler, and standards conformance
  49. options such as `-std=c99', define __STRICT_ANSI__. If none of
  50. these are defined, or if _DEFAULT_SOURCE is defined, the default is
  51. to have _POSIX_SOURCE set to one and _POSIX_C_SOURCE set to
  52. 200809L, as well as enabling miscellaneous functions from BSD and
  53. SVID. If more than one of these are defined, they accumulate. For
  54. example __STRICT_ANSI__, _POSIX_SOURCE and _POSIX_C_SOURCE together
  55. give you ISO C, 1003.1, and 1003.2, but nothing else.
  56. These are defined by this file and are used by the
  57. header files to decide what to declare or define:
  58. __GLIBC_USE (F) Define things from feature set F. This is defined
  59. to 1 or 0; the subsequent macros are either defined
  60. or undefined, and those tests should be moved to
  61. __GLIBC_USE.
  62. __USE_ISOC11 Define ISO C11 things.
  63. __USE_ISOC99 Define ISO C99 things.
  64. __USE_ISOC95 Define ISO C90 AMD1 (C95) things.
  65. __USE_POSIX Define IEEE Std 1003.1 things.
  66. __USE_POSIX2 Define IEEE Std 1003.2 things.
  67. __USE_POSIX199309 Define IEEE Std 1003.1, and .1b things.
  68. __USE_POSIX199506 Define IEEE Std 1003.1, .1b, .1c and .1i things.
  69. __USE_XOPEN Define XPG things.
  70. __USE_XOPEN_EXTENDED Define X/Open Unix things.
  71. __USE_UNIX98 Define Single Unix V2 things.
  72. __USE_XOPEN2K Define XPG6 things.
  73. __USE_XOPEN2KXSI Define XPG6 XSI things.
  74. __USE_XOPEN2K8 Define XPG7 things.
  75. __USE_XOPEN2K8XSI Define XPG7 XSI things.
  76. __USE_LARGEFILE Define correct standard I/O things.
  77. __USE_LARGEFILE64 Define LFS things with separate names.
  78. __USE_FILE_OFFSET64 Define 64bit interface as default.
  79. __USE_MISC Define things from 4.3BSD or System V Unix.
  80. __USE_ATFILE Define *at interfaces and AT_* constants for them.
  81. __USE_GNU Define GNU extensions.
  82. __USE_FORTIFY_LEVEL Additional security measures used, according to level.
  83. The macros `__GNU_LIBRARY__', `__GLIBC__', and `__GLIBC_MINOR__' are
  84. defined by this file unconditionally. `__GNU_LIBRARY__' is provided
  85. only for compatibility. All new code should use the other symbols
  86. to test for features.
  87. All macros listed above as possibly being defined by this file are
  88. explicitly undefined if they are not explicitly defined.
  89. Feature-test macros that are not defined by the user or compiler
  90. but are implied by the other feature-test macros defined (or by the
  91. lack of any definitions) are defined by the file.
  92. ISO C feature test macros depend on the definition of the macro
  93. when an affected header is included, not when the first system
  94. header is included, and so they are handled in
  95. <bits/libc-header-start.h>, which does not have a multiple include
  96. guard. Feature test macros that can be handled from the first
  97. system header included are handled here. */
  98. /* Undefine everything, so we get a clean slate. */
  99. #undef __USE_ISOC11
  100. #undef __USE_ISOC99
  101. #undef __USE_ISOC95
  102. #undef __USE_ISOCXX11
  103. #undef __USE_POSIX
  104. #undef __USE_POSIX2
  105. #undef __USE_POSIX199309
  106. #undef __USE_POSIX199506
  107. #undef __USE_XOPEN
  108. #undef __USE_XOPEN_EXTENDED
  109. #undef __USE_UNIX98
  110. #undef __USE_XOPEN2K
  111. #undef __USE_XOPEN2KXSI
  112. #undef __USE_XOPEN2K8
  113. #undef __USE_XOPEN2K8XSI
  114. #undef __USE_LARGEFILE
  115. #undef __USE_LARGEFILE64
  116. #undef __USE_FILE_OFFSET64
  117. #undef __USE_MISC
  118. #undef __USE_ATFILE
  119. #undef __USE_GNU
  120. #undef __USE_FORTIFY_LEVEL
  121. #undef __KERNEL_STRICT_NAMES
  122. /* Suppress kernel-name space pollution unless user expressedly asks
  123. for it. */
  124. #ifndef _LOOSE_KERNEL_NAMES
  125. # define __KERNEL_STRICT_NAMES
  126. #endif
  127. /* Convenience macro to test the version of gcc.
  128. Use like this:
  129. #if __GNUC_PREREQ (2,8)
  130. ... code requiring gcc 2.8 or later ...
  131. #endif
  132. Note: only works for GCC 2.0 and later, because __GNUC_MINOR__ was
  133. added in 2.0. */
  134. #if defined __GNUC__ && defined __GNUC_MINOR__
  135. # define __GNUC_PREREQ(maj, min) \
  136. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  137. #else
  138. # define __GNUC_PREREQ(maj, min) 0
  139. #endif
  140. /* Similarly for clang. Features added to GCC after version 4.2 may
  141. or may not also be available in clang, and clang's definitions of
  142. __GNUC(_MINOR)__ are fixed at 4 and 2 respectively. Not all such
  143. features can be queried via __has_extension/__has_feature. */
  144. #if defined __clang_major__ && defined __clang_minor__
  145. # define __glibc_clang_prereq(maj, min) \
  146. ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
  147. #else
  148. # define __glibc_clang_prereq(maj, min) 0
  149. #endif
  150. /* Whether to use feature set F. */
  151. #define __GLIBC_USE(F) __GLIBC_USE_ ## F
  152. /* _BSD_SOURCE and _SVID_SOURCE are deprecated aliases for
  153. _DEFAULT_SOURCE. If _DEFAULT_SOURCE is present we do not
  154. issue a warning; the expectation is that the source is being
  155. transitioned to use the new macro. */
  156. #if (defined _BSD_SOURCE || defined _SVID_SOURCE) \
  157. && !defined _DEFAULT_SOURCE
  158. # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
  159. # undef _DEFAULT_SOURCE
  160. # define _DEFAULT_SOURCE 1
  161. #endif
  162. /* If _GNU_SOURCE was defined by the user, turn on all the other features. */
  163. #ifdef _GNU_SOURCE
  164. # undef _ISOC95_SOURCE
  165. # define _ISOC95_SOURCE 1
  166. # undef _ISOC99_SOURCE
  167. # define _ISOC99_SOURCE 1
  168. # undef _ISOC11_SOURCE
  169. # define _ISOC11_SOURCE 1
  170. # undef _POSIX_SOURCE
  171. # define _POSIX_SOURCE 1
  172. # undef _POSIX_C_SOURCE
  173. # define _POSIX_C_SOURCE 200809L
  174. # undef _XOPEN_SOURCE
  175. # define _XOPEN_SOURCE 700
  176. # undef _XOPEN_SOURCE_EXTENDED
  177. # define _XOPEN_SOURCE_EXTENDED 1
  178. # undef _LARGEFILE64_SOURCE
  179. # define _LARGEFILE64_SOURCE 1
  180. # undef _DEFAULT_SOURCE
  181. # define _DEFAULT_SOURCE 1
  182. # undef _ATFILE_SOURCE
  183. # define _ATFILE_SOURCE 1
  184. #endif
  185. /* If nothing (other than _GNU_SOURCE and _DEFAULT_SOURCE) is defined,
  186. define _DEFAULT_SOURCE. */
  187. #if (defined _DEFAULT_SOURCE \
  188. || (!defined __STRICT_ANSI__ \
  189. && !defined _ISOC99_SOURCE \
  190. && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE \
  191. && !defined _XOPEN_SOURCE))
  192. # undef _DEFAULT_SOURCE
  193. # define _DEFAULT_SOURCE 1
  194. #endif
  195. /* This is to enable the ISO C11 extension. */
  196. #if (defined _ISOC11_SOURCE \
  197. || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L))
  198. # define __USE_ISOC11 1
  199. #endif
  200. /* This is to enable the ISO C99 extension. */
  201. #if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE \
  202. || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
  203. # define __USE_ISOC99 1
  204. #endif
  205. /* This is to enable the ISO C90 Amendment 1:1995 extension. */
  206. #if (defined _ISOC99_SOURCE || defined _ISOC11_SOURCE \
  207. || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199409L))
  208. # define __USE_ISOC95 1
  209. #endif
  210. /* This is to enable compatibility for ISO C++11.
  211. So far g++ does not provide a macro. Check the temporary macro for
  212. now, too. */
  213. #if ((defined __cplusplus && __cplusplus >= 201103L) \
  214. || defined __GXX_EXPERIMENTAL_CXX0X__)
  215. # define __USE_ISOCXX11 1
  216. #endif
  217. /* If none of the ANSI/POSIX macros are defined, or if _DEFAULT_SOURCE
  218. is defined, use POSIX.1-2008 (or another version depending on
  219. _XOPEN_SOURCE). */
  220. #ifdef _DEFAULT_SOURCE
  221. # if !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE
  222. # define __USE_POSIX_IMPLICITLY 1
  223. # endif
  224. # undef _POSIX_SOURCE
  225. # define _POSIX_SOURCE 1
  226. # undef _POSIX_C_SOURCE
  227. # define _POSIX_C_SOURCE 200809L
  228. #endif
  229. #if ((!defined __STRICT_ANSI__ \
  230. || (defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) >= 500)) \
  231. && !defined _POSIX_SOURCE && !defined _POSIX_C_SOURCE)
  232. # define _POSIX_SOURCE 1
  233. # if defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 500
  234. # define _POSIX_C_SOURCE 2
  235. # elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 600
  236. # define _POSIX_C_SOURCE 199506L
  237. # elif defined _XOPEN_SOURCE && (_XOPEN_SOURCE - 0) < 700
  238. # define _POSIX_C_SOURCE 200112L
  239. # else
  240. # define _POSIX_C_SOURCE 200809L
  241. # endif
  242. # define __USE_POSIX_IMPLICITLY 1
  243. #endif
  244. /* Some C libraries once required _REENTRANT and/or _THREAD_SAFE to be
  245. defined in all multithreaded code. GNU libc has not required this
  246. for many years. We now treat them as compatibility synonyms for
  247. _POSIX_C_SOURCE=199506L, which is the earliest level of POSIX with
  248. comprehensive support for multithreaded code. Using them never
  249. lowers the selected level of POSIX conformance, only raises it. */
  250. #if ((!defined _POSIX_C_SOURCE || (_POSIX_C_SOURCE - 0) < 199506L) \
  251. && (defined _REENTRANT || defined _THREAD_SAFE))
  252. # define _POSIX_SOURCE 1
  253. # undef _POSIX_C_SOURCE
  254. # define _POSIX_C_SOURCE 199506L
  255. #endif
  256. #if (defined _POSIX_SOURCE \
  257. || (defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 1) \
  258. || defined _XOPEN_SOURCE)
  259. # define __USE_POSIX 1
  260. #endif
  261. #if defined _POSIX_C_SOURCE && _POSIX_C_SOURCE >= 2 || defined _XOPEN_SOURCE
  262. # define __USE_POSIX2 1
  263. #endif
  264. #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199309L
  265. # define __USE_POSIX199309 1
  266. #endif
  267. #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 199506L
  268. # define __USE_POSIX199506 1
  269. #endif
  270. #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200112L
  271. # define __USE_XOPEN2K 1
  272. # undef __USE_ISOC95
  273. # define __USE_ISOC95 1
  274. # undef __USE_ISOC99
  275. # define __USE_ISOC99 1
  276. #endif
  277. #if defined _POSIX_C_SOURCE && (_POSIX_C_SOURCE - 0) >= 200809L
  278. # define __USE_XOPEN2K8 1
  279. # undef _ATFILE_SOURCE
  280. # define _ATFILE_SOURCE 1
  281. #endif
  282. #ifdef _XOPEN_SOURCE
  283. # define __USE_XOPEN 1
  284. # if (_XOPEN_SOURCE - 0) >= 500
  285. # define __USE_XOPEN_EXTENDED 1
  286. # define __USE_UNIX98 1
  287. # undef _LARGEFILE_SOURCE
  288. # define _LARGEFILE_SOURCE 1
  289. # if (_XOPEN_SOURCE - 0) >= 600
  290. # if (_XOPEN_SOURCE - 0) >= 700
  291. # define __USE_XOPEN2K8 1
  292. # define __USE_XOPEN2K8XSI 1
  293. # endif
  294. # define __USE_XOPEN2K 1
  295. # define __USE_XOPEN2KXSI 1
  296. # undef __USE_ISOC95
  297. # define __USE_ISOC95 1
  298. # undef __USE_ISOC99
  299. # define __USE_ISOC99 1
  300. # endif
  301. # else
  302. # ifdef _XOPEN_SOURCE_EXTENDED
  303. # define __USE_XOPEN_EXTENDED 1
  304. # endif
  305. # endif
  306. #endif
  307. #ifdef _LARGEFILE_SOURCE
  308. # define __USE_LARGEFILE 1
  309. #endif
  310. #ifdef _LARGEFILE64_SOURCE
  311. # define __USE_LARGEFILE64 1
  312. #endif
  313. #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
  314. # define __USE_FILE_OFFSET64 1
  315. #endif
  316. #if defined _DEFAULT_SOURCE
  317. # define __USE_MISC 1
  318. #endif
  319. #ifdef _ATFILE_SOURCE
  320. # define __USE_ATFILE 1
  321. #endif
  322. #ifdef _GNU_SOURCE
  323. # define __USE_GNU 1
  324. #endif
  325. #if defined _FORTIFY_SOURCE && _FORTIFY_SOURCE > 0
  326. # if !defined __OPTIMIZE__ || __OPTIMIZE__ <= 0
  327. # warning _FORTIFY_SOURCE requires compiling with optimization (-O)
  328. # elif !__GNUC_PREREQ (4, 1)
  329. # warning _FORTIFY_SOURCE requires GCC 4.1 or later
  330. # elif _FORTIFY_SOURCE > 1
  331. # define __USE_FORTIFY_LEVEL 2
  332. # else
  333. # define __USE_FORTIFY_LEVEL 1
  334. # endif
  335. #endif
  336. #ifndef __USE_FORTIFY_LEVEL
  337. # define __USE_FORTIFY_LEVEL 0
  338. #endif
  339. /* Get definitions of __STDC_* predefined macros, if the compiler has
  340. not preincluded this header automatically. */
  341. #include <stdc-predef.h>
  342. /* This macro indicates that the installed library is the GNU C Library.
  343. For historic reasons the value now is 6 and this will stay from now
  344. on. The use of this variable is deprecated. Use __GLIBC__ and
  345. __GLIBC_MINOR__ now (see below) when you want to test for a specific
  346. GNU C library version and use the values in <gnu/lib-names.h> to get
  347. the sonames of the shared libraries. */
  348. #undef __GNU_LIBRARY__
  349. #define __GNU_LIBRARY__ 6
  350. /* Major and minor version number of the GNU C library package. Use
  351. these macros to test for features in specific releases. */
  352. #define __GLIBC__ 2
  353. #define __GLIBC_MINOR__ 25
  354. #define __GLIBC_PREREQ(maj, min) \
  355. ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
  356. /* This is here only because every header file already includes this one. */
  357. #ifndef __ASSEMBLER__
  358. # ifndef _SYS_CDEFS_H
  359. # include <sys/cdefs.h>
  360. # endif
  361. /* If we don't have __REDIRECT, prototypes will be missing if
  362. __USE_FILE_OFFSET64 but not __USE_LARGEFILE[64]. */
  363. # if defined __USE_FILE_OFFSET64 && !defined __REDIRECT
  364. # define __USE_LARGEFILE 1
  365. # define __USE_LARGEFILE64 1
  366. # endif
  367. #endif /* !ASSEMBLER */
  368. /* Decide whether we can define 'extern inline' functions in headers. */
  369. #if __GNUC_PREREQ (2, 7) && defined __OPTIMIZE__ \
  370. && !defined __OPTIMIZE_SIZE__ && !defined __NO_INLINE__ \
  371. && defined __extern_inline
  372. # define __USE_EXTERN_INLINES 1
  373. #endif
  374. /* This is here only because every header file already includes this one.
  375. Get the definitions of all the appropriate `__stub_FUNCTION' symbols.
  376. <gnu/stubs.h> contains `#define __stub_FUNCTION' when FUNCTION is a stub
  377. that will always return failure (and set errno to ENOSYS). */
  378. #include <gnu/stubs.h>
  379. #endif /* features.h */