t2ex/bsd_source/lib/libc/src_bsd/include/sys/cdefs.h | bare source | permlink (0.04 seconds) |
1: /* $OpenBSD: cdefs.h,v 1.32 2012/01/03 16:56:58 kettenis Exp $ */ 2: /* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */ 3: 4: /* 5: * Copyright (c) 1991, 1993 6: * The Regents of the University of California. All rights reserved. 7: * 8: * This code is derived from software contributed to Berkeley by 9: * Berkeley Software Design, Inc. 10: * 11: * Redistribution and use in source and binary forms, with or without 12: * modification, are permitted provided that the following conditions 13: * are met: 14: * 1. Redistributions of source code must retain the above copyright 15: * notice, this list of conditions and the following disclaimer. 16: * 2. Redistributions in binary form must reproduce the above copyright 17: * notice, this list of conditions and the following disclaimer in the 18: * documentation and/or other materials provided with the distribution. 19: * 3. Neither the name of the University nor the names of its contributors 20: * may be used to endorse or promote products derived from this software 21: * without specific prior written permission. 22: * 23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33: * SUCH DAMAGE. 34: * 35: * @(#)cdefs.h 8.7 (Berkeley) 1/21/94 36: */ 37: 38: #ifndef _SYS_CDEFS_H_ 39: #define _SYS_CDEFS_H_ 40: 41: #include <machine/cdefs.h> 42: 43: #if defined(__cplusplus) 44: #define __BEGIN_DECLS extern "C" { 45: #define __END_DECLS } 46: #else 47: #define __BEGIN_DECLS 48: #define __END_DECLS 49: #endif 50: 51: /* 52: * Macro to test if we're using a specific version of gcc or later. 53: */ 54: #ifdef __GNUC__ 55: #define __GNUC_PREREQ__(ma, mi) \ 56: ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))) 57: #else 58: #define __GNUC_PREREQ__(ma, mi) 0 59: #endif 60: 61: /* 62: * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 63: * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 64: * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 65: * in between its arguments. __CONCAT can also concatenate double-quoted 66: * strings produced by the __STRING macro, but this only works with ANSI C. 67: */ 68: #if defined(__STDC__) || defined(__cplusplus) 69: #define __P(protos) protos /* full-blown ANSI C */ 70: #define __CONCAT(x,y) x ## y 71: #define __STRING(x) #x 72: 73: #define __const const /* define reserved names to standard */ 74: #define __signed signed 75: #define __volatile volatile 76: #if defined(__cplusplus) || defined(__PCC__) 77: #define __inline inline /* convert to C++ keyword */ 78: #else 79: #if !defined(__GNUC__) && !defined(lint) 80: #define __inline /* delete GCC keyword */ 81: #endif /* !__GNUC__ && !lint */ 82: #endif /* !__cplusplus */ 83: 84: #else /* !(__STDC__ || __cplusplus) */ 85: #define __P(protos) () /* traditional C preprocessor */ 86: #define __CONCAT(x,y) x/**/y 87: #define __STRING(x) "x" 88: 89: #if !defined(__GNUC__) && !defined(lint) 90: #define __const /* delete pseudo-ANSI C keywords */ 91: #define __inline 92: #define __signed 93: #define __volatile 94: #endif /* !__GNUC__ && !lint */ 95: 96: /* 97: * In non-ANSI C environments, new programs will want ANSI-only C keywords 98: * deleted from the program and old programs will want them left alone. 99: * Programs using the ANSI C keywords const, inline etc. as normal 100: * identifiers should define -DNO_ANSI_KEYWORDS. 101: */ 102: #ifndef NO_ANSI_KEYWORDS 103: #define const __const /* convert ANSI C keywords */ 104: #define inline __inline 105: #define signed __signed 106: #define volatile __volatile 107: #endif /* !NO_ANSI_KEYWORDS */ 108: #endif /* !(__STDC__ || __cplusplus) */ 109: 110: /* 111: * GCC1 and some versions of GCC2 declare dead (non-returning) and 112: * pure (no side effects) functions using "volatile" and "const"; 113: * unfortunately, these then cause warnings under "-ansi -pedantic". 114: * GCC >= 2.5 uses the __attribute__((attrs)) style. All of these 115: * work for GNU C++ (modulo a slight glitch in the C++ grammar in 116: * the distribution version of 2.5.5). 117: */ 118: 119: #if !__GNUC_PREREQ__(2, 5) && !defined(__PCC__) 120: #define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 121: #if defined(__GNUC__) && !defined(__STRICT_ANSI__) 122: #define __dead __volatile 123: #define __pure __const 124: #elif defined(lint) 125: #define __dead /* NORETURN */ 126: #endif 127: #elif !defined(__STRICT_ANSI__) 128: #define __dead __attribute__((__noreturn__)) 129: #define __pure __attribute__((__const__)) 130: #endif 131: 132: #if __GNUC_PREREQ__(2, 7) 133: #define __unused __attribute__((__unused__)) 134: #else 135: #define __unused /* delete */ 136: #endif 137: 138: #if __GNUC_PREREQ__(3, 1) 139: #define __used __attribute__((__used__)) 140: #else 141: #define __used __unused /* suppress -Wunused warnings */ 142: #endif 143: 144: /* 145: * __returns_twice makes the compiler not assume the function 146: * only returns once. This affects registerisation of variables: 147: * even local variables need to be in memory across such a call. 148: * Example: setjmp() 149: */ 150: #if __GNUC_PREREQ__(4, 1) 151: #define __returns_twice __attribute__((returns_twice)) 152: #else 153: #define __returns_twice 154: #endif 155: 156: /* 157: * __only_inline makes the compiler only use this function definition 158: * for inlining; references that can't be inlined will be left as 159: * external references instead of generating a local copy. The 160: * matching library should include a simple extern definition for 161: * the function to handle those references. c.f. ctype.h 162: */ 163: #ifdef __GNUC__ 164: # if __GNUC_PREREQ__(4, 2) 165: #define __only_inline extern __inline __attribute__((__gnu_inline__)) 166: # else 167: #define __only_inline extern __inline 168: # endif 169: #else 170: #define __only_inline static __inline 171: #endif 172: 173: /* 174: * GNU C version 2.96 adds explicit branch prediction so that 175: * the CPU back-end can hint the processor and also so that 176: * code blocks can be reordered such that the predicted path 177: * sees a more linear flow, thus improving cache behavior, etc. 178: * 179: * The following two macros provide us with a way to utilize this 180: * compiler feature. Use __predict_true() if you expect the expression 181: * to evaluate to true, and __predict_false() if you expect the 182: * expression to evaluate to false. 183: * 184: * A few notes about usage: 185: * 186: * * Generally, __predict_false() error condition checks (unless 187: * you have some _strong_ reason to do otherwise, in which case 188: * document it), and/or __predict_true() `no-error' condition 189: * checks, assuming you want to optimize for the no-error case. 190: * 191: * * Other than that, if you don't know the likelihood of a test 192: * succeeding from empirical or other `hard' evidence, don't 193: * make predictions. 194: * 195: * * These are meant to be used in places that are run `a lot'. 196: * It is wasteful to make predictions in code that is run 197: * seldomly (e.g. at subsystem initialization time) as the 198: * basic block reordering that this affects can often generate 199: * larger code. 200: */ 201: #if __GNUC_PREREQ__(2, 96) 202: #define __predict_true(exp) __builtin_expect(((exp) != 0), 1) 203: #define __predict_false(exp) __builtin_expect(((exp) != 0), 0) 204: #else 205: #define __predict_true(exp) ((exp) != 0) 206: #define __predict_false(exp) ((exp) != 0) 207: #endif 208: 209: /* Delete pseudo-keywords wherever they are not available or needed. */ 210: #ifndef __dead 211: #define __dead 212: #define __pure 213: #endif 214: 215: #if __GNUC_PREREQ__(2, 7) || defined(__PCC__) 216: #define __packed __attribute__((__packed__)) 217: #elif defined(lint) 218: #define __packed 219: #endif 220: 221: #if !__GNUC_PREREQ__(2, 8) 222: #define __extension__ 223: #endif 224: 225: #if __GNUC_PREREQ__(2, 8) || defined(__PCC__) 226: #define __statement(x) __extension__(x) 227: #elif defined(lint) 228: #define __statement(x) (0) 229: #else 230: #define __statement(x) (x) 231: #endif 232: 233: #if __GNUC_PREREQ__(3, 0) 234: #define __malloc __attribute__((__malloc__)) 235: #else 236: #define __malloc 237: #endif 238: 239: /* 240: * "The nice thing about standards is that there are so many to choose from." 241: * There are a number of "feature test macros" specified by (different) 242: * standards that determine which interfaces and types the header files 243: * should expose. 244: * 245: * Because of inconsistencies in these macros, we define our own 246: * set in the private name space that end in _VISIBLE. These are 247: * always defined and so headers can test their values easily. 248: * Things can get tricky when multiple feature macros are defined. 249: * We try to take the union of all the features requested. 250: * 251: * The following macros are guaranteed to have a value after cdefs.h 252: * has been included: 253: * __POSIX_VISIBLE 254: * __XPG_VISIBLE 255: * __ISO_C_VISIBLE 256: * __BSD_VISIBLE 257: */ 258: 259: /* 260: * X/Open Portability Guides and Single Unix Specifications. 261: * _XOPEN_SOURCE XPG3 262: * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4 263: * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2 264: * _XOPEN_SOURCE == 500 XPG5 265: * _XOPEN_SOURCE == 520 XPG5v2 266: * _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI 267: * _XOPEN_SOURCE == 700 POSIX 1003.1-2008 with XSI 268: * 269: * The XPG spec implies a specific value for _POSIX_C_SOURCE. 270: */ 271: #ifdef _XOPEN_SOURCE 272: # if (_XOPEN_SOURCE - 0 >= 700) 273: # define __XPG_VISIBLE 700 274: # undef _POSIX_C_SOURCE 275: # define _POSIX_C_SOURCE 200809L 276: # elif (_XOPEN_SOURCE - 0 >= 600) 277: # define __XPG_VISIBLE 600 278: # undef _POSIX_C_SOURCE 279: # define _POSIX_C_SOURCE 200112L 280: # elif (_XOPEN_SOURCE - 0 >= 520) 281: # define __XPG_VISIBLE 520 282: # undef _POSIX_C_SOURCE 283: # define _POSIX_C_SOURCE 199506L 284: # elif (_XOPEN_SOURCE - 0 >= 500) 285: # define __XPG_VISIBLE 500 286: # undef _POSIX_C_SOURCE 287: # define _POSIX_C_SOURCE 199506L 288: # elif (_XOPEN_SOURCE_EXTENDED - 0 == 1) 289: # define __XPG_VISIBLE 420 290: # elif (_XOPEN_VERSION - 0 >= 4) 291: # define __XPG_VISIBLE 400 292: # else 293: # define __XPG_VISIBLE 300 294: # endif 295: #endif 296: 297: /* 298: * POSIX macros, these checks must follow the XOPEN ones above. 299: * 300: * _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE) 301: * _POSIX_C_SOURCE == 1 1003.1-1990 302: * _POSIX_C_SOURCE == 2 1003.2-1992 303: * _POSIX_C_SOURCE == 199309L 1003.1b-1993 304: * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995, 305: * and the omnibus ISO/IEC 9945-1:1996 306: * _POSIX_C_SOURCE == 200112L 1003.1-2001 307: * _POSIX_C_SOURCE == 200809L 1003.1-2008 308: * 309: * The POSIX spec implies a specific value for __ISO_C_VISIBLE, though 310: * this may be overridden by the _ISOC99_SOURCE macro later. 311: */ 312: #ifdef _POSIX_C_SOURCE 313: # if (_POSIX_C_SOURCE - 0 >= 200809) 314: # define __POSIX_VISIBLE 200809 315: # define __ISO_C_VISIBLE 1999 316: # elif (_POSIX_C_SOURCE - 0 >= 200112) 317: # define __POSIX_VISIBLE 200112 318: # define __ISO_C_VISIBLE 1999 319: # elif (_POSIX_C_SOURCE - 0 >= 199506) 320: # define __POSIX_VISIBLE 199506 321: # define __ISO_C_VISIBLE 1990 322: # elif (_POSIX_C_SOURCE - 0 >= 199309) 323: # define __POSIX_VISIBLE 199309 324: # define __ISO_C_VISIBLE 1990 325: # elif (_POSIX_C_SOURCE - 0 >= 2) 326: # define __POSIX_VISIBLE 199209 327: # define __ISO_C_VISIBLE 1990 328: # else 329: # define __POSIX_VISIBLE 199009 330: # define __ISO_C_VISIBLE 1990 331: # endif 332: #elif defined(_POSIX_SOURCE) 333: # define __POSIX_VISIBLE 198808 334: # define __ISO_C_VISIBLE 0 335: #endif 336: 337: /* 338: * _ANSI_SOURCE means to expose ANSI C89 interfaces only. 339: * If the user defines it in addition to one of the POSIX or XOPEN 340: * macros, assume the POSIX/XOPEN macro(s) should take precedence. 341: */ 342: #if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \ 343: !defined(__XPG_VISIBLE) 344: # define __POSIX_VISIBLE 0 345: # define __XPG_VISIBLE 0 346: # define __ISO_C_VISIBLE 1990 347: #endif 348: 349: /* 350: * _ISOC99_SOURCE and __STDC_VERSION__ override any of the other macros since 351: * they are non-exclusive. 352: */ 353: #if defined(_ISOC99_SOURCE) || \ 354: (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \ 355: (defined(__cplusplus) && __cplusplus >= 201103) 356: # undef __ISO_C_VISIBLE 357: # define __ISO_C_VISIBLE 1999 358: #endif 359: 360: /* 361: * Finally deal with BSD-specific interfaces that are not covered 362: * by any standards. We expose these when none of the POSIX or XPG 363: * macros is defined or if the user explicitly asks for them. 364: */ 365: #if !defined(_BSD_SOURCE) && \ 366: (defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE)) 367: # define __BSD_VISIBLE 0 368: #endif 369: 370: /* 371: * Default values. 372: */ 373: #ifndef __XPG_VISIBLE 374: # define __XPG_VISIBLE 700 375: #endif 376: #ifndef __POSIX_VISIBLE 377: # define __POSIX_VISIBLE 200809 378: #endif 379: #ifndef __ISO_C_VISIBLE 380: # define __ISO_C_VISIBLE 1999 381: #endif 382: #ifndef __BSD_VISIBLE 383: # define __BSD_VISIBLE 1 384: #endif 385: 386: #endif /* !_SYS_CDEFS_H_ */