cdefs.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /* libc/sys/linux/sys/cdefs.h - Helper macros for K&R vs. ANSI C compat. */
  2. /* Written 2000 by Werner Almesberger */
  3. /*-
  4. * Copyright (c) 1991, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This code is derived from software contributed to Berkeley by
  8. * Berkeley Software Design, Inc.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 4. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * @(#)cdefs.h 8.8 (Berkeley) 1/9/95
  35. * $FreeBSD$
  36. */
  37. #ifndef _SYS_CDEFS_H_
  38. #define _SYS_CDEFS_H_
  39. #include <machine/_default_types.h>
  40. #include <sys/features.h>
  41. #include <stddef.h>
  42. #define __PMT(args) args
  43. #define __DOTS , ...
  44. #define __THROW
  45. #ifdef __GNUC__
  46. # define __ASMNAME(cname) __XSTRING (__USER_LABEL_PREFIX__) cname
  47. #endif
  48. #define __ptr_t void *
  49. #define __long_double_t long double
  50. #define __attribute_malloc__
  51. #define __attribute_pure__
  52. #define __attribute_format_strfmon__(a,b)
  53. #define __flexarr [0]
  54. #ifndef __BOUNDED_POINTERS__
  55. # define __bounded /* nothing */
  56. # define __unbounded /* nothing */
  57. # define __ptrvalue /* nothing */
  58. #endif
  59. /*
  60. * Testing against Clang-specific extensions.
  61. */
  62. #ifndef __has_extension
  63. #define __has_extension __has_feature
  64. #endif
  65. #ifndef __has_feature
  66. #define __has_feature(x) 0
  67. #endif
  68. #ifndef __has_include
  69. #define __has_include(x) 0
  70. #endif
  71. #ifndef __has_builtin
  72. #define __has_builtin(x) 0
  73. #endif
  74. #if defined(__cplusplus)
  75. #define __BEGIN_DECLS extern "C" {
  76. #define __END_DECLS }
  77. #else
  78. #define __BEGIN_DECLS
  79. #define __END_DECLS
  80. #endif
  81. /*
  82. * This code has been put in place to help reduce the addition of
  83. * compiler specific defines in FreeBSD code. It helps to aid in
  84. * having a compiler-agnostic source tree.
  85. */
  86. #if defined(__GNUC__) || defined(__INTEL_COMPILER)
  87. #if __GNUC__ >= 3 || defined(__INTEL_COMPILER)
  88. #define __GNUCLIKE_ASM 3
  89. #define __GNUCLIKE_MATH_BUILTIN_CONSTANTS
  90. #else
  91. #define __GNUCLIKE_ASM 2
  92. #endif
  93. #define __GNUCLIKE___TYPEOF 1
  94. #define __GNUCLIKE___OFFSETOF 1
  95. #define __GNUCLIKE___SECTION 1
  96. #ifndef __INTEL_COMPILER
  97. # define __GNUCLIKE_CTOR_SECTION_HANDLING 1
  98. #endif
  99. #define __GNUCLIKE_BUILTIN_CONSTANT_P 1
  100. # if defined(__INTEL_COMPILER) && defined(__cplusplus) \
  101. && __INTEL_COMPILER < 800
  102. # undef __GNUCLIKE_BUILTIN_CONSTANT_P
  103. # endif
  104. #if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER)
  105. # define __GNUCLIKE_BUILTIN_VARARGS 1
  106. # define __GNUCLIKE_BUILTIN_STDARG 1
  107. # define __GNUCLIKE_BUILTIN_VAALIST 1
  108. #endif
  109. #if defined(__GNUC__)
  110. # define __GNUC_VA_LIST_COMPATIBILITY 1
  111. #endif
  112. /*
  113. * Compiler memory barriers, specific to gcc and clang.
  114. */
  115. #if defined(__GNUC__)
  116. #define __compiler_membar() __asm __volatile(" " : : : "memory")
  117. #endif
  118. #ifndef __INTEL_COMPILER
  119. # define __GNUCLIKE_BUILTIN_NEXT_ARG 1
  120. # define __GNUCLIKE_MATH_BUILTIN_RELOPS
  121. #endif
  122. #define __GNUCLIKE_BUILTIN_MEMCPY 1
  123. /* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */
  124. #define __CC_SUPPORTS_INLINE 1
  125. #define __CC_SUPPORTS___INLINE 1
  126. #define __CC_SUPPORTS___INLINE__ 1
  127. #define __CC_SUPPORTS___FUNC__ 1
  128. #define __CC_SUPPORTS_WARNING 1
  129. #define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */
  130. #define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1
  131. #endif /* __GNUC__ || __INTEL_COMPILER */
  132. /*
  133. * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
  134. * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
  135. * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI
  136. * mode -- there must be no spaces between its arguments, and for nested
  137. * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also
  138. * concatenate double-quoted strings produced by the __STRING macro, but
  139. * this only works with ANSI C.
  140. *
  141. * __XSTRING is like __STRING, but it expands any macros in its argument
  142. * first. It is only available with ANSI C.
  143. */
  144. #if defined(__STDC__) || defined(__cplusplus)
  145. #define __P(protos) protos /* full-blown ANSI C */
  146. #define __CONCAT1(x,y) x ## y
  147. #define __CONCAT(x,y) __CONCAT1(x,y)
  148. #define __STRING(x) #x /* stringify without expanding x */
  149. #define __XSTRING(x) __STRING(x) /* expand x, then stringify */
  150. #define __const const /* define reserved names to standard */
  151. #define __signed signed
  152. #define __volatile volatile
  153. #if defined(__cplusplus)
  154. #define __inline inline /* convert to C++ keyword */
  155. #else
  156. #if !(defined(__CC_SUPPORTS___INLINE))
  157. #define __inline /* delete GCC keyword */
  158. #endif /* ! __CC_SUPPORTS___INLINE */
  159. #endif /* !__cplusplus */
  160. #else /* !(__STDC__ || __cplusplus) */
  161. #define __P(protos) () /* traditional C preprocessor */
  162. #define __CONCAT(x,y) x/**/y
  163. #define __STRING(x) "x"
  164. #if !defined(__CC_SUPPORTS___INLINE)
  165. #define __const /* delete pseudo-ANSI C keywords */
  166. #define __inline
  167. #define __signed
  168. #define __volatile
  169. /*
  170. * In non-ANSI C environments, new programs will want ANSI-only C keywords
  171. * deleted from the program and old programs will want them left alone.
  172. * When using a compiler other than gcc, programs using the ANSI C keywords
  173. * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS.
  174. * When using "gcc -traditional", we assume that this is the intent; if
  175. * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone.
  176. */
  177. #ifndef NO_ANSI_KEYWORDS
  178. #define const /* delete ANSI C keywords */
  179. #define inline
  180. #define signed
  181. #define volatile
  182. #endif /* !NO_ANSI_KEYWORDS */
  183. #endif /* !__CC_SUPPORTS___INLINE */
  184. #endif /* !(__STDC__ || __cplusplus) */
  185. /*
  186. * Compiler-dependent macros to help declare dead (non-returning) and
  187. * pure (no side effects) functions, and unused variables. They are
  188. * null except for versions of gcc that are known to support the features
  189. * properly (old versions of gcc-2 supported the dead and pure features
  190. * in a different (wrong) way). If we do not provide an implementation
  191. * for a given compiler, let the compile fail if it is told to use
  192. * a feature that we cannot live without.
  193. */
  194. #ifdef lint
  195. #define __dead2
  196. #define __pure2
  197. #define __unused
  198. #define __packed
  199. #define __aligned(x)
  200. #define __section(x)
  201. #else
  202. #if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER)
  203. #define __dead2
  204. #define __pure2
  205. #define __unused
  206. #endif
  207. #if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER)
  208. #define __dead2 __attribute__((__noreturn__))
  209. #define __pure2 __attribute__((__const__))
  210. #define __unused
  211. /* XXX Find out what to do for __packed, __aligned and __section */
  212. #endif
  213. #if __GNUC_PREREQ__(2, 7)
  214. #define __dead2 __attribute__((__noreturn__))
  215. #define __pure2 __attribute__((__const__))
  216. #define __unused __attribute__((__unused__))
  217. #define __used __attribute__((__used__))
  218. #define __packed __attribute__((__packed__))
  219. #define __aligned(x) __attribute__((__aligned__(x)))
  220. #define __section(x) __attribute__((__section__(x)))
  221. #endif
  222. #if defined(__INTEL_COMPILER)
  223. #define __dead2 __attribute__((__noreturn__))
  224. #define __pure2 __attribute__((__const__))
  225. #define __unused __attribute__((__unused__))
  226. #define __used __attribute__((__used__))
  227. #define __packed __attribute__((__packed__))
  228. #define __aligned(x) __attribute__((__aligned__(x)))
  229. #define __section(x) __attribute__((__section__(x)))
  230. #endif
  231. #endif
  232. #if !__GNUC_PREREQ__(2, 95)
  233. #define __alignof(x) __offsetof(struct { char __a; x __b; }, __b)
  234. #endif
  235. /*
  236. * Keywords added in C11.
  237. */
  238. #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L
  239. #if !__has_extension(c_alignas)
  240. #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
  241. __has_extension(cxx_alignas)
  242. #define _Alignas(x) alignas(x)
  243. #else
  244. /* XXX: Only emulates _Alignas(constant-expression); not _Alignas(type-name). */
  245. #define _Alignas(x) __aligned(x)
  246. #endif
  247. #endif
  248. #if defined(__cplusplus) && __cplusplus >= 201103L
  249. #define _Alignof(x) alignof(x)
  250. #else
  251. #define _Alignof(x) __alignof(x)
  252. #endif
  253. #if !__has_extension(c_atomic) && !__has_extension(cxx_atomic)
  254. /*
  255. * No native support for _Atomic(). Place object in structure to prevent
  256. * most forms of direct non-atomic access.
  257. */
  258. #define _Atomic(T) struct { T volatile __val; }
  259. #endif
  260. #if defined(__cplusplus) && __cplusplus >= 201103L
  261. #define _Noreturn [[noreturn]]
  262. #else
  263. #define _Noreturn __dead2
  264. #endif
  265. #if __GNUC_PREREQ__(4, 6) && !defined(__cplusplus)
  266. /* Do nothing: _Static_assert() works as per C11 */
  267. #elif !__has_extension(c_static_assert)
  268. #if (defined(__cplusplus) && __cplusplus >= 201103L) || \
  269. __has_extension(cxx_static_assert)
  270. #define _Static_assert(x, y) static_assert(x, y)
  271. #elif defined(__COUNTER__)
  272. #define _Static_assert(x, y) __Static_assert(x, __COUNTER__)
  273. #define __Static_assert(x, y) ___Static_assert(x, y)
  274. #define ___Static_assert(x, y) typedef char __assert_ ## y[(x) ? 1 : -1]
  275. #else
  276. #define _Static_assert(x, y) struct __hack
  277. #endif
  278. #endif
  279. #if !__has_extension(c_thread_local)
  280. /* XXX: Change this to test against C++11 when clang in base supports it. */
  281. #if /* (defined(__cplusplus) && __cplusplus >= 201103L) || */ \
  282. __has_extension(cxx_thread_local)
  283. #define _Thread_local thread_local
  284. #else
  285. #define _Thread_local __thread
  286. #endif
  287. #endif
  288. #endif /* __STDC_VERSION__ || __STDC_VERSION__ < 201112L */
  289. /*
  290. * Emulation of C11 _Generic(). Unlike the previously defined C11
  291. * keywords, it is not possible to implement this using exactly the same
  292. * syntax. Therefore implement something similar under the name
  293. * __generic(). Unlike _Generic(), this macro can only distinguish
  294. * between a single type, so it requires nested invocations to
  295. * distinguish multiple cases.
  296. */
  297. #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
  298. #define __generic(expr, t, yes, no) \
  299. _Generic(expr, t: yes, default: no)
  300. #elif __GNUC_PREREQ__(3, 1) && !defined(__cplusplus)
  301. #define __generic(expr, t, yes, no) \
  302. __builtin_choose_expr( \
  303. __builtin_types_compatible_p(__typeof(expr), t), yes, no)
  304. #endif
  305. #if __GNUC_PREREQ__(2, 96)
  306. #define __malloc_like __attribute__((__malloc__))
  307. #define __pure __attribute__((__pure__))
  308. #else
  309. #define __malloc_like
  310. #define __pure
  311. #endif
  312. #if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800)
  313. #define __always_inline __attribute__((__always_inline__))
  314. #else
  315. #define __always_inline
  316. #endif
  317. #if __GNUC_PREREQ__(3, 1)
  318. #define __noinline __attribute__ ((__noinline__))
  319. #else
  320. #define __noinline
  321. #endif
  322. #if __GNUC_PREREQ__(3, 3)
  323. #define __nonnull(x) __attribute__((__nonnull__(x)))
  324. #else
  325. #define __nonnull(x)
  326. #endif
  327. #if __GNUC_PREREQ__(3, 4)
  328. #define __fastcall __attribute__((__fastcall__))
  329. #else
  330. #define __fastcall
  331. #endif
  332. #if __GNUC_PREREQ__(4, 1)
  333. #define __returns_twice __attribute__((__returns_twice__))
  334. #else
  335. #define __returns_twice
  336. #endif
  337. /* XXX: should use `#if __STDC_VERSION__ < 199901'. */
  338. #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
  339. #define __func__ NULL
  340. #endif
  341. /*
  342. * GCC 2.95 provides `__restrict' as an extension to C90 to support the
  343. * C99-specific `restrict' type qualifier. We happen to use `__restrict' as
  344. * a way to define the `restrict' type qualifier without disturbing older
  345. * software that is unaware of C99 keywords.
  346. */
  347. #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95)
  348. #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 || defined(lint)
  349. #define __restrict
  350. #else
  351. #define __restrict restrict
  352. #endif
  353. #endif
  354. /*
  355. * GNU C version 2.96 adds explicit branch prediction so that
  356. * the CPU back-end can hint the processor and also so that
  357. * code blocks can be reordered such that the predicted path
  358. * sees a more linear flow, thus improving cache behavior, etc.
  359. *
  360. * The following two macros provide us with a way to utilize this
  361. * compiler feature. Use __predict_true() if you expect the expression
  362. * to evaluate to true, and __predict_false() if you expect the
  363. * expression to evaluate to false.
  364. *
  365. * A few notes about usage:
  366. *
  367. * * Generally, __predict_false() error condition checks (unless
  368. * you have some _strong_ reason to do otherwise, in which case
  369. * document it), and/or __predict_true() `no-error' condition
  370. * checks, assuming you want to optimize for the no-error case.
  371. *
  372. * * Other than that, if you don't know the likelihood of a test
  373. * succeeding from empirical or other `hard' evidence, don't
  374. * make predictions.
  375. *
  376. * * These are meant to be used in places that are run `a lot'.
  377. * It is wasteful to make predictions in code that is run
  378. * seldomly (e.g. at subsystem initialization time) as the
  379. * basic block reordering that this affects can often generate
  380. * larger code.
  381. */
  382. #if __GNUC_PREREQ__(2, 96)
  383. #define __predict_true(exp) __builtin_expect((exp), 1)
  384. #define __predict_false(exp) __builtin_expect((exp), 0)
  385. #else
  386. #define __predict_true(exp) (exp)
  387. #define __predict_false(exp) (exp)
  388. #endif
  389. #if __GNUC_PREREQ__(4, 2)
  390. #define __hidden __attribute__((__visibility__("hidden")))
  391. #define __exported __attribute__((__visibility__("default")))
  392. #else
  393. #define __hidden
  394. #define __exported
  395. #endif
  396. #define __offsetof(type, field) offsetof(type, field)
  397. #define __rangeof(type, start, end) \
  398. (__offsetof(type, end) - __offsetof(type, start))
  399. /*
  400. * Given the pointer x to the member m of the struct s, return
  401. * a pointer to the containing structure. When using GCC, we first
  402. * assign pointer x to a local variable, to check that its type is
  403. * compatible with member m.
  404. */
  405. #if __GNUC_PREREQ__(3, 1)
  406. #define __containerof(x, s, m) ({ \
  407. const volatile __typeof__(((s *)0)->m) *__x = (x); \
  408. __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
  409. })
  410. #else
  411. #define __containerof(x, s, m) \
  412. __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
  413. #endif
  414. /*
  415. * Compiler-dependent macros to declare that functions take printf-like
  416. * or scanf-like arguments. They are null except for versions of gcc
  417. * that are known to support the features properly (old versions of gcc-2
  418. * didn't permit keeping the keywords out of the application namespace).
  419. */
  420. #if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER)
  421. #define __printflike(fmtarg, firstvararg)
  422. #define __scanflike(fmtarg, firstvararg)
  423. #define __format_arg(fmtarg)
  424. #define __strfmonlike(fmtarg, firstvararg)
  425. #define __strftimelike(fmtarg, firstvararg)
  426. #else
  427. #define __printflike(fmtarg, firstvararg) \
  428. __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
  429. #define __scanflike(fmtarg, firstvararg) \
  430. __attribute__((__format__ (__scanf__, fmtarg, firstvararg)))
  431. #define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg)))
  432. #define __strfmonlike(fmtarg, firstvararg) \
  433. __attribute__((__format__ (__strfmon__, fmtarg, firstvararg)))
  434. #define __strftimelike(fmtarg, firstvararg) \
  435. __attribute__((__format__ (__strftime__, fmtarg, firstvararg)))
  436. #endif
  437. /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */
  438. #if defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 300001 && \
  439. defined(__GNUC__) && !defined(__INTEL_COMPILER)
  440. #define __printf0like(fmtarg, firstvararg) \
  441. __attribute__((__format__ (__printf0__, fmtarg, firstvararg)))
  442. #else
  443. #define __printf0like(fmtarg, firstvararg)
  444. #endif
  445. #if defined(__GNUC__) || defined(__INTEL_COMPILER)
  446. #ifndef __INTEL_COMPILER
  447. #define __strong_reference(sym,aliassym) \
  448. extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
  449. #endif
  450. #ifdef __ELF__
  451. #ifdef __STDC__
  452. #define __weak_reference(sym,alias) \
  453. __asm__(".weak " #alias); \
  454. __asm__(".equ " #alias ", " #sym)
  455. #define __warn_references(sym,msg) \
  456. __asm__(".section .gnu.warning." #sym); \
  457. __asm__(".asciz \"" msg "\""); \
  458. __asm__(".previous")
  459. #define __sym_compat(sym,impl,verid) \
  460. __asm__(".symver " #impl ", " #sym "@" #verid)
  461. #define __sym_default(sym,impl,verid) \
  462. __asm__(".symver " #impl ", " #sym "@@" #verid)
  463. #else
  464. #define __weak_reference(sym,alias) \
  465. __asm__(".weak alias"); \
  466. __asm__(".equ alias, sym")
  467. #define __warn_references(sym,msg) \
  468. __asm__(".section .gnu.warning.sym"); \
  469. __asm__(".asciz \"msg\""); \
  470. __asm__(".previous")
  471. #define __sym_compat(sym,impl,verid) \
  472. __asm__(".symver impl, sym@verid")
  473. #define __sym_default(impl,sym,verid) \
  474. __asm__(".symver impl, sym@@verid")
  475. #endif /* __STDC__ */
  476. #else /* !__ELF__ */
  477. #ifdef __STDC__
  478. #define __weak_reference(sym,alias) \
  479. __asm__(".stabs \"_" #alias "\",11,0,0,0"); \
  480. __asm__(".stabs \"_" #sym "\",1,0,0,0")
  481. #define __warn_references(sym,msg) \
  482. __asm__(".stabs \"" msg "\",30,0,0,0"); \
  483. __asm__(".stabs \"_" #sym "\",1,0,0,0")
  484. #else
  485. #define __weak_reference(sym,alias) \
  486. __asm__(".stabs \"_/**/alias\",11,0,0,0"); \
  487. __asm__(".stabs \"_/**/sym\",1,0,0,0")
  488. #define __warn_references(sym,msg) \
  489. __asm__(".stabs msg,30,0,0,0"); \
  490. __asm__(".stabs \"_/**/sym\",1,0,0,0")
  491. #endif /* __STDC__ */
  492. #endif /* __ELF__ */
  493. #endif /* __GNUC__ || __INTEL_COMPILER */
  494. #ifndef __FBSDID
  495. #define __FBSDID(s) struct __hack
  496. #endif
  497. #ifndef __RCSID
  498. #define __RCSID(s) struct __hack
  499. #endif
  500. #ifndef __RCSID_SOURCE
  501. #define __RCSID_SOURCE(s) struct __hack
  502. #endif
  503. #ifndef __SCCSID
  504. #define __SCCSID(s) struct __hack
  505. #endif
  506. #ifndef __COPYRIGHT
  507. #define __COPYRIGHT(s) struct __hack
  508. #endif
  509. #ifndef __DECONST
  510. #define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))
  511. #endif
  512. #ifndef __DEVOLATILE
  513. #define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))
  514. #endif
  515. #ifndef __DEQUALIFY
  516. #define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))
  517. #endif
  518. /*-
  519. * The following definitions are an extension of the behavior originally
  520. * implemented in <sys/_posix.h>, but with a different level of granularity.
  521. * POSIX.1 requires that the macros we test be defined before any standard
  522. * header file is included.
  523. *
  524. * Here's a quick run-down of the versions:
  525. * defined(_POSIX_SOURCE) 1003.1-1988
  526. * _POSIX_C_SOURCE == 1 1003.1-1990
  527. * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option
  528. * _POSIX_C_SOURCE == 199309 1003.1b-1993
  529. * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995,
  530. * and the omnibus ISO/IEC 9945-1: 1996
  531. * _POSIX_C_SOURCE == 200112 1003.1-2001
  532. * _POSIX_C_SOURCE == 200809 1003.1-2008
  533. *
  534. * In addition, the X/Open Portability Guide, which is now the Single UNIX
  535. * Specification, defines a feature-test macro which indicates the version of
  536. * that specification, and which subsumes _POSIX_C_SOURCE.
  537. *
  538. * Our macros begin with two underscores to avoid namespace screwage.
  539. */
  540. /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */
  541. #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1
  542. #undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */
  543. #define _POSIX_C_SOURCE 199009
  544. #endif
  545. /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */
  546. #if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2
  547. #undef _POSIX_C_SOURCE
  548. #define _POSIX_C_SOURCE 199209
  549. #endif
  550. /* Deal with various X/Open Portability Guides and Single UNIX Spec. */
  551. #ifdef _XOPEN_SOURCE
  552. #if _XOPEN_SOURCE - 0 >= 700
  553. #define __XSI_VISIBLE 700
  554. #undef _POSIX_C_SOURCE
  555. #define _POSIX_C_SOURCE 200809
  556. #elif _XOPEN_SOURCE - 0 >= 600
  557. #define __XSI_VISIBLE 600
  558. #undef _POSIX_C_SOURCE
  559. #define _POSIX_C_SOURCE 200112
  560. #elif _XOPEN_SOURCE - 0 >= 500
  561. #define __XSI_VISIBLE 500
  562. #undef _POSIX_C_SOURCE
  563. #define _POSIX_C_SOURCE 199506
  564. #endif
  565. #endif
  566. /*
  567. * Deal with all versions of POSIX. The ordering relative to the tests above is
  568. * important.
  569. */
  570. #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE)
  571. #define _POSIX_C_SOURCE 198808
  572. #endif
  573. #ifdef _POSIX_C_SOURCE
  574. #if _POSIX_C_SOURCE >= 200809
  575. #define __POSIX_VISIBLE 200809
  576. #define __ISO_C_VISIBLE 1999
  577. #elif _POSIX_C_SOURCE >= 200112
  578. #define __POSIX_VISIBLE 200112
  579. #define __ISO_C_VISIBLE 1999
  580. #elif _POSIX_C_SOURCE >= 199506
  581. #define __POSIX_VISIBLE 199506
  582. #define __ISO_C_VISIBLE 1990
  583. #elif _POSIX_C_SOURCE >= 199309
  584. #define __POSIX_VISIBLE 199309
  585. #define __ISO_C_VISIBLE 1990
  586. #elif _POSIX_C_SOURCE >= 199209
  587. #define __POSIX_VISIBLE 199209
  588. #define __ISO_C_VISIBLE 1990
  589. #elif _POSIX_C_SOURCE >= 199009
  590. #define __POSIX_VISIBLE 199009
  591. #define __ISO_C_VISIBLE 1990
  592. #else
  593. #define __POSIX_VISIBLE 198808
  594. #define __ISO_C_VISIBLE 0
  595. #endif /* _POSIX_C_SOURCE */
  596. #else
  597. /*-
  598. * Deal with _ANSI_SOURCE:
  599. * If it is defined, and no other compilation environment is explicitly
  600. * requested, then define our internal feature-test macros to zero. This
  601. * makes no difference to the preprocessor (undefined symbols in preprocessing
  602. * expressions are defined to have value zero), but makes it more convenient for
  603. * a test program to print out the values.
  604. *
  605. * If a program mistakenly defines _ANSI_SOURCE and some other macro such as
  606. * _POSIX_C_SOURCE, we will assume that it wants the broader compilation
  607. * environment (and in fact we will never get here).
  608. */
  609. #if defined(_ANSI_SOURCE) /* Hide almost everything. */
  610. #define __POSIX_VISIBLE 0
  611. #define __XSI_VISIBLE 0
  612. #define __BSD_VISIBLE 0
  613. #define __ISO_C_VISIBLE 1990
  614. #elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */
  615. #define __POSIX_VISIBLE 0
  616. #define __XSI_VISIBLE 0
  617. #define __BSD_VISIBLE 0
  618. #define __ISO_C_VISIBLE 1999
  619. #elif defined(_C11_SOURCE) /* Localism to specify strict C11 env. */
  620. #define __POSIX_VISIBLE 0
  621. #define __XSI_VISIBLE 0
  622. #define __BSD_VISIBLE 0
  623. #define __ISO_C_VISIBLE 2011
  624. #elif defined(_GNU_SOURCE) /* Everything and the kitchen sink. */
  625. #define __POSIX_VISIBLE 200809
  626. #define __XSI_VISIBLE 700
  627. #define __BSD_VISIBLE 1
  628. #define __ISO_C_VISIBLE 2011
  629. #define __GNU_VISIBLE 1
  630. #else /* Default: everything except __GNU_VISIBLE. */
  631. #define __POSIX_VISIBLE 200809
  632. #define __XSI_VISIBLE 700
  633. #define __BSD_VISIBLE 1
  634. #define __ISO_C_VISIBLE 2011
  635. #endif
  636. #endif
  637. #endif /* !_SYS_CDEFS_H_ */