cdefs.h revision 148005
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 148005 2005-07-14 19:30:49Z kbyanc $ 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 77143063Sjoerg#if __GNUC_MINOR__ > 95 || __GNUC__ >= 3 || defined(__INTEL_COMPILER) 78143063Sjoerg# define __GNUCLIKE_BUILTIN_VARARGS 1 79143063Sjoerg#endif 80143063Sjoerg#define __GNUCLIKE_BUILTIN_VAALIST 1 81143063Sjoerg 82143063Sjoerg#if defined(__GNUC__) 83143063Sjoerg# define __GNUC_VA_LIST_COMPATIBILITY 1 84143063Sjoerg#endif 85143063Sjoerg 86143063Sjoerg#if (__GNUC_MINOR__ > 95 || __GNUC__ >= 3) && !defined(__INTEL_COMPILER) 87143063Sjoerg# define __GNUCLIKE_BUILTIN_STDARG 1 88143063Sjoerg#endif 89143063Sjoerg 90143063Sjoerg#ifndef __INTEL_COMPILER 91143063Sjoerg# define __GNUCLIKE_BUILTIN_NEXT_ARG 1 92143063Sjoerg# define __GNUCLIKE_MATH_BUILTIN_RELOPS 93143063Sjoerg#endif 94143063Sjoerg 95143063Sjoerg#define __GNUCLIKE_BUILTIN_MEMCPY 1 96143063Sjoerg 97143063Sjoerg/* XXX: if __GNUC__ >= 2: not tested everywhere originally, where replaced */ 98143063Sjoerg#define __CC_SUPPORTS_INLINE 1 99143063Sjoerg#define __CC_SUPPORTS___INLINE 1 100143063Sjoerg#define __CC_SUPPORTS___INLINE__ 1 101143063Sjoerg 102143063Sjoerg#define __CC_SUPPORTS___FUNC__ 1 103143063Sjoerg#define __CC_SUPPORTS_WARNING 1 104143063Sjoerg 105143063Sjoerg#define __CC_SUPPORTS_VARADIC_XXX 1 /* see varargs.h */ 106143063Sjoerg 107143063Sjoerg#define __CC_SUPPORTS_DYNAMIC_ARRAY_INIT 1 108143063Sjoerg 109143063Sjoerg/* XXX: sys/dev/mpt/mpilib/mpi_type.h uses it, someone should review it */ 110143063Sjoerg#define __CC_INT_IS_32BIT 1 111143063Sjoerg 112143063Sjoerg#endif /* __GNUC__ || __INTEL_COMPILER */ 113143063Sjoerg 114143063Sjoerg/* 115120608Smux * Macro to test if we're using a specific version of gcc or later. 116120608Smux */ 117126891Strhodes#if defined(__GNUC__) && !defined(__INTEL_COMPILER) 118120608Smux#define __GNUC_PREREQ__(ma, mi) \ 119120629Smux (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) 120120608Smux#else 121120608Smux#define __GNUC_PREREQ__(ma, mi) 0 122120608Smux#endif 123120608Smux 124120608Smux/* 1251541Srgrimes * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 1261541Srgrimes * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 12736971Sbde * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI 12836971Sbde * mode -- there must be no spaces between its arguments, and for nested 12936971Sbde * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also 13036971Sbde * concatenate double-quoted strings produced by the __STRING macro, but 13136971Sbde * this only works with ANSI C. 13225083Sjdp * 13325083Sjdp * __XSTRING is like __STRING, but it expands any macros in its argument 13425083Sjdp * first. It is only available with ANSI C. 1351541Srgrimes */ 1361541Srgrimes#if defined(__STDC__) || defined(__cplusplus) 1371541Srgrimes#define __P(protos) protos /* full-blown ANSI C */ 1385012Sbde#define __CONCAT1(x,y) x ## y 1395012Sbde#define __CONCAT(x,y) __CONCAT1(x,y) 14025083Sjdp#define __STRING(x) #x /* stringify without expanding x */ 14125083Sjdp#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ 1421541Srgrimes 1431541Srgrimes#define __const const /* define reserved names to standard */ 1441541Srgrimes#define __signed signed 1451541Srgrimes#define __volatile volatile 1461541Srgrimes#if defined(__cplusplus) 1471541Srgrimes#define __inline inline /* convert to C++ keyword */ 1481541Srgrimes#else 149143063Sjoerg#if !(defined(__CC_SUPPORTS___INLINE)) 1501541Srgrimes#define __inline /* delete GCC keyword */ 151143063Sjoerg#endif /* ! __CC_SUPPORTS___INLINE */ 1521541Srgrimes#endif /* !__cplusplus */ 1531541Srgrimes 1541541Srgrimes#else /* !(__STDC__ || __cplusplus) */ 1551541Srgrimes#define __P(protos) () /* traditional C preprocessor */ 1561541Srgrimes#define __CONCAT(x,y) x/**/y 1571541Srgrimes#define __STRING(x) "x" 1581541Srgrimes 159143063Sjoerg#if !defined(__CC_SUPPORTS___INLINE) 1601541Srgrimes#define __const /* delete pseudo-ANSI C keywords */ 1611541Srgrimes#define __inline 1621541Srgrimes#define __signed 1631541Srgrimes#define __volatile 1641541Srgrimes/* 1651541Srgrimes * In non-ANSI C environments, new programs will want ANSI-only C keywords 1661541Srgrimes * deleted from the program and old programs will want them left alone. 1671541Srgrimes * When using a compiler other than gcc, programs using the ANSI C keywords 1681541Srgrimes * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. 1691541Srgrimes * When using "gcc -traditional", we assume that this is the intent; if 1701541Srgrimes * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. 1711541Srgrimes */ 1721541Srgrimes#ifndef NO_ANSI_KEYWORDS 1731541Srgrimes#define const /* delete ANSI C keywords */ 1741541Srgrimes#define inline 1751541Srgrimes#define signed 1761541Srgrimes#define volatile 1775209Snate#endif /* !NO_ANSI_KEYWORDS */ 178143063Sjoerg#endif /* !__CC_SUPPORTS___INLINE */ 1791541Srgrimes#endif /* !(__STDC__ || __cplusplus) */ 1801541Srgrimes 1811541Srgrimes/* 18238509Sbde * Compiler-dependent macros to help declare dead (non-returning) and 18338509Sbde * pure (no side effects) functions, and unused variables. They are 18438509Sbde * null except for versions of gcc that are known to support the features 18538509Sbde * properly (old versions of gcc-2 supported the dead and pure features 186103845Speter * in a different (wrong) way). If we do not provide an implementation 187103845Speter * for a given compiler, let the compile fail if it is told to use 188103845Speter * a feature that we cannot live without. 1891541Srgrimes */ 190103845Speter#ifdef lint 19183443Sasmodai#define __dead2 19283443Sasmodai#define __pure2 19383443Sasmodai#define __unused 194103834Speter#define __packed 195103836Speter#define __aligned(x) 196103841Speter#define __section(x) 197103845Speter#else 198126891Strhodes#if !__GNUC_PREREQ__(2, 5) && !defined(__INTEL_COMPILER) 199103845Speter#define __dead2 200103845Speter#define __pure2 201103845Speter#define __unused 2022059Sdg#endif 203126891Strhodes#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 && !defined(__INTEL_COMPILER) 20483443Sasmodai#define __dead2 __attribute__((__noreturn__)) 20583443Sasmodai#define __pure2 __attribute__((__const__)) 20683443Sasmodai#define __unused 207103845Speter/* XXX Find out what to do for __packed, __aligned and __section */ 2081541Srgrimes#endif 209120608Smux#if __GNUC_PREREQ__(2, 7) 21083443Sasmodai#define __dead2 __attribute__((__noreturn__)) 21183443Sasmodai#define __pure2 __attribute__((__const__)) 21283443Sasmodai#define __unused __attribute__((__unused__)) 213132782Skan#define __used __attribute__((__used__)) 214103834Speter#define __packed __attribute__((__packed__)) 215103834Speter#define __aligned(x) __attribute__((__aligned__(x))) 216103836Speter#define __section(x) __attribute__((__section__(x))) 21717648Speter#endif 218126891Strhodes#if defined(__INTEL_COMPILER) 219126891Strhodes#define __dead2 __attribute__((__noreturn__)) 220126891Strhodes#define __pure2 __attribute__((__const__)) 221126891Strhodes#define __unused __attribute__((__unused__)) 222132782Skan#define __used __attribute__((__used__)) 223126891Strhodes#define __packed __attribute__((__packed__)) 224126891Strhodes#define __aligned(x) __attribute__((__aligned__(x))) 225126891Strhodes#define __section(x) __attribute__((__section__(x))) 226103845Speter#endif 227126891Strhodes#endif 2281541Srgrimes 229132538Stjr#if __GNUC_PREREQ__(2, 96) 230132538Stjr#define __pure __attribute__((__pure__)) 231132538Stjr#else 232132538Stjr#define __pure 233132538Stjr#endif 234132538Stjr 235126891Strhodes#if __GNUC_PREREQ__(3, 1) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 800) 236117906Speter#define __always_inline __attribute__((__always_inline__)) 237117906Speter#else 238117906Speter#define __always_inline 239117906Speter#endif 240117906Speter 241120608Smux#if __GNUC_PREREQ__(3, 3) 242117837Sphk#define __nonnull(x) __attribute__((__nonnull__(x))) 243117837Sphk#else 244117837Sphk#define __nonnull(x) 245117837Sphk#endif 246117837Sphk 24785672Smike/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ 248126891Strhodes#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) 24985672Smike#define __func__ NULL 25085672Smike#endif 25185672Smike 252126891Strhodes#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 25386302Smike#define __LONG_LONG_SUPPORTED 25486302Smike#endif 25586302Smike 25638509Sbde/* 257104591Smike * GCC 2.95 provides `__restrict' as an extension to C90 to support the 258103370Swollman * C99-specific `restrict' type qualifier. We happen to use `__restrict' as 259103370Swollman * a way to define the `restrict' type qualifier without disturbing older 260103370Swollman * software that is unaware of C99 keywords. 26186803Smike */ 26286803Smike#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) 263121783Speter#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901 26486803Smike#define __restrict 26586803Smike#else 26686803Smike#define __restrict restrict 26786803Smike#endif 26886803Smike#endif 26986803Smike 27086803Smike/* 271120609Smux * GNU C version 2.96 adds explicit branch prediction so that 272120609Smux * the CPU back-end can hint the processor and also so that 273120609Smux * code blocks can be reordered such that the predicted path 274120609Smux * sees a more linear flow, thus improving cache behavior, etc. 275120609Smux * 276120609Smux * The following two macros provide us with a way to utilize this 277120609Smux * compiler feature. Use __predict_true() if you expect the expression 278120609Smux * to evaluate to true, and __predict_false() if you expect the 279120609Smux * expression to evaluate to false. 280120609Smux * 281120609Smux * A few notes about usage: 282120609Smux * 283120609Smux * * Generally, __predict_false() error condition checks (unless 284120609Smux * you have some _strong_ reason to do otherwise, in which case 285120609Smux * document it), and/or __predict_true() `no-error' condition 286120609Smux * checks, assuming you want to optimize for the no-error case. 287120609Smux * 288120609Smux * * Other than that, if you don't know the likelihood of a test 289120609Smux * succeeding from empirical or other `hard' evidence, don't 290120609Smux * make predictions. 291120609Smux * 292120609Smux * * These are meant to be used in places that are run `a lot'. 293120609Smux * It is wasteful to make predictions in code that is run 294120609Smux * seldomly (e.g. at subsystem initialization time) as the 295120609Smux * basic block reordering that this affects can often generate 296120609Smux * larger code. 297120609Smux */ 298120609Smux#if __GNUC_PREREQ__(2, 96) 299120609Smux#define __predict_true(exp) __builtin_expect((exp), 1) 300120609Smux#define __predict_false(exp) __builtin_expect((exp), 0) 301120609Smux#else 302120609Smux#define __predict_true(exp) (exp) 303120609Smux#define __predict_false(exp) (exp) 304120609Smux#endif 305120609Smux 306120609Smux/* 30799594Smike * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h> 30899594Smike * require it. 30999594Smike */ 310146941Skan#ifndef __cplusplus 31199594Smike#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) 312146941Skan#else 313146941Skan#define __offsetof(type, field) \ 314146941Skan (__offsetof__ (reinterpret_cast <size_t> \ 315146941Skan (&reinterpret_cast <const volatile char &> \ 316146941Skan (static_cast<type *> (0)->field)))) 317146941Skan#endif 318133604Sjulian#define __rangeof(type, start, end) \ 319133604Sjulian (__offsetof(type, end) - __offsetof(type, start)) 32099594Smike 32199594Smike/* 32238509Sbde * Compiler-dependent macros to declare that functions take printf-like 32338509Sbde * or scanf-like arguments. They are null except for versions of gcc 32438509Sbde * that are known to support the features properly (old versions of gcc-2 32538509Sbde * didn't permit keeping the keywords out of the application namespace). 32638509Sbde */ 327126891Strhodes#if !__GNUC_PREREQ__(2, 7) && !defined(__INTEL_COMPILER) 32837614Sbde#define __printflike(fmtarg, firstvararg) 32937614Sbde#define __scanflike(fmtarg, firstvararg) 33037614Sbde#else 33137614Sbde#define __printflike(fmtarg, firstvararg) \ 33237614Sbde __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 33337614Sbde#define __scanflike(fmtarg, firstvararg) \ 33437614Sbde __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) 33537614Sbde#endif 33637614Sbde 33740716Sjdp/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ 338126891Strhodes#if __FreeBSD_cc_version >= 300001 && defined(__GNUC__) && !defined(__INTEL_COMPILER) 33940716Sjdp#define __printf0like(fmtarg, firstvararg) \ 34040716Sjdp __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) 34140716Sjdp#else 34240716Sjdp#define __printf0like(fmtarg, firstvararg) 34340716Sjdp#endif 34440716Sjdp 345126891Strhodes#if defined(__GNUC__) || defined(__INTEL_COMPILER) 346126891Strhodes#ifndef __INTEL_COMPILER 34783443Sasmodai#define __strong_reference(sym,aliassym) \ 348148005Skbyanc extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))) 349126891Strhodes#endif 3505209Snate#ifdef __STDC__ 35137052Speter#define __weak_reference(sym,alias) \ 35237052Speter __asm__(".weak " #alias); \ 35337862Sdfr __asm__(".equ " #alias ", " #sym) 35437052Speter#define __warn_references(sym,msg) \ 35537052Speter __asm__(".section .gnu.warning." #sym); \ 35639502Sjdp __asm__(".asciz \"" msg "\""); \ 35737052Speter __asm__(".previous") 35837052Speter#else 35937052Speter#define __weak_reference(sym,alias) \ 36037052Speter __asm__(".weak alias"); \ 36137862Sdfr __asm__(".equ alias, sym") 36237052Speter#define __warn_references(sym,msg) \ 36337052Speter __asm__(".section .gnu.warning.sym"); \ 36439502Sjdp __asm__(".asciz \"msg\""); \ 36537052Speter __asm__(".previous") 36637052Speter#endif /* __STDC__ */ 367126891Strhodes#endif /* __GNUC__ || __INTEL_COMPILER */ 3685209Snate 369126891Strhodes#if defined(__GNUC__) || defined(__INTEL_COMPILER) 37050614Speter#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") 37150614Speter#else 37283049Speter/* 373118023Sgad * The following definition might not work well if used in header files, 374118023Sgad * but it should be better than nothing. If you want a "do nothing" 375118023Sgad * version, then it should generate some harmless declaration, such as: 376118023Sgad * #define __IDSTRING(name,string) struct __hack 37783049Speter */ 37836971Sbde#define __IDSTRING(name,string) static const char name[] __unused = string 37950614Speter#endif 38031707Spst 38183552Sdillon/* 38283552Sdillon * Embed the rcs id of a source file in the resulting library. Note that in 38383552Sdillon * more recent ELF binutils, we use .ident allowing the ID to be stripped. 38483552Sdillon * Usage: 38583552Sdillon * __FBSDID("$FreeBSD: head/sys/sys/cdefs.h 148005 2005-07-14 19:30:49Z kbyanc $"); 38683552Sdillon */ 38783489Sdillon#ifndef __FBSDID 38883528Sobrien#if !defined(lint) && !defined(STRIP_FBSDID) 38983526Sobrien#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 39083489Sdillon#else 39183552Sdillon#define __FBSDID(s) struct __hack 39283489Sdillon#endif 39383489Sdillon#endif 39483489Sdillon 39593996Sobrien#ifndef __RCSID 39693996Sobrien#ifndef NO__RCSID 39793993Sobrien#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 39893996Sobrien#else 399118023Sgad#define __RCSID(s) struct __hack 40093993Sobrien#endif 40193996Sobrien#endif 40293993Sobrien 40393996Sobrien#ifndef __RCSID_SOURCE 40493996Sobrien#ifndef NO__RCSID_SOURCE 40583049Speter#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) 40693996Sobrien#else 407118023Sgad#define __RCSID_SOURCE(s) struct __hack 40831707Spst#endif 40993996Sobrien#endif 41031707Spst 41193996Sobrien#ifndef __SCCSID 41293996Sobrien#ifndef NO__SCCSID 41393996Sobrien#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) 41493996Sobrien#else 415118023Sgad#define __SCCSID(s) struct __hack 41693996Sobrien#endif 41793996Sobrien#endif 41893996Sobrien 41993996Sobrien#ifndef __COPYRIGHT 42093996Sobrien#ifndef NO__COPYRIGHT 42183049Speter#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) 42293996Sobrien#else 423118023Sgad#define __COPYRIGHT(s) struct __hack 42431707Spst#endif 42593996Sobrien#endif 42631707Spst 42774070Sbillf#ifndef __DECONST 42874070Sbillf#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 42974070Sbillf#endif 43074070Sbillf 43174070Sbillf#ifndef __DEVOLATILE 43274070Sbillf#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) 43374070Sbillf#endif 43474070Sbillf 43574070Sbillf#ifndef __DEQUALIFY 43674070Sbillf#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) 43774070Sbillf#endif 43874070Sbillf 43993510Smike/*- 44093510Smike * The following definitions are an extension of the behavior originally 44199904Smikeh * implemented in <sys/_posix.h>, but with a different level of granularity. 44293510Smike * POSIX.1 requires that the macros we test be defined before any standard 44393510Smike * header file is included. 44493510Smike * 44593510Smike * Here's a quick run-down of the versions: 44693510Smike * defined(_POSIX_SOURCE) 1003.1-1988 44793510Smike * _POSIX_C_SOURCE == 1 1003.1-1990 448100109Swollman * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 44993510Smike * _POSIX_C_SOURCE == 199309 1003.1b-1993 45093510Smike * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 45193510Smike * and the omnibus ISO/IEC 9945-1: 1996 45293510Smike * _POSIX_C_SOURCE == 200112 1003.1-2001 45393510Smike * 45493510Smike * In addition, the X/Open Portability Guide, which is now the Single UNIX 45593510Smike * Specification, defines a feature-test macro which indicates the version of 45693510Smike * that specification, and which subsumes _POSIX_C_SOURCE. 45793510Smike * 45893510Smike * Our macros begin with two underscores to avoid namespace screwage. 45993510Smike */ 46093510Smike 46193510Smike/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 462121783Speter#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 46393510Smike#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 46493510Smike#define _POSIX_C_SOURCE 199009 46593510Smike#endif 46693510Smike 467100109Swollman/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 468121783Speter#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 469100109Swollman#undef _POSIX_C_SOURCE 470100109Swollman#define _POSIX_C_SOURCE 199209 471100109Swollman#endif 472100109Swollman 47393510Smike/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 47493510Smike#ifdef _XOPEN_SOURCE 47593715Speter#if _XOPEN_SOURCE - 0 >= 600 47693510Smike#define __XSI_VISIBLE 600 47793510Smike#undef _POSIX_C_SOURCE 47893510Smike#define _POSIX_C_SOURCE 200112 47993715Speter#elif _XOPEN_SOURCE - 0 >= 500 48093510Smike#define __XSI_VISIBLE 500 48193510Smike#undef _POSIX_C_SOURCE 48293510Smike#define _POSIX_C_SOURCE 199506 48393510Smike#endif 48493510Smike#endif 48593510Smike 48693510Smike/* 48793510Smike * Deal with all versions of POSIX. The ordering relative to the tests above is 48893510Smike * important. 48993510Smike */ 49093510Smike#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 49193510Smike#define _POSIX_C_SOURCE 198808 49293510Smike#endif 49393510Smike#ifdef _POSIX_C_SOURCE 49493510Smike#if _POSIX_C_SOURCE >= 200112 49593510Smike#define __POSIX_VISIBLE 200112 49693510Smike#define __ISO_C_VISIBLE 1999 49793510Smike#elif _POSIX_C_SOURCE >= 199506 49893510Smike#define __POSIX_VISIBLE 199506 49993510Smike#define __ISO_C_VISIBLE 1990 50093510Smike#elif _POSIX_C_SOURCE >= 199309 50193510Smike#define __POSIX_VISIBLE 199309 50293510Smike#define __ISO_C_VISIBLE 1990 503100109Swollman#elif _POSIX_C_SOURCE >= 199209 504100109Swollman#define __POSIX_VISIBLE 199209 505100109Swollman#define __ISO_C_VISIBLE 1990 50693510Smike#elif _POSIX_C_SOURCE >= 199009 50793510Smike#define __POSIX_VISIBLE 199009 50893510Smike#define __ISO_C_VISIBLE 1990 50993510Smike#else 51093510Smike#define __POSIX_VISIBLE 198808 51193510Smike#define __ISO_C_VISIBLE 0 51293510Smike#endif /* _POSIX_C_SOURCE */ 51393510Smike#else 51493510Smike/*- 51593510Smike * Deal with _ANSI_SOURCE: 51693510Smike * If it is defined, and no other compilation environment is explicitly 51793510Smike * requested, then define our internal feature-test macros to zero. This 51893510Smike * makes no difference to the preprocessor (undefined symbols in preprocessing 51993510Smike * expressions are defined to have value zero), but makes it more convenient for 52093510Smike * a test program to print out the values. 52193510Smike * 52293510Smike * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 52393510Smike * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 52493510Smike * environment (and in fact we will never get here). 52593510Smike */ 526105654Smike#if defined(_ANSI_SOURCE) /* Hide almost everything. */ 52793510Smike#define __POSIX_VISIBLE 0 52893510Smike#define __XSI_VISIBLE 0 52993510Smike#define __BSD_VISIBLE 0 53093510Smike#define __ISO_C_VISIBLE 1990 531105654Smike#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 532105654Smike#define __POSIX_VISIBLE 0 533105654Smike#define __XSI_VISIBLE 0 534105654Smike#define __BSD_VISIBLE 0 535105654Smike#define __ISO_C_VISIBLE 1999 53693510Smike#else /* Default environment: show everything. */ 53793510Smike#define __POSIX_VISIBLE 200112 53893510Smike#define __XSI_VISIBLE 600 53993510Smike#define __BSD_VISIBLE 1 54093510Smike#define __ISO_C_VISIBLE 1999 54193510Smike#endif 54293510Smike#endif 54393510Smike 5442212Sbde#endif /* !_SYS_CDEFS_H_ */ 545