cdefs.h revision 189209
1139825Simp/*- 21541Srgrimes * Copyright (c) 1991, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed to Berkeley by 61541Srgrimes * Berkeley Software Design, Inc. 71541Srgrimes * 81541Srgrimes * Redistribution and use in source and binary forms, with or without 91541Srgrimes * modification, are permitted provided that the following conditions 101541Srgrimes * are met: 111541Srgrimes * 1. Redistributions of source code must retain the above copyright 121541Srgrimes * notice, this list of conditions and the following disclaimer. 131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer in the 151541Srgrimes * documentation and/or other materials provided with the distribution. 161541Srgrimes * 4. Neither the name of the University nor the names of its contributors 171541Srgrimes * may be used to endorse or promote products derived from this software 181541Srgrimes * without specific prior written permission. 191541Srgrimes * 201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301541Srgrimes * SUCH DAMAGE. 311541Srgrimes * 3214495Shsu * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 3350477Speter * $FreeBSD: head/sys/sys/cdefs.h 189209 2009-03-01 06:27:03Z das $ 341541Srgrimes */ 351541Srgrimes 362165Spaul#ifndef _SYS_CDEFS_H_ 372165Spaul#define _SYS_CDEFS_H_ 381541Srgrimes 391541Srgrimes#if defined(__cplusplus) 401541Srgrimes#define __BEGIN_DECLS extern "C" { 4136449Sdt#define __END_DECLS } 421541Srgrimes#else 431541Srgrimes#define __BEGIN_DECLS 441541Srgrimes#define __END_DECLS 451541Srgrimes#endif 461541Srgrimes 471541Srgrimes/* 48143063Sjoerg * This code has been put in place to help reduce the addition of 49143063Sjoerg * compiler specific defines in FreeBSD code. It helps to aid in 50143063Sjoerg * having a compiler-agnostic source tree. 51143063Sjoerg */ 52143063Sjoerg 53143063Sjoerg#if defined(__GNUC__) || defined(__INTEL_COMPILER) 54143063Sjoerg 55143063Sjoerg#if __GNUC__ >= 3 || defined(__INTEL_COMPILER) 56143063Sjoerg#define __GNUCLIKE_ASM 3 57143063Sjoerg#define __GNUCLIKE_MATH_BUILTIN_CONSTANTS 58143063Sjoerg#else 59143063Sjoerg#define __GNUCLIKE_ASM 2 60143063Sjoerg#endif 61143063Sjoerg#define __GNUCLIKE___TYPEOF 1 62143063Sjoerg#define __GNUCLIKE___OFFSETOF 1 63143063Sjoerg#define __GNUCLIKE___SECTION 1 64143063Sjoerg 65143063Sjoerg#define __GNUCLIKE_ATTRIBUTE_MODE_DI 1 66143063Sjoerg 67143063Sjoerg#ifndef __INTEL_COMPILER 68143063Sjoerg# define __GNUCLIKE_CTOR_SECTION_HANDLING 1 69143063Sjoerg#endif 70143063Sjoerg 71143063Sjoerg#define __GNUCLIKE_BUILTIN_CONSTANT_P 1 72143063Sjoerg# if defined(__INTEL_COMPILER) && defined(__cplusplus) \ 73143063Sjoerg && __INTEL_COMPILER < 800 74143063Sjoerg# undef __GNUCLIKE_BUILTIN_CONSTANT_P 75143063Sjoerg# endif 76143063Sjoerg 77150976Snetchild#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER) 78143063Sjoerg# define __GNUCLIKE_BUILTIN_VARARGS 1 79150976Snetchild# define __GNUCLIKE_BUILTIN_STDARG 1 80150976Snetchild# define __GNUCLIKE_BUILTIN_VAALIST 1 81143063Sjoerg#endif 82143063Sjoerg 83143063Sjoerg#if defined(__GNUC__) 84143063Sjoerg# define __GNUC_VA_LIST_COMPATIBILITY 1 85143063Sjoerg#endif 86143063Sjoerg 87143063Sjoerg#ifndef __INTEL_COMPILER 88143063Sjoerg# define __GNUCLIKE_BUILTIN_NEXT_ARG 1 89143063Sjoerg# define __GNUCLIKE_MATH_BUILTIN_RELOPS 90143063Sjoerg#endif 91143063Sjoerg 92143063Sjoerg#define __GNUCLIKE_BUILTIN_MEMCPY 1 93143063Sjoerg 94143063Sjoerg/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ 95143063Sjoerg#define __CC_SUPPORTS_INLINE 1 96143063Sjoerg#define __CC_SUPPORTS___INLINE 1 97143063Sjoerg#define __CC_SUPPORTS___INLINE__ 1 98143063Sjoerg 99143063Sjoerg#define __CC_SUPPORTS___FUNC__ 1 100143063Sjoerg#define __CC_SUPPORTS_WARNING 1 101143063Sjoerg 102143063Sjoerg#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ 103143063Sjoerg 104143063Sjoerg#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 105143063Sjoerg 106143063Sjoerg#endif /* __GNUC__ || __INTEL_COMPILER */ 107143063Sjoerg 108143063Sjoerg/* 109120608Smux * Macro to test if we're using a specific version of gcc or later. 110120608Smux */ 111126891Strhodes#if defined(__GNUC__) && !defined(__INTEL_COMPILER) 112120608Smux#define __GNUC_PREREQ__(ma, mi) \ 113120629Smux (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) 114120608Smux#else 115120608Smux#define __GNUC_PREREQ__(ma, mi) 0 116120608Smux#endif 117120608Smux 118120608Smux/* 1191541Srgrimes * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 1201541Srgrimes * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 12136971Sbde * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI 12236971Sbde * mode -- there must be no spaces between its arguments, and for nested 12336971Sbde * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also 12436971Sbde * concatenate double-quoted strings produced by the __STRING macro, but 12536971Sbde * this only works with ANSI C. 12625083Sjdp * 12725083Sjdp * __XSTRING is like __STRING, but it expands any macros in its argument 12825083Sjdp * first. It is only available with ANSI C. 1291541Srgrimes */ 1301541Srgrimes#if defined(__STDC__) || defined(__cplusplus) 1311541Srgrimes#define __P(protos) protos /* full-blown ANSI C */ 1325012Sbde#define __CONCAT1(x,y) x ## y 1335012Sbde#define __CONCAT(x,y) __CONCAT1(x,y) 13425083Sjdp#define __STRING(x) #x /* stringify without expanding x */ 13525083Sjdp#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ 1361541Srgrimes 1371541Srgrimes#define __const const /* define reserved names to standard */ 1381541Srgrimes#define __signed signed 1391541Srgrimes#define __volatile volatile 1401541Srgrimes#if defined(__cplusplus) 1411541Srgrimes#define __inline inline /* convert to C++ keyword */ 1421541Srgrimes#else 143143063Sjoerg#if !(defined(__CC_SUPPORTS___INLINE)) 1441541Srgrimes#define __inline /* delete GCC keyword */ 145143063Sjoerg#endif /* ! __CC_SUPPORTS___INLINE */ 1461541Srgrimes#endif /* !__cplusplus */ 1471541Srgrimes 1481541Srgrimes#else /* !(__STDC__ || __cplusplus) */ 1491541Srgrimes#define __P(protos) () /* traditional C preprocessor */ 1501541Srgrimes#define __CONCAT(x,y) x/**/y 1511541Srgrimes#define __STRING(x) "x" 1521541Srgrimes 153143063Sjoerg#if !defined(__CC_SUPPORTS___INLINE) 1541541Srgrimes#define __const /* delete pseudo-ANSI C keywords */ 1551541Srgrimes#define __inline 1561541Srgrimes#define __signed 1571541Srgrimes#define __volatile 1581541Srgrimes/* 1591541Srgrimes * In non-ANSI C environments, new programs will want ANSI-only C keywords 1601541Srgrimes * deleted from the program and old programs will want them left alone. 1611541Srgrimes * When using a compiler other than gcc, programs using the ANSI C keywords 1621541Srgrimes * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. 1631541Srgrimes * When using "gcc -traditional", we assume that this is the intent; if 1641541Srgrimes * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. 1651541Srgrimes */ 1661541Srgrimes#ifndef NO_ANSI_KEYWORDS 1671541Srgrimes#define const /* delete ANSI C keywords */ 1681541Srgrimes#define inline 1691541Srgrimes#define signed 1701541Srgrimes#define volatile 1715209Snate#endif /* !NO_ANSI_KEYWORDS */ 172143063Sjoerg#endif /* !__CC_SUPPORTS___INLINE */ 1731541Srgrimes#endif /* !(__STDC__ || __cplusplus) */ 1741541Srgrimes 1751541Srgrimes/* 17638509Sbde * Compiler-dependent macros to help declare dead (non-returning) and 17738509Sbde * pure (no side effects) functions, and unused variables. They are 17838509Sbde * null except for versions of gcc that are known to support the features 17938509Sbde * properly (old versions of gcc-2 supported the dead and pure features 180103845Speter * in a different (wrong) way). If we do not provide an implementation 181103845Speter * for a given compiler, let the compile fail if it is told to use 182103845Speter * a feature that we cannot live without. 1831541Srgrimes */ 184103845Speter#ifdef lint 18583443Sasmodai#define __dead2 18683443Sasmodai#define __pure2 18783443Sasmodai#define __unused 188103834Speter#define __packed 189103836Speter#define __aligned(x) 190103841Speter#define __section(x) 191103845Speter#else 192126891Strhodes#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) 193103845Speter#define __dead2 194103845Speter#define __pure2 195103845Speter#define __unused 1962059Sdg#endif 197126891Strhodes#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) 19883443Sasmodai#define __dead2 __attribute__((__noreturn__)) 19983443Sasmodai#define __pure2 __attribute__((__const__)) 20083443Sasmodai#define __unused 201103845Speter/* XXX Find out what to do for __packed, __aligned and __section */ 2021541Srgrimes#endif 203120608Smux#if __GNUC_PREREQ__(2, 7) 20483443Sasmodai#define __dead2 __attribute__((__noreturn__)) 20583443Sasmodai#define __pure2 __attribute__((__const__)) 20683443Sasmodai#define __unused __attribute__((__unused__)) 207132782Skan#define __used __attribute__((__used__)) 208103834Speter#define __packed __attribute__((__packed__)) 209103834Speter#define __aligned(x) __attribute__((__aligned__(x))) 210103836Speter#define __section(x) __attribute__((__section__(x))) 21117648Speter#endif 212126891Strhodes#if defined(__INTEL_COMPILER) 213126891Strhodes#define __dead2 __attribute__((__noreturn__)) 214126891Strhodes#define __pure2 __attribute__((__const__)) 215126891Strhodes#define __unused __attribute__((__unused__)) 216132782Skan#define __used __attribute__((__used__)) 217126891Strhodes#define __packed __attribute__((__packed__)) 218126891Strhodes#define __aligned(x) __attribute__((__aligned__(x))) 219126891Strhodes#define __section(x) __attribute__((__section__(x))) 220103845Speter#endif 221126891Strhodes#endif 2221541Srgrimes 223132538Stjr#if __GNUC_PREREQ__(2, 96) 224187961Sdas#define __malloc_like __attribute__((__malloc__)) 225132538Stjr#define __pure __attribute__((__pure__)) 226132538Stjr#else 227187961Sdas#define __malloc_like 228132538Stjr#define __pure 229132538Stjr#endif 230132538Stjr 231126891Strhodes#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) 232117906Speter#define __always_inline __attribute__((__always_inline__)) 233117906Speter#else 234117906Speter#define __always_inline 235117906Speter#endif 236117906Speter 237174496Salc#if __GNUC_PREREQ__(4, 2) /* actually 4.1.3 */ 238174496Salc#define __gnu89_inline __attribute__((__gnu_inline__)) __inline 239174496Salc#else 240174496Salc#define __gnu89_inline 241174496Salc#endif 242174496Salc 243177618Ssam#if __GNUC_PREREQ__(3, 1) 244177618Ssam#define __noinline __attribute__ ((__noinline__)) 245177618Ssam#else 246177618Ssam#define __noinline 247177618Ssam#endif 248177618Ssam 249120608Smux#if __GNUC_PREREQ__(3, 3) 250117837Sphk#define __nonnull(x) __attribute__((__nonnull__(x))) 251117837Sphk#else 252117837Sphk#define __nonnull(x) 253117837Sphk#endif 254117837Sphk 25585672Smike/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ 256126891Strhodes#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) 25785672Smike#define __func__ NULL 25885672Smike#endif 25985672Smike 260126891Strhodes#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 26186302Smike#define __LONG_LONG_SUPPORTED 26286302Smike#endif 26386302Smike 26438509Sbde/* 265104591Smike * GCC 2.95 provides `__restrict' as an extension to C90 to support the 266103370Swollman * C99-specific `restrict' type qualifier. We happen to use `__restrict' as 267103370Swollman * a way to define the `restrict' type qualifier without disturbing older 268103370Swollman * software that is unaware of C99 keywords. 26986803Smike */ 27086803Smike#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) 271121783Speter#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 27286803Smike#define __restrict 27386803Smike#else 27486803Smike#define __restrict restrict 27586803Smike#endif 27686803Smike#endif 27786803Smike 27886803Smike/* 279120609Smux * GNU C version 2.96 adds explicit branch prediction so that 280120609Smux * the CPU back-end can hint the processor and also so that 281120609Smux * code blocks can be reordered such that the predicted path 282120609Smux * sees a more linear flow, thus improving cache behavior, etc. 283120609Smux * 284120609Smux * The following two macros provide us with a way to utilize this 285120609Smux * compiler feature. Use __predict_true() if you expect the expression 286120609Smux * to evaluate to true, and __predict_false() if you expect the 287120609Smux * expression to evaluate to false. 288120609Smux * 289120609Smux * A few notes about usage: 290120609Smux * 291120609Smux * * Generally, __predict_false() error condition checks (unless 292120609Smux * you have some _strong_ reason to do otherwise, in which case 293120609Smux * document it), and/or __predict_true() `no-error' condition 294120609Smux * checks, assuming you want to optimize for the no-error case. 295120609Smux * 296120609Smux * * Other than that, if you don't know the likelihood of a test 297120609Smux * succeeding from empirical or other `hard' evidence, don't 298120609Smux * make predictions. 299120609Smux * 300120609Smux * * These are meant to be used in places that are run `a lot'. 301120609Smux * It is wasteful to make predictions in code that is run 302120609Smux * seldomly (e.g. at subsystem initialization time) as the 303120609Smux * basic block reordering that this affects can often generate 304120609Smux * larger code. 305120609Smux */ 306120609Smux#if __GNUC_PREREQ__(2, 96) 307120609Smux#define __predict_true(exp) __builtin_expect((exp), 1) 308120609Smux#define __predict_false(exp) __builtin_expect((exp), 0) 309120609Smux#else 310120609Smux#define __predict_true(exp) (exp) 311120609Smux#define __predict_false(exp) (exp) 312120609Smux#endif 313120609Smux 314120609Smux/* 31599594Smike * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h> 31699594Smike * require it. 31799594Smike */ 318162488Skan#if __GNUC_PREREQ__(4, 1) 319162488Skan#define __offsetof(type, field) __builtin_offsetof(type, field) 320162488Skan#else 321146941Skan#ifndef __cplusplus 32299594Smike#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) 323146941Skan#else 324146941Skan#define __offsetof(type, field) \ 325146941Skan (__offsetof__ (reinterpret_cast <size_t> \ 326146941Skan (&reinterpret_cast <const volatile char &> \ 327146941Skan (static_cast<type *> (0)->field)))) 328146941Skan#endif 329162488Skan#endif 330133604Sjulian#define __rangeof(type, start, end) \ 331133604Sjulian (__offsetof(type, end) - __offsetof(type, start)) 33299594Smike 33399594Smike/* 33438509Sbde * Compiler-dependent macros to declare that functions take printf-like 33538509Sbde * or scanf-like arguments. They are null except for versions of gcc 33638509Sbde * that are known to support the features properly (old versions of gcc-2 33738509Sbde * didn't permit keeping the keywords out of the application namespace). 33838509Sbde */ 339126891Strhodes#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) 34037614Sbde#define __printflike(fmtarg, firstvararg) 34137614Sbde#define __scanflike(fmtarg, firstvararg) 342154867Sstefanf#define __format_arg(fmtarg) 34337614Sbde#else 34437614Sbde#define __printflike(fmtarg, firstvararg) \ 34537614Sbde __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 34637614Sbde#define __scanflike(fmtarg, firstvararg) \ 34737614Sbde __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) 348154867Sstefanf#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) 34937614Sbde#endif 35037614Sbde 35140716Sjdp/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ 352126891Strhodes#if __FreeBSD_cc_version >= 300001 && defined(__GNUC__) && !defined(__INTEL_COMPILER) 35340716Sjdp#define __printf0like(fmtarg, firstvararg) \ 35440716Sjdp __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) 35540716Sjdp#else 35640716Sjdp#define __printf0like(fmtarg, firstvararg) 35740716Sjdp#endif 35840716Sjdp 359126891Strhodes#if defined(__GNUC__) || defined(__INTEL_COMPILER) 360126891Strhodes#ifndef __INTEL_COMPILER 36183443Sasmodai#define __strong_reference(sym,aliassym) \ 362148005Skbyanc extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) 363126891Strhodes#endif 3645209Snate#ifdef __STDC__ 36537052Speter#define __weak_reference(sym,alias) \ 36637052Speter __asm__(".weak " #alias); \ 36737862Sdfr __asm__(".equ " #alias ", " #sym) 36837052Speter#define __warn_references(sym,msg) \ 36937052Speter __asm__(".section .gnu.warning." #sym); \ 37039502Sjdp __asm__(".asciz \"" msg "\""); \ 37137052Speter __asm__(".previous") 372156607Sdeischen#define __sym_compat(sym,impl,verid) \ 373156607Sdeischen __asm__(".symver " #impl ", " #sym "@" #verid) 374156607Sdeischen#define __sym_default(sym,impl,verid) \ 375156607Sdeischen __asm__(".symver " #impl ", " #sym "@@" #verid) 37637052Speter#else 37737052Speter#define __weak_reference(sym,alias) \ 37837052Speter __asm__(".weak alias"); \ 37937862Sdfr __asm__(".equ alias, sym") 38037052Speter#define __warn_references(sym,msg) \ 38137052Speter __asm__(".section .gnu.warning.sym"); \ 38239502Sjdp __asm__(".asciz \"msg\""); \ 38337052Speter __asm__(".previous") 384156607Sdeischen#define __sym_compat(sym,impl,verid) \ 385156607Sdeischen __asm__(".symver impl, sym@verid") 386156607Sdeischen#define __sym_default(impl,sym,verid) \ 387156607Sdeischen __asm__(".symver impl, sym@@verid") 38837052Speter#endif /* __STDC__ */ 389126891Strhodes#endif /* __GNUC__ || __INTEL_COMPILER */ 3905209Snate 391126891Strhodes#if defined(__GNUC__) || defined(__INTEL_COMPILER) 39250614Speter#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") 39350614Speter#else 39483049Speter/* 395118023Sgad * The following definition might not work well if used in header files, 396118023Sgad * but it should be better than nothing. If you want a "do nothing" 397118023Sgad * version, then it should generate some harmless declaration, such as: 398118023Sgad * #define __IDSTRING(name,string) struct __hack 39983049Speter */ 40036971Sbde#define __IDSTRING(name,string) static const char name[] __unused = string 40150614Speter#endif 40231707Spst 40383552Sdillon/* 40483552Sdillon * Embed the rcs id of a source file in the resulting library. Note that in 40583552Sdillon * more recent ELF binutils, we use .ident allowing the ID to be stripped. 40683552Sdillon * Usage: 40783552Sdillon * __FBSDID("$FreeBSD: head/sys/sys/cdefs.h 189209 2009-03-01 06:27:03Z das $"); 40883552Sdillon */ 40983489Sdillon#ifndef __FBSDID 41083528Sobrien#if !defined(lint) && !defined(STRIP_FBSDID) 41183526Sobrien#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 41283489Sdillon#else 41383552Sdillon#define __FBSDID(s) struct __hack 41483489Sdillon#endif 41583489Sdillon#endif 41683489Sdillon 41793996Sobrien#ifndef __RCSID 41893996Sobrien#ifndef NO__RCSID 41993993Sobrien#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 42093996Sobrien#else 421118023Sgad#define __RCSID(s) struct __hack 42293993Sobrien#endif 42393996Sobrien#endif 42493993Sobrien 42593996Sobrien#ifndef __RCSID_SOURCE 42693996Sobrien#ifndef NO__RCSID_SOURCE 42783049Speter#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) 42893996Sobrien#else 429118023Sgad#define __RCSID_SOURCE(s) struct __hack 43031707Spst#endif 43193996Sobrien#endif 43231707Spst 43393996Sobrien#ifndef __SCCSID 43493996Sobrien#ifndef NO__SCCSID 43593996Sobrien#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) 43693996Sobrien#else 437118023Sgad#define __SCCSID(s) struct __hack 43893996Sobrien#endif 43993996Sobrien#endif 44093996Sobrien 44193996Sobrien#ifndef __COPYRIGHT 44293996Sobrien#ifndef NO__COPYRIGHT 44383049Speter#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) 44493996Sobrien#else 445118023Sgad#define __COPYRIGHT(s) struct __hack 44631707Spst#endif 44793996Sobrien#endif 44831707Spst 44974070Sbillf#ifndef __DECONST 45074070Sbillf#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 45174070Sbillf#endif 45274070Sbillf 45374070Sbillf#ifndef __DEVOLATILE 45474070Sbillf#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) 45574070Sbillf#endif 45674070Sbillf 45774070Sbillf#ifndef __DEQUALIFY 45874070Sbillf#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) 45974070Sbillf#endif 46074070Sbillf 46193510Smike/*- 46293510Smike * The following definitions are an extension of the behavior originally 46399904Smikeh * implemented in <sys/_posix.h>, but with a different level of granularity. 46493510Smike * POSIX.1 requires that the macros we test be defined before any standard 46593510Smike * header file is included. 46693510Smike * 46793510Smike * Here's a quick run-down of the versions: 46893510Smike * defined(_POSIX_SOURCE) 1003.1-1988 46993510Smike * _POSIX_C_SOURCE == 1 1003.1-1990 470100109Swollman * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 47193510Smike * _POSIX_C_SOURCE == 199309 1003.1b-1993 47293510Smike * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 47393510Smike * and the omnibus ISO/IEC 9945-1: 1996 47493510Smike * _POSIX_C_SOURCE == 200112 1003.1-2001 475189134Sdas * _POSIX_C_SOURCE == 200809 1003.1-2008 47693510Smike * 47793510Smike * In addition, the X/Open Portability Guide, which is now the Single UNIX 47893510Smike * Specification, defines a feature-test macro which indicates the version of 47993510Smike * that specification, and which subsumes _POSIX_C_SOURCE. 48093510Smike * 48193510Smike * Our macros begin with two underscores to avoid namespace screwage. 48293510Smike */ 48393510Smike 48493510Smike/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 485121783Speter#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 48693510Smike#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 48793510Smike#define _POSIX_C_SOURCE 199009 48893510Smike#endif 48993510Smike 490100109Swollman/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 491121783Speter#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 492100109Swollman#undef _POSIX_C_SOURCE 493100109Swollman#define _POSIX_C_SOURCE 199209 494100109Swollman#endif 495100109Swollman 49693510Smike/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 49793510Smike#ifdef _XOPEN_SOURCE 498189134Sdas#if _XOPEN_SOURCE - 0 >= 700 499189134Sdas#define __XSI_VISIBLE 700 500189134Sdas#undef _POSIX_C_SOURCE 501189134Sdas#define _POSIX_C_SOURCE 200809 502189134Sdas#elif _XOPEN_SOURCE - 0 >= 600 50393510Smike#define __XSI_VISIBLE 600 50493510Smike#undef _POSIX_C_SOURCE 50593510Smike#define _POSIX_C_SOURCE 200112 50693715Speter#elif _XOPEN_SOURCE - 0 >= 500 50793510Smike#define __XSI_VISIBLE 500 50893510Smike#undef _POSIX_C_SOURCE 50993510Smike#define _POSIX_C_SOURCE 199506 51093510Smike#endif 51193510Smike#endif 51293510Smike 51393510Smike/* 51493510Smike * Deal with all versions of POSIX. The ordering relative to the tests above is 51593510Smike * important. 51693510Smike */ 51793510Smike#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 51893510Smike#define _POSIX_C_SOURCE 198808 51993510Smike#endif 52093510Smike#ifdef _POSIX_C_SOURCE 521189134Sdas#if _POSIX_C_SOURCE >= 200809 522189134Sdas#define __POSIX_VISIBLE 200809 523189134Sdas#define __ISO_C_VISIBLE 1999 524189209Sdas#elif _POSIX_C_SOURCE >= 200112 52593510Smike#define __POSIX_VISIBLE 200112 52693510Smike#define __ISO_C_VISIBLE 1999 52793510Smike#elif _POSIX_C_SOURCE >= 199506 52893510Smike#define __POSIX_VISIBLE 199506 52993510Smike#define __ISO_C_VISIBLE 1990 53093510Smike#elif _POSIX_C_SOURCE >= 199309 53193510Smike#define __POSIX_VISIBLE 199309 53293510Smike#define __ISO_C_VISIBLE 1990 533100109Swollman#elif _POSIX_C_SOURCE >= 199209 534100109Swollman#define __POSIX_VISIBLE 199209 535100109Swollman#define __ISO_C_VISIBLE 1990 53693510Smike#elif _POSIX_C_SOURCE >= 199009 53793510Smike#define __POSIX_VISIBLE 199009 53893510Smike#define __ISO_C_VISIBLE 1990 53993510Smike#else 54093510Smike#define __POSIX_VISIBLE 198808 54193510Smike#define __ISO_C_VISIBLE 0 54293510Smike#endif /* _POSIX_C_SOURCE */ 54393510Smike#else 54493510Smike/*- 54593510Smike * Deal with _ANSI_SOURCE: 54693510Smike * If it is defined, and no other compilation environment is explicitly 54793510Smike * requested, then define our internal feature-test macros to zero. This 54893510Smike * makes no difference to the preprocessor (undefined symbols in preprocessing 54993510Smike * expressions are defined to have value zero), but makes it more convenient for 55093510Smike * a test program to print out the values. 55193510Smike * 55293510Smike * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 55393510Smike * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 55493510Smike * environment (and in fact we will never get here). 55593510Smike */ 556105654Smike#if defined(_ANSI_SOURCE) /* Hide almost everything. */ 55793510Smike#define __POSIX_VISIBLE 0 55893510Smike#define __XSI_VISIBLE 0 55993510Smike#define __BSD_VISIBLE 0 56093510Smike#define __ISO_C_VISIBLE 1990 561105654Smike#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 562105654Smike#define __POSIX_VISIBLE 0 563105654Smike#define __XSI_VISIBLE 0 564105654Smike#define __BSD_VISIBLE 0 565105654Smike#define __ISO_C_VISIBLE 1999 56693510Smike#else /* Default environment: show everything. */ 567189134Sdas#define __POSIX_VISIBLE 200809 568189134Sdas#define __XSI_VISIBLE 700 56993510Smike#define __BSD_VISIBLE 1 57093510Smike#define __ISO_C_VISIBLE 1999 57193510Smike#endif 57293510Smike#endif 57393510Smike 5742212Sbde#endif /* !_SYS_CDEFS_H_ */ 575