cdefs.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /* Copyright (C) 1992-2016 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 _SYS_CDEFS_H
  15. #define _SYS_CDEFS_H 1
  16. /* We are almost always included from features.h. */
  17. #ifndef _FEATURES_H
  18. # include <features.h>
  19. #endif
  20. /* The GNU libc does not support any K&R compilers or the traditional mode
  21. of ISO C compilers anymore. Check for some of the combinations not
  22. anymore supported. */
  23. #if defined __GNUC__ && !defined __STDC__
  24. # error "You need a ISO C conforming compiler to use the glibc headers"
  25. #endif
  26. /* Some user header file might have defined this before. */
  27. #undef __P
  28. #undef __PMT
  29. #ifdef __GNUC__
  30. /* All functions, except those with callbacks or those that
  31. synchronize memory, are leaf functions. */
  32. # if __GNUC_PREREQ (4, 6) && !defined _LIBC
  33. # define __LEAF , __leaf__
  34. # define __LEAF_ATTR __attribute__ ((__leaf__))
  35. # else
  36. # define __LEAF
  37. # define __LEAF_ATTR
  38. # endif
  39. /* GCC can always grok prototypes. For C++ programs we add throw()
  40. to help it optimize the function calls. But this works only with
  41. gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions
  42. as non-throwing using a function attribute since programs can use
  43. the -fexceptions options for C code as well. */
  44. # if !defined __cplusplus && __GNUC_PREREQ (3, 3)
  45. # define __THROW __attribute__ ((__nothrow__ __LEAF))
  46. # define __THROWNL __attribute__ ((__nothrow__))
  47. # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
  48. # else
  49. # if defined __cplusplus && __GNUC_PREREQ (2,8)
  50. # define __THROW throw ()
  51. # define __THROWNL throw ()
  52. # define __NTH(fct) __LEAF_ATTR fct throw ()
  53. # else
  54. # define __THROW
  55. # define __THROWNL
  56. # define __NTH(fct) fct
  57. # endif
  58. # endif
  59. #else /* Not GCC. */
  60. # define __inline /* No inline functions. */
  61. # define __THROW
  62. # define __THROWNL
  63. # define __NTH(fct) fct
  64. #endif /* GCC. */
  65. /* These two macros are not used in glibc anymore. They are kept here
  66. only because some other projects expect the macros to be defined. */
  67. #define __P(args) args
  68. #define __PMT(args) args
  69. /* For these things, GCC behaves the ANSI way normally,
  70. and the non-ANSI way under -traditional. */
  71. #define __CONCAT(x,y) x ## y
  72. #define __STRING(x) #x
  73. /* This is not a typedef so `const __ptr_t' does the right thing. */
  74. #define __ptr_t void *
  75. #define __long_double_t long double
  76. /* C++ needs to know that types and declarations are C, not C++. */
  77. #ifdef __cplusplus
  78. # define __BEGIN_DECLS extern "C" {
  79. # define __END_DECLS }
  80. #else
  81. # define __BEGIN_DECLS
  82. # define __END_DECLS
  83. #endif
  84. /* The standard library needs the functions from the ISO C90 standard
  85. in the std namespace. At the same time we want to be safe for
  86. future changes and we include the ISO C99 code in the non-standard
  87. namespace __c99. The C++ wrapper header take case of adding the
  88. definitions to the global namespace. */
  89. #if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES
  90. # define __BEGIN_NAMESPACE_STD namespace std {
  91. # define __END_NAMESPACE_STD }
  92. # define __USING_NAMESPACE_STD(name) using std::name;
  93. # define __BEGIN_NAMESPACE_C99 namespace __c99 {
  94. # define __END_NAMESPACE_C99 }
  95. # define __USING_NAMESPACE_C99(name) using __c99::name;
  96. #else
  97. /* For compatibility we do not add the declarations into any
  98. namespace. They will end up in the global namespace which is what
  99. old code expects. */
  100. # define __BEGIN_NAMESPACE_STD
  101. # define __END_NAMESPACE_STD
  102. # define __USING_NAMESPACE_STD(name)
  103. # define __BEGIN_NAMESPACE_C99
  104. # define __END_NAMESPACE_C99
  105. # define __USING_NAMESPACE_C99(name)
  106. #endif
  107. /* Fortify support. */
  108. #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
  109. #define __bos0(ptr) __builtin_object_size (ptr, 0)
  110. #if __GNUC_PREREQ (4,3)
  111. # define __warndecl(name, msg) \
  112. extern void name (void) __attribute__((__warning__ (msg)))
  113. # define __warnattr(msg) __attribute__((__warning__ (msg)))
  114. # define __errordecl(name, msg) \
  115. extern void name (void) __attribute__((__error__ (msg)))
  116. #else
  117. # define __warndecl(name, msg) extern void name (void)
  118. # define __warnattr(msg)
  119. # define __errordecl(name, msg) extern void name (void)
  120. #endif
  121. /* Support for flexible arrays. */
  122. #if __GNUC_PREREQ (2,97)
  123. /* GCC 2.97 supports C99 flexible array members. */
  124. # define __flexarr []
  125. #else
  126. # ifdef __GNUC__
  127. # define __flexarr [0]
  128. # else
  129. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  130. # define __flexarr []
  131. # else
  132. /* Some other non-C99 compiler. Approximate with [1]. */
  133. # define __flexarr [1]
  134. # endif
  135. # endif
  136. #endif
  137. /* __asm__ ("xyz") is used throughout the headers to rename functions
  138. at the assembly language level. This is wrapped by the __REDIRECT
  139. macro, in order to support compilers that can do this some other
  140. way. When compilers don't support asm-names at all, we have to do
  141. preprocessor tricks instead (which don't have exactly the right
  142. semantics, but it's the best we can do).
  143. Example:
  144. int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
  145. #if defined __GNUC__ && __GNUC__ >= 2
  146. # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
  147. # ifdef __cplusplus
  148. # define __REDIRECT_NTH(name, proto, alias) \
  149. name proto __THROW __asm__ (__ASMNAME (#alias))
  150. # define __REDIRECT_NTHNL(name, proto, alias) \
  151. name proto __THROWNL __asm__ (__ASMNAME (#alias))
  152. # else
  153. # define __REDIRECT_NTH(name, proto, alias) \
  154. name proto __asm__ (__ASMNAME (#alias)) __THROW
  155. # define __REDIRECT_NTHNL(name, proto, alias) \
  156. name proto __asm__ (__ASMNAME (#alias)) __THROWNL
  157. # endif
  158. # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
  159. # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
  160. /*
  161. #elif __SOME_OTHER_COMPILER__
  162. # define __REDIRECT(name, proto, alias) name proto; \
  163. _Pragma("let " #name " = " #alias)
  164. */
  165. #endif
  166. /* GCC has various useful declarations that can be made with the
  167. `__attribute__' syntax. All of the ways we use this do fine if
  168. they are omitted for compilers that don't understand it. */
  169. #if !defined __GNUC__ || __GNUC__ < 2
  170. # define __attribute__(xyz) /* Ignore */
  171. #endif
  172. /* At some point during the gcc 2.96 development the `malloc' attribute
  173. for functions was introduced. We don't want to use it unconditionally
  174. (although this would be possible) since it generates warnings. */
  175. #if __GNUC_PREREQ (2,96)
  176. # define __attribute_malloc__ __attribute__ ((__malloc__))
  177. #else
  178. # define __attribute_malloc__ /* Ignore */
  179. #endif
  180. /* Tell the compiler which arguments to an allocation function
  181. indicate the size of the allocation. */
  182. #if __GNUC_PREREQ (4, 3)
  183. # define __attribute_alloc_size__(params) \
  184. __attribute__ ((__alloc_size__ params))
  185. #else
  186. # define __attribute_alloc_size__(params) /* Ignore. */
  187. #endif
  188. /* At some point during the gcc 2.96 development the `pure' attribute
  189. for functions was introduced. We don't want to use it unconditionally
  190. (although this would be possible) since it generates warnings. */
  191. #if __GNUC_PREREQ (2,96)
  192. # define __attribute_pure__ __attribute__ ((__pure__))
  193. #else
  194. # define __attribute_pure__ /* Ignore */
  195. #endif
  196. /* This declaration tells the compiler that the value is constant. */
  197. #if __GNUC_PREREQ (2,5)
  198. # define __attribute_const__ __attribute__ ((__const__))
  199. #else
  200. # define __attribute_const__ /* Ignore */
  201. #endif
  202. /* At some point during the gcc 3.1 development the `used' attribute
  203. for functions was introduced. We don't want to use it unconditionally
  204. (although this would be possible) since it generates warnings. */
  205. #if __GNUC_PREREQ (3,1)
  206. # define __attribute_used__ __attribute__ ((__used__))
  207. # define __attribute_noinline__ __attribute__ ((__noinline__))
  208. #else
  209. # define __attribute_used__ __attribute__ ((__unused__))
  210. # define __attribute_noinline__ /* Ignore */
  211. #endif
  212. /* gcc allows marking deprecated functions. */
  213. #if __GNUC_PREREQ (3,2)
  214. # define __attribute_deprecated__ __attribute__ ((__deprecated__))
  215. #else
  216. # define __attribute_deprecated__ /* Ignore */
  217. #endif
  218. /* At some point during the gcc 2.8 development the `format_arg' attribute
  219. for functions was introduced. We don't want to use it unconditionally
  220. (although this would be possible) since it generates warnings.
  221. If several `format_arg' attributes are given for the same function, in
  222. gcc-3.0 and older, all but the last one are ignored. In newer gccs,
  223. all designated arguments are considered. */
  224. #if __GNUC_PREREQ (2,8)
  225. # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
  226. #else
  227. # define __attribute_format_arg__(x) /* Ignore */
  228. #endif
  229. /* At some point during the gcc 2.97 development the `strfmon' format
  230. attribute for functions was introduced. We don't want to use it
  231. unconditionally (although this would be possible) since it
  232. generates warnings. */
  233. #if __GNUC_PREREQ (2,97)
  234. # define __attribute_format_strfmon__(a,b) \
  235. __attribute__ ((__format__ (__strfmon__, a, b)))
  236. #else
  237. # define __attribute_format_strfmon__(a,b) /* Ignore */
  238. #endif
  239. /* The nonull function attribute allows to mark pointer parameters which
  240. must not be NULL. */
  241. #if __GNUC_PREREQ (3,3)
  242. # define __nonnull(params) __attribute__ ((__nonnull__ params))
  243. #else
  244. # define __nonnull(params)
  245. #endif
  246. /* If fortification mode, we warn about unused results of certain
  247. function calls which can lead to problems. */
  248. #if __GNUC_PREREQ (3,4)
  249. # define __attribute_warn_unused_result__ \
  250. __attribute__ ((__warn_unused_result__))
  251. # if __USE_FORTIFY_LEVEL > 0
  252. # define __wur __attribute_warn_unused_result__
  253. # endif
  254. #else
  255. # define __attribute_warn_unused_result__ /* empty */
  256. #endif
  257. #ifndef __wur
  258. # define __wur /* Ignore */
  259. #endif
  260. /* Forces a function to be always inlined. */
  261. #if __GNUC_PREREQ (3,2)
  262. # define __always_inline __inline __attribute__ ((__always_inline__))
  263. #else
  264. # define __always_inline __inline
  265. #endif
  266. /* Associate error messages with the source location of the call site rather
  267. than with the source location inside the function. */
  268. #if __GNUC_PREREQ (4,3)
  269. # define __attribute_artificial__ __attribute__ ((__artificial__))
  270. #else
  271. # define __attribute_artificial__ /* Ignore */
  272. #endif
  273. /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
  274. inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
  275. or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
  276. older than 4.3 may define these macros and still not guarantee GNU inlining
  277. semantics.
  278. clang++ identifies itself as gcc-4.2, but has support for GNU inlining
  279. semantics, that can be checked fot by using the __GNUC_STDC_INLINE_ and
  280. __GNUC_GNU_INLINE__ macro definitions. */
  281. #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
  282. || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
  283. || defined __GNUC_GNU_INLINE__)))
  284. # if defined __GNUC_STDC_INLINE__ || defined __cplusplus
  285. # define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
  286. # define __extern_always_inline \
  287. extern __always_inline __attribute__ ((__gnu_inline__))
  288. # else
  289. # define __extern_inline extern __inline
  290. # define __extern_always_inline extern __always_inline
  291. # endif
  292. #endif
  293. #ifdef __extern_always_inline
  294. # define __fortify_function __extern_always_inline __attribute_artificial__
  295. #endif
  296. /* GCC 4.3 and above allow passing all anonymous arguments of an
  297. __extern_always_inline function to some other vararg function. */
  298. #if __GNUC_PREREQ (4,3)
  299. # define __va_arg_pack() __builtin_va_arg_pack ()
  300. # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
  301. #endif
  302. /* It is possible to compile containing GCC extensions even if GCC is
  303. run in pedantic mode if the uses are carefully marked using the
  304. `__extension__' keyword. But this is not generally available before
  305. version 2.8. */
  306. #if !__GNUC_PREREQ (2,8)
  307. # define __extension__ /* Ignore */
  308. #endif
  309. /* __restrict is known in EGCS 1.2 and above. */
  310. #if !__GNUC_PREREQ (2,92)
  311. # define __restrict /* Ignore */
  312. #endif
  313. /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
  314. array_name[restrict]
  315. GCC 3.1 supports this. */
  316. #if __GNUC_PREREQ (3,1) && !defined __GNUG__
  317. # define __restrict_arr __restrict
  318. #else
  319. # ifdef __GNUC__
  320. # define __restrict_arr /* Not supported in old GCC. */
  321. # else
  322. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  323. # define __restrict_arr restrict
  324. # else
  325. /* Some other non-C99 compiler. */
  326. # define __restrict_arr /* Not supported. */
  327. # endif
  328. # endif
  329. #endif
  330. #if __GNUC__ >= 3
  331. # define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
  332. # define __glibc_likely(cond) __builtin_expect ((cond), 1)
  333. #else
  334. # define __glibc_unlikely(cond) (cond)
  335. # define __glibc_likely(cond) (cond)
  336. #endif
  337. #if (!defined _Noreturn \
  338. && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
  339. && !__GNUC_PREREQ (4,7))
  340. # if __GNUC_PREREQ (2,8)
  341. # define _Noreturn __attribute__ ((__noreturn__))
  342. # else
  343. # define _Noreturn
  344. # endif
  345. #endif
  346. #if (!defined _Static_assert && !defined __cplusplus \
  347. && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
  348. && (!__GNUC_PREREQ (4, 6) || defined __STRICT_ANSI__))
  349. # define _Static_assert(expr, diagnostic) \
  350. extern int (*__Static_assert_function (void)) \
  351. [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
  352. #endif
  353. #include <bits/wordsize.h>
  354. #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
  355. # define __LDBL_COMPAT 1
  356. # ifdef __REDIRECT
  357. # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
  358. # define __LDBL_REDIR(name, proto) \
  359. __LDBL_REDIR1 (name, proto, __nldbl_##name)
  360. # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
  361. # define __LDBL_REDIR_NTH(name, proto) \
  362. __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
  363. # define __LDBL_REDIR1_DECL(name, alias) \
  364. extern __typeof (name) name __asm (__ASMNAME (#alias));
  365. # define __LDBL_REDIR_DECL(name) \
  366. extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
  367. # define __REDIRECT_LDBL(name, proto, alias) \
  368. __LDBL_REDIR1 (name, proto, __nldbl_##alias)
  369. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  370. __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
  371. # endif
  372. #endif
  373. #if !defined __LDBL_COMPAT || !defined __REDIRECT
  374. # define __LDBL_REDIR1(name, proto, alias) name proto
  375. # define __LDBL_REDIR(name, proto) name proto
  376. # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
  377. # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
  378. # define __LDBL_REDIR_DECL(name)
  379. # ifdef __REDIRECT
  380. # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
  381. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  382. __REDIRECT_NTH (name, proto, alias)
  383. # endif
  384. #endif
  385. #endif /* sys/cdefs.h */