cdefs.h revision 118023
11541Srgrimes/* 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 * 3. All advertising materials mentioning features or use of this software 171541Srgrimes * must display the following acknowledgement: 181541Srgrimes * This product includes software developed by the University of 191541Srgrimes * California, Berkeley and its contributors. 201541Srgrimes * 4. Neither the name of the University nor the names of its contributors 211541Srgrimes * may be used to endorse or promote products derived from this software 221541Srgrimes * without specific prior written permission. 231541Srgrimes * 241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341541Srgrimes * SUCH DAMAGE. 351541Srgrimes * 3614495Shsu * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 3750477Speter * $FreeBSD: head/sys/sys/cdefs.h 118023 2003-07-25 18:40:36Z gad $ 381541Srgrimes */ 391541Srgrimes 402165Spaul#ifndef _SYS_CDEFS_H_ 412165Spaul#define _SYS_CDEFS_H_ 421541Srgrimes 431541Srgrimes#if defined(__cplusplus) 441541Srgrimes#define __BEGIN_DECLS extern "C" { 4536449Sdt#define __END_DECLS } 461541Srgrimes#else 471541Srgrimes#define __BEGIN_DECLS 481541Srgrimes#define __END_DECLS 491541Srgrimes#endif 501541Srgrimes 511541Srgrimes/* 521541Srgrimes * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 531541Srgrimes * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 5436971Sbde * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI 5536971Sbde * mode -- there must be no spaces between its arguments, and for nested 5636971Sbde * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also 5736971Sbde * concatenate double-quoted strings produced by the __STRING macro, but 5836971Sbde * this only works with ANSI C. 5925083Sjdp * 6025083Sjdp * __XSTRING is like __STRING, but it expands any macros in its argument 6125083Sjdp * first. It is only available with ANSI C. 621541Srgrimes */ 631541Srgrimes#if defined(__STDC__) || defined(__cplusplus) 641541Srgrimes#define __P(protos) protos /* full-blown ANSI C */ 655012Sbde#define __CONCAT1(x,y) x ## y 665012Sbde#define __CONCAT(x,y) __CONCAT1(x,y) 6725083Sjdp#define __STRING(x) #x /* stringify without expanding x */ 6825083Sjdp#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ 691541Srgrimes 701541Srgrimes#define __const const /* define reserved names to standard */ 711541Srgrimes#define __signed signed 721541Srgrimes#define __volatile volatile 731541Srgrimes#if defined(__cplusplus) 741541Srgrimes#define __inline inline /* convert to C++ keyword */ 751541Srgrimes#else 761541Srgrimes#ifndef __GNUC__ 771541Srgrimes#define __inline /* delete GCC keyword */ 781541Srgrimes#endif /* !__GNUC__ */ 791541Srgrimes#endif /* !__cplusplus */ 801541Srgrimes 811541Srgrimes#else /* !(__STDC__ || __cplusplus) */ 821541Srgrimes#define __P(protos) () /* traditional C preprocessor */ 831541Srgrimes#define __CONCAT(x,y) x/**/y 841541Srgrimes#define __STRING(x) "x" 851541Srgrimes 861541Srgrimes#ifndef __GNUC__ 871541Srgrimes#define __const /* delete pseudo-ANSI C keywords */ 881541Srgrimes#define __inline 891541Srgrimes#define __signed 901541Srgrimes#define __volatile 911541Srgrimes/* 921541Srgrimes * In non-ANSI C environments, new programs will want ANSI-only C keywords 931541Srgrimes * deleted from the program and old programs will want them left alone. 941541Srgrimes * When using a compiler other than gcc, programs using the ANSI C keywords 951541Srgrimes * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. 961541Srgrimes * When using "gcc -traditional", we assume that this is the intent; if 971541Srgrimes * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. 981541Srgrimes */ 991541Srgrimes#ifndef NO_ANSI_KEYWORDS 1001541Srgrimes#define const /* delete ANSI C keywords */ 1011541Srgrimes#define inline 1021541Srgrimes#define signed 1031541Srgrimes#define volatile 1045209Snate#endif /* !NO_ANSI_KEYWORDS */ 10515243Sbde#endif /* !__GNUC__ */ 1061541Srgrimes#endif /* !(__STDC__ || __cplusplus) */ 1071541Srgrimes 1081541Srgrimes/* 10938509Sbde * Compiler-dependent macros to help declare dead (non-returning) and 11038509Sbde * pure (no side effects) functions, and unused variables. They are 11138509Sbde * null except for versions of gcc that are known to support the features 11238509Sbde * properly (old versions of gcc-2 supported the dead and pure features 113103845Speter * in a different (wrong) way). If we do not provide an implementation 114103845Speter * for a given compiler, let the compile fail if it is told to use 115103845Speter * a feature that we cannot live without. 1161541Srgrimes */ 117103845Speter#ifdef lint 11883443Sasmodai#define __dead2 11983443Sasmodai#define __pure2 12083443Sasmodai#define __unused 121103834Speter#define __packed 122103836Speter#define __aligned(x) 123103841Speter#define __section(x) 124103845Speter#else 125103845Speter#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5 126103845Speter#define __dead2 127103845Speter#define __pure2 128103845Speter#define __unused 1292059Sdg#endif 13017648Speter#if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 13183443Sasmodai#define __dead2 __attribute__((__noreturn__)) 13283443Sasmodai#define __pure2 __attribute__((__const__)) 13383443Sasmodai#define __unused 134103845Speter/* XXX Find out what to do for __packed, __aligned and __section */ 1351541Srgrimes#endif 13677631Sobrien#if __GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ == 3 13783443Sasmodai#define __dead2 __attribute__((__noreturn__)) 13883443Sasmodai#define __pure2 __attribute__((__const__)) 13983443Sasmodai#define __unused __attribute__((__unused__)) 140103834Speter#define __packed __attribute__((__packed__)) 141103834Speter#define __aligned(x) __attribute__((__aligned__(x))) 142103836Speter#define __section(x) __attribute__((__section__(x))) 14317648Speter#endif 144103845Speter#endif 1451541Srgrimes 146117906Speter#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ >= 4 147117906Speter#define __always_inline __attribute__((__always_inline__)) 148117906Speter#else 149117906Speter#define __always_inline 150117906Speter#endif 151117906Speter 152117905Simp#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4 153117837Sphk#define __nonnull(x) __attribute__((__nonnull__(x))) 154117837Sphk#else 155117837Sphk#define __nonnull(x) 156117837Sphk#endif 157117837Sphk 15885672Smike/* XXX: should use `#if __STDC_VERSION__ < 199901'. */ 15985672Smike#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3) 16085672Smike#define __func__ NULL 16185672Smike#endif 16285672Smike 163103345Sbde#if __GNUC__ >= 2 && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 16486302Smike#define __LONG_LONG_SUPPORTED 16586302Smike#endif 16686302Smike 16738509Sbde/* 168104591Smike * GCC 2.95 provides `__restrict' as an extension to C90 to support the 169103370Swollman * C99-specific `restrict' type qualifier. We happen to use `__restrict' as 170103370Swollman * a way to define the `restrict' type qualifier without disturbing older 171103370Swollman * software that is unaware of C99 keywords. 17286803Smike */ 17386803Smike#if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) 17486803Smike#if __STDC_VERSION__ < 199901 17586803Smike#define __restrict 17686803Smike#else 17786803Smike#define __restrict restrict 17886803Smike#endif 17986803Smike#endif 18086803Smike 18186803Smike/* 18299594Smike * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h> 18399594Smike * require it. 18499594Smike */ 18599594Smike#define __offsetof(type, field) ((size_t)(&((type *)0)->field)) 18699594Smike 18799594Smike/* 18838509Sbde * Compiler-dependent macros to declare that functions take printf-like 18938509Sbde * or scanf-like arguments. They are null except for versions of gcc 19038509Sbde * that are known to support the features properly (old versions of gcc-2 19138509Sbde * didn't permit keeping the keywords out of the application namespace). 19238509Sbde */ 19337614Sbde#if __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 7 19437614Sbde#define __printflike(fmtarg, firstvararg) 19537614Sbde#define __scanflike(fmtarg, firstvararg) 19637614Sbde#else 19737614Sbde#define __printflike(fmtarg, firstvararg) \ 19837614Sbde __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 19937614Sbde#define __scanflike(fmtarg, firstvararg) \ 20037614Sbde __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) 20137614Sbde#endif 20237614Sbde 20340716Sjdp/* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ 204113679Sbde#if __FreeBSD_cc_version >= 300001 20540716Sjdp#define __printf0like(fmtarg, firstvararg) \ 20640716Sjdp __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) 20740716Sjdp#else 20840716Sjdp#define __printf0like(fmtarg, firstvararg) 20940716Sjdp#endif 21040716Sjdp 2115209Snate#ifdef __GNUC__ 21283443Sasmodai#define __strong_reference(sym,aliassym) \ 21358256Sjasone extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))); 2145209Snate#ifdef __STDC__ 21537052Speter#define __weak_reference(sym,alias) \ 21637052Speter __asm__(".weak " #alias); \ 21737862Sdfr __asm__(".equ " #alias ", " #sym) 21837052Speter#define __warn_references(sym,msg) \ 21937052Speter __asm__(".section .gnu.warning." #sym); \ 22039502Sjdp __asm__(".asciz \"" msg "\""); \ 22137052Speter __asm__(".previous") 22237052Speter#else 22337052Speter#define __weak_reference(sym,alias) \ 22437052Speter __asm__(".weak alias"); \ 22537862Sdfr __asm__(".equ alias, sym") 22637052Speter#define __warn_references(sym,msg) \ 22737052Speter __asm__(".section .gnu.warning.sym"); \ 22839502Sjdp __asm__(".asciz \"msg\""); \ 22937052Speter __asm__(".previous") 23037052Speter#endif /* __STDC__ */ 23137052Speter#endif /* __GNUC__ */ 2325209Snate 23383049Speter#ifdef __GNUC__ 23450614Speter#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") 23550614Speter#else 23683049Speter/* 237118023Sgad * The following definition might not work well if used in header files, 238118023Sgad * but it should be better than nothing. If you want a "do nothing" 239118023Sgad * version, then it should generate some harmless declaration, such as: 240118023Sgad * #define __IDSTRING(name,string) struct __hack 24183049Speter */ 24236971Sbde#define __IDSTRING(name,string) static const char name[] __unused = string 24350614Speter#endif 24431707Spst 24583552Sdillon/* 24683552Sdillon * Embed the rcs id of a source file in the resulting library. Note that in 24783552Sdillon * more recent ELF binutils, we use .ident allowing the ID to be stripped. 24883552Sdillon * Usage: 24983552Sdillon * __FBSDID("$FreeBSD: head/sys/sys/cdefs.h 118023 2003-07-25 18:40:36Z gad $"); 25083552Sdillon */ 25183489Sdillon#ifndef __FBSDID 25283528Sobrien#if !defined(lint) && !defined(STRIP_FBSDID) 25383526Sobrien#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 25483489Sdillon#else 25583552Sdillon#define __FBSDID(s) struct __hack 25683489Sdillon#endif 25783489Sdillon#endif 25883489Sdillon 25993996Sobrien#ifndef __RCSID 26093996Sobrien#ifndef NO__RCSID 26193993Sobrien#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 26293996Sobrien#else 263118023Sgad#define __RCSID(s) struct __hack 26493993Sobrien#endif 26593996Sobrien#endif 26693993Sobrien 26793996Sobrien#ifndef __RCSID_SOURCE 26893996Sobrien#ifndef NO__RCSID_SOURCE 26983049Speter#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) 27093996Sobrien#else 271118023Sgad#define __RCSID_SOURCE(s) struct __hack 27231707Spst#endif 27393996Sobrien#endif 27431707Spst 27593996Sobrien#ifndef __SCCSID 27693996Sobrien#ifndef NO__SCCSID 27793996Sobrien#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) 27893996Sobrien#else 279118023Sgad#define __SCCSID(s) struct __hack 28093996Sobrien#endif 28193996Sobrien#endif 28293996Sobrien 28393996Sobrien#ifndef __COPYRIGHT 28493996Sobrien#ifndef NO__COPYRIGHT 28583049Speter#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) 28693996Sobrien#else 287118023Sgad#define __COPYRIGHT(s) struct __hack 28831707Spst#endif 28993996Sobrien#endif 29031707Spst 29174070Sbillf#ifndef __DECONST 29274070Sbillf#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 29374070Sbillf#endif 29474070Sbillf 29574070Sbillf#ifndef __DEVOLATILE 29674070Sbillf#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) 29774070Sbillf#endif 29874070Sbillf 29974070Sbillf#ifndef __DEQUALIFY 30074070Sbillf#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) 30174070Sbillf#endif 30274070Sbillf 30393510Smike/*- 30493510Smike * The following definitions are an extension of the behavior originally 30599904Smikeh * implemented in <sys/_posix.h>, but with a different level of granularity. 30693510Smike * POSIX.1 requires that the macros we test be defined before any standard 30793510Smike * header file is included. 30893510Smike * 30993510Smike * Here's a quick run-down of the versions: 31093510Smike * defined(_POSIX_SOURCE) 1003.1-1988 31193510Smike * _POSIX_C_SOURCE == 1 1003.1-1990 312100109Swollman * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 31393510Smike * _POSIX_C_SOURCE == 199309 1003.1b-1993 31493510Smike * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 31593510Smike * and the omnibus ISO/IEC 9945-1: 1996 31693510Smike * _POSIX_C_SOURCE == 200112 1003.1-2001 31793510Smike * 31893510Smike * In addition, the X/Open Portability Guide, which is now the Single UNIX 31993510Smike * Specification, defines a feature-test macro which indicates the version of 32093510Smike * that specification, and which subsumes _POSIX_C_SOURCE. 32193510Smike * 32293510Smike * Our macros begin with two underscores to avoid namespace screwage. 32393510Smike */ 32493510Smike 32593510Smike/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 326100109Swollman#if _POSIX_C_SOURCE == 1 32793510Smike#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 32893510Smike#define _POSIX_C_SOURCE 199009 32993510Smike#endif 33093510Smike 331100109Swollman/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 332100109Swollman#if _POSIX_C_SOURCE == 2 333100109Swollman#undef _POSIX_C_SOURCE 334100109Swollman#define _POSIX_C_SOURCE 199209 335100109Swollman#endif 336100109Swollman 33793510Smike/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 33893510Smike#ifdef _XOPEN_SOURCE 33993715Speter#if _XOPEN_SOURCE - 0 >= 600 34093510Smike#define __XSI_VISIBLE 600 34193510Smike#undef _POSIX_C_SOURCE 34293510Smike#define _POSIX_C_SOURCE 200112 34393715Speter#elif _XOPEN_SOURCE - 0 >= 500 34493510Smike#define __XSI_VISIBLE 500 34593510Smike#undef _POSIX_C_SOURCE 34693510Smike#define _POSIX_C_SOURCE 199506 34793510Smike#endif 34893510Smike#endif 34993510Smike 35093510Smike/* 35193510Smike * Deal with all versions of POSIX. The ordering relative to the tests above is 35293510Smike * important. 35393510Smike */ 35493510Smike#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 35593510Smike#define _POSIX_C_SOURCE 198808 35693510Smike#endif 35793510Smike#ifdef _POSIX_C_SOURCE 35893510Smike#if _POSIX_C_SOURCE >= 200112 35993510Smike#define __POSIX_VISIBLE 200112 36093510Smike#define __ISO_C_VISIBLE 1999 36193510Smike#elif _POSIX_C_SOURCE >= 199506 36293510Smike#define __POSIX_VISIBLE 199506 36393510Smike#define __ISO_C_VISIBLE 1990 36493510Smike#elif _POSIX_C_SOURCE >= 199309 36593510Smike#define __POSIX_VISIBLE 199309 36693510Smike#define __ISO_C_VISIBLE 1990 367100109Swollman#elif _POSIX_C_SOURCE >= 199209 368100109Swollman#define __POSIX_VISIBLE 199209 369100109Swollman#define __ISO_C_VISIBLE 1990 37093510Smike#elif _POSIX_C_SOURCE >= 199009 37193510Smike#define __POSIX_VISIBLE 199009 37293510Smike#define __ISO_C_VISIBLE 1990 37393510Smike#else 37493510Smike#define __POSIX_VISIBLE 198808 37593510Smike#define __ISO_C_VISIBLE 0 37693510Smike#endif /* _POSIX_C_SOURCE */ 37793510Smike#else 37893510Smike/*- 37993510Smike * Deal with _ANSI_SOURCE: 38093510Smike * If it is defined, and no other compilation environment is explicitly 38193510Smike * requested, then define our internal feature-test macros to zero. This 38293510Smike * makes no difference to the preprocessor (undefined symbols in preprocessing 38393510Smike * expressions are defined to have value zero), but makes it more convenient for 38493510Smike * a test program to print out the values. 38593510Smike * 38693510Smike * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 38793510Smike * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 38893510Smike * environment (and in fact we will never get here). 38993510Smike */ 390105654Smike#if defined(_ANSI_SOURCE) /* Hide almost everything. */ 39193510Smike#define __POSIX_VISIBLE 0 39293510Smike#define __XSI_VISIBLE 0 39393510Smike#define __BSD_VISIBLE 0 39493510Smike#define __ISO_C_VISIBLE 1990 395105654Smike#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 396105654Smike#define __POSIX_VISIBLE 0 397105654Smike#define __XSI_VISIBLE 0 398105654Smike#define __BSD_VISIBLE 0 399105654Smike#define __ISO_C_VISIBLE 1999 40093510Smike#else /* Default environment: show everything. */ 40193510Smike#define __POSIX_VISIBLE 200112 40293510Smike#define __XSI_VISIBLE 600 40393510Smike#define __BSD_VISIBLE 1 40493510Smike#define __ISO_C_VISIBLE 1999 40593510Smike#endif 40693510Smike#endif 40793510Smike 4082212Sbde#endif /* !_SYS_CDEFS_H_ */ 409