00001 /* 00002 * Copyright (c) 1991, 1993 00003 * The Regents of the University of California. All rights reserved. 00004 * 00005 * This code is derived from software contributed to Berkeley by 00006 * Berkeley Software Design, Inc. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 1. Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 3. All advertising materials mentioning features or use of this software 00017 * must display the following acknowledgement: 00018 * This product includes software developed by the University of 00019 * California, Berkeley and its contributors. 00020 * 4. Neither the name of the University nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00025 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00027 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00030 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00031 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00033 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00034 * SUCH DAMAGE. 00035 * 00036 * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 00037 * $FreeBSD: src/sys/sys/cdefs.h,v 1.78 2003/10/01 11:26:20 mux Exp $ 00038 */ 00039 00040 #ifndef _SYS_CDEFS_H_ 00041 #define _SYS_CDEFS_H_ 00042 00043 #if defined(__cplusplus) 00044 #define __BEGIN_DECLS extern "C" { 00045 #define __END_DECLS } 00046 #else 00047 #define __BEGIN_DECLS 00048 #define __END_DECLS 00049 #endif 00050 00051 /* 00052 * Macro to test if we're using a specific version of gcc or later. 00053 */ 00054 #ifdef __GNUC__ 00055 #define __GNUC_PREREQ__(ma, mi) \ 00056 (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)) 00057 #else 00058 #define __GNUC_PREREQ__(ma, mi) 0 00059 #endif 00060 00061 /* 00062 * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 00063 * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 00064 * The __CONCAT macro is a bit tricky to use if it must work in non-ANSI 00065 * mode -- there must be no spaces between its arguments, and for nested 00066 * __CONCAT's, all the __CONCAT's must be at the left. __CONCAT can also 00067 * concatenate double-quoted strings produced by the __STRING macro, but 00068 * this only works with ANSI C. 00069 * 00070 * __XSTRING is like __STRING, but it expands any macros in its argument 00071 * first. It is only available with ANSI C. 00072 */ 00073 #if defined(__STDC__) || defined(__cplusplus) 00074 #define __P(protos) protos /* full-blown ANSI C */ 00075 #define __CONCAT1(x,y) x ## y 00076 #define __CONCAT(x,y) __CONCAT1(x,y) 00077 #define __STRING(x) #x /* stringify without expanding x */ 00078 #define __XSTRING(x) __STRING(x) /* expand x, then stringify */ 00079 00080 #define __const const /* define reserved names to standard */ 00081 #define __signed signed 00082 #define __volatile volatile 00083 #if defined(__cplusplus) 00084 #define __inline inline /* convert to C++ keyword */ 00085 #else 00086 #ifndef __GNUC__ 00087 #define __inline /* delete GCC keyword */ 00088 #endif /* !__GNUC__ */ 00089 #endif /* !__cplusplus */ 00090 00091 #else /* !(__STDC__ || __cplusplus) */ 00092 #define __P(protos) () /* traditional C preprocessor */ 00093 #define __CONCAT(x,y) xy 00094 #define __STRING(x) "x" 00095 00096 #ifndef __GNUC__ 00097 #define __const /* delete pseudo-ANSI C keywords */ 00098 #define __inline 00099 #define __signed 00100 #define __volatile 00101 /* 00102 * In non-ANSI C environments, new programs will want ANSI-only C keywords 00103 * deleted from the program and old programs will want them left alone. 00104 * When using a compiler other than gcc, programs using the ANSI C keywords 00105 * const, inline etc. as normal identifiers should define -DNO_ANSI_KEYWORDS. 00106 * When using "gcc -traditional", we assume that this is the intent; if 00107 * __GNUC__ is defined but __STDC__ is not, we leave the new keywords alone. 00108 */ 00109 #ifndef NO_ANSI_KEYWORDS 00110 #define const /* delete ANSI C keywords */ 00111 #define inline 00112 #define signed 00113 #define volatile 00114 #endif /* !NO_ANSI_KEYWORDS */ 00115 #endif /* !__GNUC__ */ 00116 #endif /* !(__STDC__ || __cplusplus) */ 00117 00118 /* 00119 * Compiler-dependent macros to help declare dead (non-returning) and 00120 * pure (no side effects) functions, and unused variables. They are 00121 * null except for versions of gcc that are known to support the features 00122 * properly (old versions of gcc-2 supported the dead and pure features 00123 * in a different (wrong) way). If we do not provide an implementation 00124 * for a given compiler, let the compile fail if it is told to use 00125 * a feature that we cannot live without. 00126 */ 00127 #ifdef lint 00128 #define __dead2 00129 #define __pure2 00130 #define __unused 00131 #define __packed 00132 #define __aligned(x) 00133 #define __section(x) 00134 #else 00135 #if !__GNUC_PREREQ__(2, 5) 00136 #define __dead2 00137 #define __pure2 00138 #define __unused 00139 #endif 00140 #if __GNUC__ == 2 && __GNUC_MINOR__ >= 5 && __GNUC_MINOR__ < 7 00141 #define __dead2 __attribute__((__noreturn__)) 00142 #define __pure2 __attribute__((__const__)) 00143 #define __unused 00144 /* XXX Find out what to do for __packed, __aligned and __section */ 00145 #endif 00146 #if __GNUC_PREREQ__(2, 7) 00147 #define __dead2 __attribute__((__noreturn__)) 00148 #define __pure2 __attribute__((__const__)) 00149 #define __unused __attribute__((__unused__)) 00150 #define __packed __attribute__((__packed__)) 00151 #define __aligned(x) __attribute__((__aligned__(x))) 00152 #define __section(x) __attribute__((__section__(x))) 00153 #endif 00154 #endif 00155 00156 #if __GNUC_PREREQ__(3, 1) 00157 #define __always_inline __attribute__((__always_inline__)) 00158 #else 00159 #define __always_inline 00160 #endif 00161 00162 #if __GNUC_PREREQ__(3, 3) 00163 #define __nonnull(x) __attribute__((__nonnull__(x))) 00164 #else 00165 #define __nonnull(x) 00166 #endif 00167 00168 /* XXX: should use `#if __STDC_VERSION__ < 199901'. */ 00169 #if !__GNUC_PREREQ__(2, 7) 00170 #define __func__ NULL 00171 #endif 00172 00173 #if __GNUC__ >= 2 && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901 00174 #define __LONG_LONG_SUPPORTED 00175 #endif 00176 00177 /* 00178 * GCC 2.95 provides `__restrict' as an extension to C90 to support the 00179 * C99-specific `restrict' type qualifier. We happen to use `__restrict' as 00180 * a way to define the `restrict' type qualifier without disturbing older 00181 * software that is unaware of C99 keywords. 00182 */ 00183 #if !(__GNUC__ == 2 && __GNUC_MINOR__ == 95) 00184 #if __STDC_VERSION__ < 199901 00185 #define __restrict 00186 #else 00187 #define __restrict restrict 00188 #endif 00189 #endif 00190 00191 /* 00192 * GNU C version 2.96 adds explicit branch prediction so that 00193 * the CPU back-end can hint the processor and also so that 00194 * code blocks can be reordered such that the predicted path 00195 * sees a more linear flow, thus improving cache behavior, etc. 00196 * 00197 * The following two macros provide us with a way to utilize this 00198 * compiler feature. Use __predict_true() if you expect the expression 00199 * to evaluate to true, and __predict_false() if you expect the 00200 * expression to evaluate to false. 00201 * 00202 * A few notes about usage: 00203 * 00204 * * Generally, __predict_false() error condition checks (unless 00205 * you have some _strong_ reason to do otherwise, in which case 00206 * document it), and/or __predict_true() `no-error' condition 00207 * checks, assuming you want to optimize for the no-error case. 00208 * 00209 * * Other than that, if you don't know the likelihood of a test 00210 * succeeding from empirical or other `hard' evidence, don't 00211 * make predictions. 00212 * 00213 * * These are meant to be used in places that are run `a lot'. 00214 * It is wasteful to make predictions in code that is run 00215 * seldomly (e.g. at subsystem initialization time) as the 00216 * basic block reordering that this affects can often generate 00217 * larger code. 00218 */ 00219 #if __GNUC_PREREQ__(2, 96) 00220 #define __predict_true(exp) __builtin_expect((exp), 1) 00221 #define __predict_false(exp) __builtin_expect((exp), 0) 00222 #else 00223 #define __predict_true(exp) (exp) 00224 #define __predict_false(exp) (exp) 00225 #endif 00226 00227 /* 00228 * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h> 00229 * require it. 00230 */ 00231 #define __offsetof(type, field) ((size_t)(&((type *)0)->field)) 00232 00233 /* 00234 * Compiler-dependent macros to declare that functions take printf-like 00235 * or scanf-like arguments. They are null except for versions of gcc 00236 * that are known to support the features properly (old versions of gcc-2 00237 * didn't permit keeping the keywords out of the application namespace). 00238 */ 00239 #if !__GNUC_PREREQ__(2, 7) 00240 #define __printflike(fmtarg, firstvararg) 00241 #define __scanflike(fmtarg, firstvararg) 00242 #else 00243 #define __printflike(fmtarg, firstvararg) \ 00244 __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 00245 #define __scanflike(fmtarg, firstvararg) \ 00246 __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) 00247 #endif 00248 00249 /* Compiler-dependent macros that rely on FreeBSD-specific extensions. */ 00250 #if __FreeBSD_cc_version >= 300001 00251 #define __printf0like(fmtarg, firstvararg) \ 00252 __attribute__((__format__ (__printf0__, fmtarg, firstvararg))) 00253 #else 00254 #define __printf0like(fmtarg, firstvararg) 00255 #endif 00256 00257 #ifdef __GNUC__ 00258 #define __strong_reference(sym,aliassym) \ 00259 extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym))); 00260 #ifdef __STDC__ 00261 #define __weak_reference(sym,alias) \ 00262 __asm__(".weak " #alias); \ 00263 __asm__(".equ " #alias ", " #sym) 00264 #define __warn_references(sym,msg) \ 00265 __asm__(".section .gnu.warning." #sym); \ 00266 __asm__(".asciz \"" msg "\""); \ 00267 __asm__(".previous") 00268 #else 00269 #define __weak_reference(sym,alias) \ 00270 __asm__(".weak alias"); \ 00271 __asm__(".equ alias, sym") 00272 #define __warn_references(sym,msg) \ 00273 __asm__(".section .gnu.warning.sym"); \ 00274 __asm__(".asciz \"msg\""); \ 00275 __asm__(".previous") 00276 #endif /* __STDC__ */ 00277 #endif /* __GNUC__ */ 00278 00279 #ifdef __GNUC__ 00280 #define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") 00281 #else 00282 /* 00283 * The following definition might not work well if used in header files, 00284 * but it should be better than nothing. If you want a "do nothing" 00285 * version, then it should generate some harmless declaration, such as: 00286 * #define __IDSTRING(name,string) struct __hack 00287 */ 00288 #define __IDSTRING(name,string) static const char name[] __unused = string 00289 #endif 00290 00291 /* 00292 * Embed the rcs id of a source file in the resulting library. Note that in 00293 * more recent ELF binutils, we use .ident allowing the ID to be stripped. 00294 * Usage: 00295 * __FBSDID("$FreeBSD: src/sys/sys/cdefs.h,v 1.78 2003/10/01 11:26:20 mux Exp $"); 00296 */ 00297 #ifndef __FBSDID 00298 #if !defined(lint) && !defined(STRIP_FBSDID) 00299 #define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 00300 #else 00301 #define __FBSDID(s) struct __hack 00302 #endif 00303 #endif 00304 00305 #ifndef __RCSID 00306 #ifndef NO__RCSID 00307 #define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s) 00308 #else 00309 #define __RCSID(s) struct __hack 00310 #endif 00311 #endif 00312 00313 #ifndef __RCSID_SOURCE 00314 #ifndef NO__RCSID_SOURCE 00315 #define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s) 00316 #else 00317 #define __RCSID_SOURCE(s) struct __hack 00318 #endif 00319 #endif 00320 00321 #ifndef __SCCSID 00322 #ifndef NO__SCCSID 00323 #define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s) 00324 #else 00325 #define __SCCSID(s) struct __hack 00326 #endif 00327 #endif 00328 00329 #ifndef __COPYRIGHT 00330 #ifndef NO__COPYRIGHT 00331 #define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s) 00332 #else 00333 #define __COPYRIGHT(s) struct __hack 00334 #endif 00335 #endif 00336 00337 #ifndef __DECONST 00338 #define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) 00339 #endif 00340 00341 #ifndef __DEVOLATILE 00342 #define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var)) 00343 #endif 00344 00345 #ifndef __DEQUALIFY 00346 #define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var)) 00347 #endif 00348 00349 /*- 00350 * The following definitions are an extension of the behavior originally 00351 * implemented in <sys/_posix.h>, but with a different level of granularity. 00352 * POSIX.1 requires that the macros we test be defined before any standard 00353 * header file is included. 00354 * 00355 * Here's a quick run-down of the versions: 00356 * defined(_POSIX_SOURCE) 1003.1-1988 00357 * _POSIX_C_SOURCE == 1 1003.1-1990 00358 * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 00359 * _POSIX_C_SOURCE == 199309 1003.1b-1993 00360 * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 00361 * and the omnibus ISO/IEC 9945-1: 1996 00362 * _POSIX_C_SOURCE == 200112 1003.1-2001 00363 * 00364 * In addition, the X/Open Portability Guide, which is now the Single UNIX 00365 * Specification, defines a feature-test macro which indicates the version of 00366 * that specification, and which subsumes _POSIX_C_SOURCE. 00367 * 00368 * Our macros begin with two underscores to avoid namespace screwage. 00369 */ 00370 00371 /* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 00372 #if _POSIX_C_SOURCE == 1 00373 #undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 00374 #define _POSIX_C_SOURCE 199009 00375 #endif 00376 00377 /* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 00378 #if _POSIX_C_SOURCE == 2 00379 #undef _POSIX_C_SOURCE 00380 #define _POSIX_C_SOURCE 199209 00381 #endif 00382 00383 /* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 00384 #ifdef _XOPEN_SOURCE 00385 #if _XOPEN_SOURCE - 0 >= 600 00386 #define __XSI_VISIBLE 600 00387 #undef _POSIX_C_SOURCE 00388 #define _POSIX_C_SOURCE 200112 00389 #elif _XOPEN_SOURCE - 0 >= 500 00390 #define __XSI_VISIBLE 500 00391 #undef _POSIX_C_SOURCE 00392 #define _POSIX_C_SOURCE 199506 00393 #endif 00394 #endif 00395 00396 /* 00397 * Deal with all versions of POSIX. The ordering relative to the tests above is 00398 * important. 00399 */ 00400 #if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 00401 #define _POSIX_C_SOURCE 198808 00402 #endif 00403 #ifdef _POSIX_C_SOURCE 00404 #if _POSIX_C_SOURCE >= 200112 00405 #define __POSIX_VISIBLE 200112 00406 #define __ISO_C_VISIBLE 1999 00407 #elif _POSIX_C_SOURCE >= 199506 00408 #define __POSIX_VISIBLE 199506 00409 #define __ISO_C_VISIBLE 1990 00410 #elif _POSIX_C_SOURCE >= 199309 00411 #define __POSIX_VISIBLE 199309 00412 #define __ISO_C_VISIBLE 1990 00413 #elif _POSIX_C_SOURCE >= 199209 00414 #define __POSIX_VISIBLE 199209 00415 #define __ISO_C_VISIBLE 1990 00416 #elif _POSIX_C_SOURCE >= 199009 00417 #define __POSIX_VISIBLE 199009 00418 #define __ISO_C_VISIBLE 1990 00419 #else 00420 #define __POSIX_VISIBLE 198808 00421 #define __ISO_C_VISIBLE 0 00422 #endif /* _POSIX_C_SOURCE */ 00423 #else 00424 /*- 00425 * Deal with _ANSI_SOURCE: 00426 * If it is defined, and no other compilation environment is explicitly 00427 * requested, then define our internal feature-test macros to zero. This 00428 * makes no difference to the preprocessor (undefined symbols in preprocessing 00429 * expressions are defined to have value zero), but makes it more convenient for 00430 * a test program to print out the values. 00431 * 00432 * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 00433 * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 00434 * environment (and in fact we will never get here). 00435 */ 00436 #if defined(_ANSI_SOURCE) /* Hide almost everything. */ 00437 #define __POSIX_VISIBLE 0 00438 #define __XSI_VISIBLE 0 00439 #define __BSD_VISIBLE 0 00440 #define __ISO_C_VISIBLE 1990 00441 #elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 00442 #define __POSIX_VISIBLE 0 00443 #define __XSI_VISIBLE 0 00444 #define __BSD_VISIBLE 0 00445 #define __ISO_C_VISIBLE 1999 00446 #else /* Default environment: show everything. */ 00447 #define __POSIX_VISIBLE 200112 00448 #define __XSI_VISIBLE 600 00449 #define __BSD_VISIBLE 1 00450 #define __ISO_C_VISIBLE 1999 00451 #endif 00452 #endif 00453 00454 #endif /* !_SYS_CDEFS_H_ */