cdefs.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /* Copyright (C) 1992-2023 Free Software Foundation, Inc.
  2. Copyright The GNU Toolchain Authors.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifndef _SYS_CDEFS_H
  16. #define _SYS_CDEFS_H 1
  17. /* We are almost always included from features.h. */
  18. #ifndef _FEATURES_H
  19. # include <features.h>
  20. #endif
  21. /* The GNU libc does not support any K&R compilers or the traditional mode
  22. of ISO C compilers anymore. Check for some of the combinations not
  23. supported anymore. */
  24. #if defined __GNUC__ && !defined __STDC__
  25. # error "You need a ISO C conforming compiler to use the glibc headers"
  26. #endif
  27. /* Some user header file might have defined this before. */
  28. #undef __P
  29. #undef __PMT
  30. /* Compilers that lack __has_attribute may object to
  31. #if defined __has_attribute && __has_attribute (...)
  32. even though they do not need to evaluate the right-hand side of the &&.
  33. Similarly for __has_builtin, etc. */
  34. #if (defined __has_attribute \
  35. && (!defined __clang_minor__ \
  36. || (defined __apple_build_version__ \
  37. ? 6000000 <= __apple_build_version__ \
  38. : 3 < __clang_major__ + (5 <= __clang_minor__))))
  39. # define __glibc_has_attribute(attr) __has_attribute (attr)
  40. #else
  41. # define __glibc_has_attribute(attr) 0
  42. #endif
  43. #ifdef __has_builtin
  44. # define __glibc_has_builtin(name) __has_builtin (name)
  45. #else
  46. # define __glibc_has_builtin(name) 0
  47. #endif
  48. #ifdef __has_extension
  49. # define __glibc_has_extension(ext) __has_extension (ext)
  50. #else
  51. # define __glibc_has_extension(ext) 0
  52. #endif
  53. #if defined __GNUC__ || defined __clang__
  54. /* All functions, except those with callbacks or those that
  55. synchronize memory, are leaf functions. */
  56. # if __GNUC_PREREQ (4, 6) && !defined _LIBC
  57. # define __LEAF , __leaf__
  58. # define __LEAF_ATTR __attribute__ ((__leaf__))
  59. # else
  60. # define __LEAF
  61. # define __LEAF_ATTR
  62. # endif
  63. /* GCC can always grok prototypes. For C++ programs we add throw()
  64. to help it optimize the function calls. But this only works with
  65. gcc 2.8.x and egcs. For gcc 3.4 and up we even mark C functions
  66. as non-throwing using a function attribute since programs can use
  67. the -fexceptions options for C code as well. */
  68. # if !defined __cplusplus \
  69. && (__GNUC_PREREQ (3, 4) || __glibc_has_attribute (__nothrow__))
  70. # define __THROW __attribute__ ((__nothrow__ __LEAF))
  71. # define __THROWNL __attribute__ ((__nothrow__))
  72. # define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct
  73. # define __NTHNL(fct) __attribute__ ((__nothrow__)) fct
  74. # else
  75. # if defined __cplusplus && (__GNUC_PREREQ (2,8) || __clang_major >= 4)
  76. # if __cplusplus >= 201103L
  77. # define __THROW noexcept (true)
  78. # else
  79. # define __THROW throw ()
  80. # endif
  81. # define __THROWNL __THROW
  82. # define __NTH(fct) __LEAF_ATTR fct __THROW
  83. # define __NTHNL(fct) fct __THROW
  84. # else
  85. # define __THROW
  86. # define __THROWNL
  87. # define __NTH(fct) fct
  88. # define __NTHNL(fct) fct
  89. # endif
  90. # endif
  91. #else /* Not GCC or clang. */
  92. # if (defined __cplusplus \
  93. || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L))
  94. # define __inline inline
  95. # else
  96. # define __inline /* No inline functions. */
  97. # endif
  98. # define __THROW
  99. # define __THROWNL
  100. # define __NTH(fct) fct
  101. #endif /* GCC || clang. */
  102. /* These two macros are not used in glibc anymore. They are kept here
  103. only because some other projects expect the macros to be defined. */
  104. #define __P(args) args
  105. #define __PMT(args) args
  106. /* For these things, GCC behaves the ANSI way normally,
  107. and the non-ANSI way under -traditional. */
  108. #define __CONCAT(x,y) x ## y
  109. #define __STRING(x) #x
  110. /* This is not a typedef so `const __ptr_t' does the right thing. */
  111. #define __ptr_t void *
  112. /* C++ needs to know that types and declarations are C, not C++. */
  113. #ifdef __cplusplus
  114. # define __BEGIN_DECLS extern "C" {
  115. # define __END_DECLS }
  116. #else
  117. # define __BEGIN_DECLS
  118. # define __END_DECLS
  119. #endif
  120. /* Fortify support. */
  121. #define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1)
  122. #define __bos0(ptr) __builtin_object_size (ptr, 0)
  123. /* Use __builtin_dynamic_object_size at _FORTIFY_SOURCE=3 when available. */
  124. #if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \
  125. || __GNUC_PREREQ (12, 0))
  126. # define __glibc_objsize0(__o) __builtin_dynamic_object_size (__o, 0)
  127. # define __glibc_objsize(__o) __builtin_dynamic_object_size (__o, 1)
  128. #else
  129. # define __glibc_objsize0(__o) __bos0 (__o)
  130. # define __glibc_objsize(__o) __bos (__o)
  131. #endif
  132. /* Compile time conditions to choose between the regular, _chk and _chk_warn
  133. variants. These conditions should get evaluated to constant and optimized
  134. away. */
  135. #define __glibc_safe_len_cond(__l, __s, __osz) ((__l) <= (__osz) / (__s))
  136. #define __glibc_unsigned_or_positive(__l) \
  137. ((__typeof (__l)) 0 < (__typeof (__l)) -1 \
  138. || (__builtin_constant_p (__l) && (__l) > 0))
  139. /* Length is known to be safe at compile time if the __L * __S <= __OBJSZ
  140. condition can be folded to a constant and if it is true, or unknown (-1) */
  141. #define __glibc_safe_or_unknown_len(__l, __s, __osz) \
  142. ((__osz) == (__SIZE_TYPE__) -1 \
  143. || (__glibc_unsigned_or_positive (__l) \
  144. && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
  145. (__s), (__osz))) \
  146. && __glibc_safe_len_cond ((__SIZE_TYPE__) (__l), (__s), (__osz))))
  147. /* Conversely, we know at compile time that the length is unsafe if the
  148. __L * __S <= __OBJSZ condition can be folded to a constant and if it is
  149. false. */
  150. #define __glibc_unsafe_len(__l, __s, __osz) \
  151. (__glibc_unsigned_or_positive (__l) \
  152. && __builtin_constant_p (__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), \
  153. __s, __osz)) \
  154. && !__glibc_safe_len_cond ((__SIZE_TYPE__) (__l), __s, __osz))
  155. /* Fortify function f. __f_alias, __f_chk and __f_chk_warn must be
  156. declared. */
  157. #define __glibc_fortify(f, __l, __s, __osz, ...) \
  158. (__glibc_safe_or_unknown_len (__l, __s, __osz) \
  159. ? __ ## f ## _alias (__VA_ARGS__) \
  160. : (__glibc_unsafe_len (__l, __s, __osz) \
  161. ? __ ## f ## _chk_warn (__VA_ARGS__, __osz) \
  162. : __ ## f ## _chk (__VA_ARGS__, __osz))) \
  163. /* Fortify function f, where object size argument passed to f is the number of
  164. elements and not total size. */
  165. #define __glibc_fortify_n(f, __l, __s, __osz, ...) \
  166. (__glibc_safe_or_unknown_len (__l, __s, __osz) \
  167. ? __ ## f ## _alias (__VA_ARGS__) \
  168. : (__glibc_unsafe_len (__l, __s, __osz) \
  169. ? __ ## f ## _chk_warn (__VA_ARGS__, (__osz) / (__s)) \
  170. : __ ## f ## _chk (__VA_ARGS__, (__osz) / (__s)))) \
  171. #if __GNUC_PREREQ (4,3)
  172. # define __warnattr(msg) __attribute__((__warning__ (msg)))
  173. # define __errordecl(name, msg) \
  174. extern void name (void) __attribute__((__error__ (msg)))
  175. #else
  176. # define __warnattr(msg)
  177. # define __errordecl(name, msg) extern void name (void)
  178. #endif
  179. /* Support for flexible arrays.
  180. Headers that should use flexible arrays only if they're "real"
  181. (e.g. only if they won't affect sizeof()) should test
  182. #if __glibc_c99_flexarr_available. */
  183. #if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L && !defined __HP_cc
  184. # define __flexarr []
  185. # define __glibc_c99_flexarr_available 1
  186. #elif __GNUC_PREREQ (2,97) || defined __clang__
  187. /* GCC 2.97 and clang support C99 flexible array members as an extension,
  188. even when in C89 mode or compiling C++ (any version). */
  189. # define __flexarr []
  190. # define __glibc_c99_flexarr_available 1
  191. #elif defined __GNUC__
  192. /* Pre-2.97 GCC did not support C99 flexible arrays but did have
  193. an equivalent extension with slightly different notation. */
  194. # define __flexarr [0]
  195. # define __glibc_c99_flexarr_available 1
  196. #else
  197. /* Some other non-C99 compiler. Approximate with [1]. */
  198. # define __flexarr [1]
  199. # define __glibc_c99_flexarr_available 0
  200. #endif
  201. /* __asm__ ("xyz") is used throughout the headers to rename functions
  202. at the assembly language level. This is wrapped by the __REDIRECT
  203. macro, in order to support compilers that can do this some other
  204. way. When compilers don't support asm-names at all, we have to do
  205. preprocessor tricks instead (which don't have exactly the right
  206. semantics, but it's the best we can do).
  207. Example:
  208. int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */
  209. #if (defined __GNUC__ && __GNUC__ >= 2) || (__clang_major__ >= 4)
  210. # define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias))
  211. # ifdef __cplusplus
  212. # define __REDIRECT_NTH(name, proto, alias) \
  213. name proto __THROW __asm__ (__ASMNAME (#alias))
  214. # define __REDIRECT_NTHNL(name, proto, alias) \
  215. name proto __THROWNL __asm__ (__ASMNAME (#alias))
  216. # else
  217. # define __REDIRECT_NTH(name, proto, alias) \
  218. name proto __asm__ (__ASMNAME (#alias)) __THROW
  219. # define __REDIRECT_NTHNL(name, proto, alias) \
  220. name proto __asm__ (__ASMNAME (#alias)) __THROWNL
  221. # endif
  222. # define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
  223. # define __ASMNAME2(prefix, cname) __STRING (prefix) cname
  224. /*
  225. #elif __SOME_OTHER_COMPILER__
  226. # define __REDIRECT(name, proto, alias) name proto; \
  227. _Pragma("let " #name " = " #alias)
  228. */
  229. #endif
  230. /* GCC and clang have various useful declarations that can be made with
  231. the '__attribute__' syntax. All of the ways we use this do fine if
  232. they are omitted for compilers that don't understand it. */
  233. #if !(defined __GNUC__ || defined __clang__)
  234. # define __attribute__(xyz) /* Ignore */
  235. #endif
  236. /* At some point during the gcc 2.96 development the `malloc' attribute
  237. for functions was introduced. We don't want to use it unconditionally
  238. (although this would be possible) since it generates warnings. */
  239. #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__malloc__)
  240. # define __attribute_malloc__ __attribute__ ((__malloc__))
  241. #else
  242. # define __attribute_malloc__ /* Ignore */
  243. #endif
  244. /* Tell the compiler which arguments to an allocation function
  245. indicate the size of the allocation. */
  246. #if __GNUC_PREREQ (4, 3)
  247. # define __attribute_alloc_size__(params) \
  248. __attribute__ ((__alloc_size__ params))
  249. #else
  250. # define __attribute_alloc_size__(params) /* Ignore. */
  251. #endif
  252. /* Tell the compiler which argument to an allocation function
  253. indicates the alignment of the allocation. */
  254. #if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__alloc_align__)
  255. # define __attribute_alloc_align__(param) \
  256. __attribute__ ((__alloc_align__ param))
  257. #else
  258. # define __attribute_alloc_align__(param) /* Ignore. */
  259. #endif
  260. /* At some point during the gcc 2.96 development the `pure' attribute
  261. for functions was introduced. We don't want to use it unconditionally
  262. (although this would be possible) since it generates warnings. */
  263. #if __GNUC_PREREQ (2,96) || __glibc_has_attribute (__pure__)
  264. # define __attribute_pure__ __attribute__ ((__pure__))
  265. #else
  266. # define __attribute_pure__ /* Ignore */
  267. #endif
  268. /* This declaration tells the compiler that the value is constant. */
  269. #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
  270. # define __attribute_const__ __attribute__ ((__const__))
  271. #else
  272. # define __attribute_const__ /* Ignore */
  273. #endif
  274. #if __GNUC_PREREQ (2,7) || __glibc_has_attribute (__unused__)
  275. # define __attribute_maybe_unused__ __attribute__ ((__unused__))
  276. #else
  277. # define __attribute_maybe_unused__ /* Ignore */
  278. #endif
  279. /* At some point during the gcc 3.1 development the `used' attribute
  280. for functions was introduced. We don't want to use it unconditionally
  281. (although this would be possible) since it generates warnings. */
  282. #if __GNUC_PREREQ (3,1) || __glibc_has_attribute (__used__)
  283. # define __attribute_used__ __attribute__ ((__used__))
  284. # define __attribute_noinline__ __attribute__ ((__noinline__))
  285. #else
  286. # define __attribute_used__ __attribute__ ((__unused__))
  287. # define __attribute_noinline__ /* Ignore */
  288. #endif
  289. /* Since version 3.2, gcc allows marking deprecated functions. */
  290. #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__deprecated__)
  291. # define __attribute_deprecated__ __attribute__ ((__deprecated__))
  292. #else
  293. # define __attribute_deprecated__ /* Ignore */
  294. #endif
  295. /* Since version 4.5, gcc also allows one to specify the message printed
  296. when a deprecated function is used. clang claims to be gcc 4.2, but
  297. may also support this feature. */
  298. #if __GNUC_PREREQ (4,5) \
  299. || __glibc_has_extension (__attribute_deprecated_with_message__)
  300. # define __attribute_deprecated_msg__(msg) \
  301. __attribute__ ((__deprecated__ (msg)))
  302. #else
  303. # define __attribute_deprecated_msg__(msg) __attribute_deprecated__
  304. #endif
  305. /* At some point during the gcc 2.8 development the `format_arg' attribute
  306. for functions was introduced. We don't want to use it unconditionally
  307. (although this would be possible) since it generates warnings.
  308. If several `format_arg' attributes are given for the same function, in
  309. gcc-3.0 and older, all but the last one are ignored. In newer gccs,
  310. all designated arguments are considered. */
  311. #if __GNUC_PREREQ (2,8) || __glibc_has_attribute (__format_arg__)
  312. # define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x)))
  313. #else
  314. # define __attribute_format_arg__(x) /* Ignore */
  315. #endif
  316. /* At some point during the gcc 2.97 development the `strfmon' format
  317. attribute for functions was introduced. We don't want to use it
  318. unconditionally (although this would be possible) since it
  319. generates warnings. */
  320. #if __GNUC_PREREQ (2,97) || __glibc_has_attribute (__format__)
  321. # define __attribute_format_strfmon__(a,b) \
  322. __attribute__ ((__format__ (__strfmon__, a, b)))
  323. #else
  324. # define __attribute_format_strfmon__(a,b) /* Ignore */
  325. #endif
  326. /* The nonnull function attribute marks pointer parameters that
  327. must not be NULL. This has the name __nonnull in glibc,
  328. and __attribute_nonnull__ in files shared with Gnulib to avoid
  329. collision with a different __nonnull in DragonFlyBSD 5.9. */
  330. #ifndef __attribute_nonnull__
  331. # if __GNUC_PREREQ (3,3) || __glibc_has_attribute (__nonnull__)
  332. # define __attribute_nonnull__(params) __attribute__ ((__nonnull__ params))
  333. # else
  334. # define __attribute_nonnull__(params)
  335. # endif
  336. #endif
  337. #ifndef __nonnull
  338. # define __nonnull(params) __attribute_nonnull__ (params)
  339. #endif
  340. /* The returns_nonnull function attribute marks the return type of the function
  341. as always being non-null. */
  342. #ifndef __returns_nonnull
  343. # if __GNUC_PREREQ (4, 9) || __glibc_has_attribute (__returns_nonnull__)
  344. # define __returns_nonnull __attribute__ ((__returns_nonnull__))
  345. # else
  346. # define __returns_nonnull
  347. # endif
  348. #endif
  349. /* If fortification mode, we warn about unused results of certain
  350. function calls which can lead to problems. */
  351. #if __GNUC_PREREQ (3,4) || __glibc_has_attribute (__warn_unused_result__)
  352. # define __attribute_warn_unused_result__ \
  353. __attribute__ ((__warn_unused_result__))
  354. # if defined __USE_FORTIFY_LEVEL && __USE_FORTIFY_LEVEL > 0
  355. # define __wur __attribute_warn_unused_result__
  356. # endif
  357. #else
  358. # define __attribute_warn_unused_result__ /* empty */
  359. #endif
  360. #ifndef __wur
  361. # define __wur /* Ignore */
  362. #endif
  363. /* Forces a function to be always inlined. */
  364. #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__)
  365. /* The Linux kernel defines __always_inline in stddef.h (283d7573), and
  366. it conflicts with this definition. Therefore undefine it first to
  367. allow either header to be included first. */
  368. # undef __always_inline
  369. # define __always_inline __inline __attribute__ ((__always_inline__))
  370. #else
  371. # undef __always_inline
  372. # define __always_inline __inline
  373. #endif
  374. /* Associate error messages with the source location of the call site rather
  375. than with the source location inside the function. */
  376. #if __GNUC_PREREQ (4,3) || __glibc_has_attribute (__artificial__)
  377. # define __attribute_artificial__ __attribute__ ((__artificial__))
  378. #else
  379. # define __attribute_artificial__ /* Ignore */
  380. #endif
  381. /* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99
  382. inline semantics, unless -fgnu89-inline is used. Using __GNUC_STDC_INLINE__
  383. or __GNUC_GNU_INLINE is not a good enough check for gcc because gcc versions
  384. older than 4.3 may define these macros and still not guarantee GNU inlining
  385. semantics.
  386. clang++ identifies itself as gcc-4.2, but has support for GNU inlining
  387. semantics, that can be checked for by using the __GNUC_STDC_INLINE_ and
  388. __GNUC_GNU_INLINE__ macro definitions. */
  389. #if (!defined __cplusplus || __GNUC_PREREQ (4,3) \
  390. || (defined __clang__ && (defined __GNUC_STDC_INLINE__ \
  391. || defined __GNUC_GNU_INLINE__)))
  392. # if defined __GNUC_STDC_INLINE__ || defined __cplusplus
  393. # define __extern_inline extern __inline __attribute__ ((__gnu_inline__))
  394. # define __extern_always_inline \
  395. extern __always_inline __attribute__ ((__gnu_inline__))
  396. # else
  397. # define __extern_inline extern __inline
  398. # define __extern_always_inline extern __always_inline
  399. # endif
  400. #endif
  401. #ifdef __extern_always_inline
  402. # define __fortify_function __extern_always_inline __attribute_artificial__
  403. #endif
  404. /* GCC 4.3 and above allow passing all anonymous arguments of an
  405. __extern_always_inline function to some other vararg function. */
  406. #if __GNUC_PREREQ (4,3)
  407. # define __va_arg_pack() __builtin_va_arg_pack ()
  408. # define __va_arg_pack_len() __builtin_va_arg_pack_len ()
  409. #endif
  410. /* It is possible to compile containing GCC extensions even if GCC is
  411. run in pedantic mode if the uses are carefully marked using the
  412. `__extension__' keyword. But this is not generally available before
  413. version 2.8. */
  414. #if !(__GNUC_PREREQ (2,8) || defined __clang__)
  415. # define __extension__ /* Ignore */
  416. #endif
  417. /* __restrict is known in EGCS 1.2 and above, and in clang.
  418. It works also in C++ mode (outside of arrays), but only when spelled
  419. as '__restrict', not 'restrict'. */
  420. #if !(__GNUC_PREREQ (2,92) || __clang_major__ >= 3)
  421. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  422. # define __restrict restrict
  423. # else
  424. # define __restrict /* Ignore */
  425. # endif
  426. #endif
  427. /* ISO C99 also allows to declare arrays as non-overlapping. The syntax is
  428. array_name[restrict]
  429. GCC 3.1 and clang support this.
  430. This syntax is not usable in C++ mode. */
  431. #if (__GNUC_PREREQ (3,1) || __clang_major__ >= 3) && !defined __cplusplus
  432. # define __restrict_arr __restrict
  433. #else
  434. # ifdef __GNUC__
  435. # define __restrict_arr /* Not supported in old GCC. */
  436. # else
  437. # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
  438. # define __restrict_arr restrict
  439. # else
  440. /* Some other non-C99 compiler. */
  441. # define __restrict_arr /* Not supported. */
  442. # endif
  443. # endif
  444. #endif
  445. #if (__GNUC__ >= 3) || __glibc_has_builtin (__builtin_expect)
  446. # define __glibc_unlikely(cond) __builtin_expect ((cond), 0)
  447. # define __glibc_likely(cond) __builtin_expect ((cond), 1)
  448. #else
  449. # define __glibc_unlikely(cond) (cond)
  450. # define __glibc_likely(cond) (cond)
  451. #endif
  452. #if (!defined _Noreturn \
  453. && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
  454. && !(__GNUC_PREREQ (4,7) \
  455. || (3 < __clang_major__ + (5 <= __clang_minor__))))
  456. # if __GNUC_PREREQ (2,8)
  457. # define _Noreturn __attribute__ ((__noreturn__))
  458. # else
  459. # define _Noreturn
  460. # endif
  461. #endif
  462. #if __GNUC_PREREQ (8, 0)
  463. /* Describes a char array whose address can safely be passed as the first
  464. argument to strncpy and strncat, as the char array is not necessarily
  465. a NUL-terminated string. */
  466. # define __attribute_nonstring__ __attribute__ ((__nonstring__))
  467. #else
  468. # define __attribute_nonstring__
  469. #endif
  470. /* Undefine (also defined in libc-symbols.h). */
  471. #undef __attribute_copy__
  472. #if __GNUC_PREREQ (9, 0)
  473. /* Copies attributes from the declaration or type referenced by
  474. the argument. */
  475. # define __attribute_copy__(arg) __attribute__ ((__copy__ (arg)))
  476. #else
  477. # define __attribute_copy__(arg)
  478. #endif
  479. #if (!defined _Static_assert && !defined __cplusplus \
  480. && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
  481. && (!(__GNUC_PREREQ (4, 6) || __clang_major__ >= 4) \
  482. || defined __STRICT_ANSI__))
  483. # define _Static_assert(expr, diagnostic) \
  484. extern int (*__Static_assert_function (void)) \
  485. [!!sizeof (struct { int __error_if_negative: (expr) ? 2 : -1; })]
  486. #endif
  487. /* Gnulib avoids including these, as they don't work on non-glibc or
  488. older glibc platforms. */
  489. #ifndef __GNULIB_CDEFS
  490. # include <bits/wordsize.h>
  491. # include <bits/long-double.h>
  492. #endif
  493. #if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  494. # ifdef __REDIRECT
  495. /* Alias name defined automatically. */
  496. # define __LDBL_REDIR(name, proto) ... unused__ldbl_redir
  497. # define __LDBL_REDIR_DECL(name) \
  498. extern __typeof (name) name __asm (__ASMNAME ("__" #name "ieee128"));
  499. /* Alias name defined automatically, with leading underscores. */
  500. # define __LDBL_REDIR2_DECL(name) \
  501. extern __typeof (__##name) __##name \
  502. __asm (__ASMNAME ("__" #name "ieee128"));
  503. /* Alias name defined manually. */
  504. # define __LDBL_REDIR1(name, proto, alias) ... unused__ldbl_redir1
  505. # define __LDBL_REDIR1_DECL(name, alias) \
  506. extern __typeof (name) name __asm (__ASMNAME (#alias));
  507. # define __LDBL_REDIR1_NTH(name, proto, alias) \
  508. __REDIRECT_NTH (name, proto, alias)
  509. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  510. __LDBL_REDIR1_NTH (name, proto, __##alias##ieee128)
  511. /* Unused. */
  512. # define __REDIRECT_LDBL(name, proto, alias) ... unused__redirect_ldbl
  513. # define __LDBL_REDIR_NTH(name, proto) ... unused__ldbl_redir_nth
  514. # else
  515. _Static_assert (0, "IEEE 128-bits long double requires redirection on this platform");
  516. # endif
  517. #elif defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
  518. # define __LDBL_COMPAT 1
  519. # ifdef __REDIRECT
  520. # define __LDBL_REDIR1(name, proto, alias) __REDIRECT (name, proto, alias)
  521. # define __LDBL_REDIR(name, proto) \
  522. __LDBL_REDIR1 (name, proto, __nldbl_##name)
  523. # define __LDBL_REDIR1_NTH(name, proto, alias) __REDIRECT_NTH (name, proto, alias)
  524. # define __LDBL_REDIR_NTH(name, proto) \
  525. __LDBL_REDIR1_NTH (name, proto, __nldbl_##name)
  526. # define __LDBL_REDIR2_DECL(name) \
  527. extern __typeof (__##name) __##name __asm (__ASMNAME ("__nldbl___" #name));
  528. # define __LDBL_REDIR1_DECL(name, alias) \
  529. extern __typeof (name) name __asm (__ASMNAME (#alias));
  530. # define __LDBL_REDIR_DECL(name) \
  531. extern __typeof (name) name __asm (__ASMNAME ("__nldbl_" #name));
  532. # define __REDIRECT_LDBL(name, proto, alias) \
  533. __LDBL_REDIR1 (name, proto, __nldbl_##alias)
  534. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  535. __LDBL_REDIR1_NTH (name, proto, __nldbl_##alias)
  536. # endif
  537. #endif
  538. #if (!defined __LDBL_COMPAT && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0) \
  539. || !defined __REDIRECT
  540. # define __LDBL_REDIR1(name, proto, alias) name proto
  541. # define __LDBL_REDIR(name, proto) name proto
  542. # define __LDBL_REDIR1_NTH(name, proto, alias) name proto __THROW
  543. # define __LDBL_REDIR_NTH(name, proto) name proto __THROW
  544. # define __LDBL_REDIR2_DECL(name)
  545. # define __LDBL_REDIR_DECL(name)
  546. # ifdef __REDIRECT
  547. # define __REDIRECT_LDBL(name, proto, alias) __REDIRECT (name, proto, alias)
  548. # define __REDIRECT_NTH_LDBL(name, proto, alias) \
  549. __REDIRECT_NTH (name, proto, alias)
  550. # endif
  551. #endif
  552. /* __glibc_macro_warning (MESSAGE) issues warning MESSAGE. This is
  553. intended for use in preprocessor macros.
  554. Note: MESSAGE must be a _single_ string; concatenation of string
  555. literals is not supported. */
  556. #if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
  557. # define __glibc_macro_warning1(message) _Pragma (#message)
  558. # define __glibc_macro_warning(message) \
  559. __glibc_macro_warning1 (GCC warning message)
  560. #else
  561. # define __glibc_macro_warning(msg)
  562. #endif
  563. /* Generic selection (ISO C11) is a C-only feature, available in GCC
  564. since version 4.9. Previous versions do not provide generic
  565. selection, even though they might set __STDC_VERSION__ to 201112L,
  566. when in -std=c11 mode. Thus, we must check for !defined __GNUC__
  567. when testing __STDC_VERSION__ for generic selection support.
  568. On the other hand, Clang also defines __GNUC__, so a clang-specific
  569. check is required to enable the use of generic selection. */
  570. #if !defined __cplusplus \
  571. && (__GNUC_PREREQ (4, 9) \
  572. || __glibc_has_extension (c_generic_selections) \
  573. || (!defined __GNUC__ && defined __STDC_VERSION__ \
  574. && __STDC_VERSION__ >= 201112L))
  575. # define __HAVE_GENERIC_SELECTION 1
  576. #else
  577. # define __HAVE_GENERIC_SELECTION 0
  578. #endif
  579. #if __GNUC_PREREQ (10, 0)
  580. /* Designates a 1-based positional argument ref-index of pointer type
  581. that can be used to access size-index elements of the pointed-to
  582. array according to access mode, or at least one element when
  583. size-index is not provided:
  584. access (access-mode, <ref-index> [, <size-index>]) */
  585. # define __attr_access(x) __attribute__ ((__access__ x))
  586. /* For _FORTIFY_SOURCE == 3 we use __builtin_dynamic_object_size, which may
  587. use the access attribute to get object sizes from function definition
  588. arguments, so we can't use them on functions we fortify. Drop the object
  589. size hints for such functions. */
  590. # if __USE_FORTIFY_LEVEL == 3
  591. # define __fortified_attr_access(a, o, s) __attribute__ ((__access__ (a, o)))
  592. # else
  593. # define __fortified_attr_access(a, o, s) __attr_access ((a, o, s))
  594. # endif
  595. # if __GNUC_PREREQ (11, 0)
  596. # define __attr_access_none(argno) __attribute__ ((__access__ (__none__, argno)))
  597. # else
  598. # define __attr_access_none(argno)
  599. # endif
  600. #else
  601. # define __fortified_attr_access(a, o, s)
  602. # define __attr_access(x)
  603. # define __attr_access_none(argno)
  604. #endif
  605. #if __GNUC_PREREQ (11, 0)
  606. /* Designates dealloc as a function to call to deallocate objects
  607. allocated by the declared function. */
  608. # define __attr_dealloc(dealloc, argno) \
  609. __attribute__ ((__malloc__ (dealloc, argno)))
  610. # define __attr_dealloc_free __attr_dealloc (__builtin_free, 1)
  611. #else
  612. # define __attr_dealloc(dealloc, argno)
  613. # define __attr_dealloc_free
  614. #endif
  615. /* Specify that a function such as setjmp or vfork may return
  616. twice. */
  617. #if __GNUC_PREREQ (4, 1)
  618. # define __attribute_returns_twice__ __attribute__ ((__returns_twice__))
  619. #else
  620. # define __attribute_returns_twice__ /* Ignore. */
  621. #endif
  622. #endif /* sys/cdefs.h */