cdefs.h revision 998f2d5a50adffcc0447912fb6a7af2dac7accf1
11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* $NetBSD: cdefs.h,v 1.58 2004/12/11 05:59:00 christos Exp $ */ 21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (c) 1991, 1993 51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * The Regents of the University of California. All rights reserved. 61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * This code is derived from software contributed to Berkeley by 81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Berkeley Software Design, Inc. 91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without 111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions 121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met: 131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 1. Redistributions of source code must retain the above copyright 141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer. 151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer in the 171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * documentation and/or other materials provided with the distribution. 181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 3. Neither the name of the University nor the names of its contributors 191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * may be used to endorse or promote products derived from this software 201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * without specific prior written permission. 211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE. 331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _SYS_CDEFS_H_ 381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _SYS_CDEFS_H_ 391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 41e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes * Testing against Clang-specific extensions. 42e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes */ 43e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes 44e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#ifndef __has_extension 45e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#define __has_extension __has_feature 46e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#endif 47e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#ifndef __has_feature 48e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#define __has_feature(x) 0 49e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#endif 50e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#ifndef __has_include 51e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#define __has_include(x) 0 52e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#endif 53e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#ifndef __has_builtin 54e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#define __has_builtin(x) 0 55e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes#endif 561aaa17802c92d99ae170245c2b2f15a6c27b133eNick Kralevich#ifndef __has_attribute 571aaa17802c92d99ae170245c2b2f15a6c27b133eNick Kralevich#define __has_attribute(x) 0 581aaa17802c92d99ae170245c2b2f15a6c27b133eNick Kralevich#endif 59e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes 60e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes 61e6c57fcb05b0dcbfa8129bb6f7d99093f4819370Elliott Hughes/* 621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Macro to test if we're using a GNU C compiler of a specific vintage 631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * or later, for e.g. features that appeared in a particular version 641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * of GNU C. Usage: 651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 66e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes * #if __GNUC_PREREQ(major, minor) 671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ...cool feature... 681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * #else 691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ...delete feature... 701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * #endif 711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef __GNUC__ 73e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#define __GNUC_PREREQ(x, y) \ 741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ 751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project (__GNUC__ > (x))) 761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 77e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#define __GNUC_PREREQ(x, y) 0 781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 80998f2d5a50adffcc0447912fb6a7af2dac7accf1Elliott Hughes#define __strong_alias(alias, sym) \ 81998f2d5a50adffcc0447912fb6a7af2dac7accf1Elliott Hughes __asm__(".global " #alias "\n" \ 82998f2d5a50adffcc0447912fb6a7af2dac7accf1Elliott Hughes #alias " = " #sym); 831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if defined(__cplusplus) 851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __BEGIN_DECLS extern "C" { 861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __END_DECLS } 871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __static_cast(x,y) static_cast<x>(y) 881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __BEGIN_DECLS 901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __END_DECLS 911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __static_cast(x,y) (x)y 921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * The __CONCAT macro is used to concatenate parts of symbol names, e.g. 961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. 971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * The __CONCAT macro is a bit tricky -- make sure you don't put spaces 981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * in between its arguments. __CONCAT can also concatenate double-quoted 991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * strings produced by the __STRING macro, but this only works with ANSI C. 1001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 1011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ___STRING(x) __STRING(x) 1031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define ___CONCAT(x,y) __CONCAT(x,y) 1041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1058eda21baa54977e4d164a4174d06b6aa12115fb1David 'Digit' Turner#if defined(__STDC__) || defined(__cplusplus) 1061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __P(protos) protos /* full-blown ANSI C */ 1071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __CONCAT(x,y) x ## y 1081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __STRING(x) #x 1091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __const const /* define reserved names to standard */ 1111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __signed signed 1121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __volatile volatile 1131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if defined(__cplusplus) 1141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __inline inline /* convert to C++ keyword */ 1151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 1161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if !defined(__GNUC__) && !defined(__lint__) 1171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __inline /* delete GCC keyword */ 1181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !__GNUC__ && !__lint__ */ 1191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !__cplusplus */ 1201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else /* !(__STDC__ || __cplusplus) */ 1221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __P(protos) () /* traditional C preprocessor */ 1231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __CONCAT(x,y) x/**/y 1241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __STRING(x) "x" 1251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef __GNUC__ 1271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __const /* delete pseudo-ANSI C keywords */ 1281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __inline 1291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __signed 1301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __volatile 1311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !__GNUC__ */ 1321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 1341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * In non-ANSI C environments, new programs will want ANSI-only C keywords 1351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * deleted from the program and old programs will want them left alone. 1361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Programs using the ANSI C keywords const, inline etc. as normal 1371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * identifiers should define -DNO_ANSI_KEYWORDS. 1381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 1391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef NO_ANSI_KEYWORDS 1401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define const __const /* convert ANSI C keywords */ 1411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define inline __inline 1421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define signed __signed 1431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define volatile __volatile 1441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !NO_ANSI_KEYWORDS */ 1451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !(__STDC__ || __cplusplus) */ 1461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 1481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Used for internal auditing of the NetBSD source tree. 1491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 1501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef __AUDIT__ 1511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __aconst __const 1521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 1531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __aconst 1541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 1551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 1571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * The following macro is used to remove const cast-away warnings 1581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * from gcc -Wcast-qual; it should be used with caution because it 1591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * can hide valid errors; in particular most valid uses are in 1601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * situations where the API requires it, not to cast away string 1611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * constants. We don't use *intptr_t on purpose here and we are 1621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * explicit about unsigned long so that we don't have additional 1631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * dependencies. 1641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 1651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 1661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 1681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * GCC2 provides __extension__ to suppress warnings for various GNU C 1691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * language extensions under "-ansi -pedantic". 1701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 171e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if !__GNUC_PREREQ(2, 0) 1721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __extension__ /* delete __extension__ if non-gcc or gcc1 */ 1731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 1741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 1761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * GCC1 and some versions of GCC2 declare dead (non-returning) and 1771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * pure (no side effects) functions using "volatile" and "const"; 1781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * unfortunately, these then cause warnings under "-ansi -pedantic". 1791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of 1801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * these work for GNU C++ (modulo a slight glitch in the C++ grammar 1811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * in the distribution version of 2.5.5). 1821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 183e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if !__GNUC_PREREQ(2, 5) 1841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */ 1851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if defined(__GNUC__) && !defined(__STRICT_ANSI__) 1861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __dead __volatile 1871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __pure __const 1881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 1891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 1901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Delete pseudo-keywords wherever they are not available or needed. */ 1921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef __dead 1931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __dead 1941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __pure 1951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 1961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 197e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(2, 7) 1981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __unused __attribute__((__unused__)) 1991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 2001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __unused /* delete */ 2011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 203a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#define __pure2 __attribute__((__const__)) /* Android-added: used by FreeBSD libm */ 204a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 205e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(3, 1) 2061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __used __attribute__((__used__)) 2071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 2081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __used /* delete */ 2091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 211e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(2, 7) 2121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __packed __attribute__((__packed__)) 2131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __aligned(x) __attribute__((__aligned__(x))) 2141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __section(x) __attribute__((__section__(x))) 2151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#elif defined(__lint__) 2161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __packed /* delete */ 2171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __aligned(x) /* delete */ 2181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __section(x) /* delete */ 2191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 2201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __packed error: no __packed for this compiler 2211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __aligned(x) error: no __aligned for this compiler 2221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __section(x) error: no __section for this compiler 2231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 225e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if !__GNUC_PREREQ(2, 8) 2261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __extension__ 2271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 229e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(2, 8) 2301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __statement(x) __extension__(x) 2311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#elif defined(lint) 2321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __statement(x) (0) 2331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 2341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __statement(x) (x) 2351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 23706040fd75c1edff9e5ffb2b3d3e2a6e66d57c11dElliott Hughes#define __nonnull(args) __attribute__((__nonnull__ args)) 23806040fd75c1edff9e5ffb2b3d3e2a6e66d57c11dElliott Hughes 23906040fd75c1edff9e5ffb2b3d3e2a6e66d57c11dElliott Hughes#define __printflike(x, y) __attribute__((__format__(printf, x, y))) __nonnull((x)) 24006040fd75c1edff9e5ffb2b3d3e2a6e66d57c11dElliott Hughes#define __scanflike(x, y) __attribute__((__format__(scanf, x, y))) __nonnull((x)) 241d04c18397946f87ac4495351537c31a3d67257daElliott Hughes 2421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * C99 defines the restrict type qualifier keyword, which was made available 2441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * in GCC 2.92. 2451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 2468eda21baa54977e4d164a4174d06b6aa12115fb1David 'Digit' Turner#if defined(__STDC__VERSION__) && __STDC_VERSION__ >= 199901L 2471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __restrict restrict 2481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 249e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if !__GNUC_PREREQ(2, 92) 2501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __restrict /* delete __restrict when not supported */ 2511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * C99 defines __func__ predefined identifier, which was made available 2561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * in GCC 2.95. 2571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 2588eda21baa54977e4d164a4174d06b6aa12115fb1David 'Digit' Turner#if !defined(__STDC_VERSION__) || !(__STDC_VERSION__ >= 199901L) 259e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(2, 6) 2601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __func__ __PRETTY_FUNCTION__ 261e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#elif __GNUC_PREREQ(2, 4) 2621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __func__ __FUNCTION__ 2631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 2641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __func__ "" 2651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !(__STDC_VERSION__ >= 199901L) */ 2671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * A barrier to stop the optimizer from moving code or assume live 2701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * register values. This is gcc specific, the version is more or less 2711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * arbitrary, might work with older compilers. 2721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 273e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(2, 95) 2741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __insn_barrier() __asm __volatile("":::"memory") 2751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 2761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __insn_barrier() /* */ 2771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * GNU C version 2.96 adds explicit branch prediction so that 2811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * the CPU back-end can hint the processor and also so that 2821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * code blocks can be reordered such that the predicted path 2831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * sees a more linear flow, thus improving cache behavior, etc. 2841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * The following two macros provide us with a way to use this 2861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * compiler feature. Use __predict_true() if you expect the expression 2871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * to evaluate to true, and __predict_false() if you expect the 2881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * expression to evaluate to false. 2891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * A few notes about usage: 2911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Generally, __predict_false() error condition checks (unless 2931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * you have some _strong_ reason to do otherwise, in which case 2941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * document it), and/or __predict_true() `no-error' condition 2951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * checks, assuming you want to optimize for the no-error case. 2961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Other than that, if you don't know the likelihood of a test 2981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * succeeding from empirical or other `hard' evidence, don't 2991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * make predictions. 3001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 3011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * These are meant to be used in places that are run `a lot'. 3021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * It is wasteful to make predictions in code that is run 3031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * seldomly (e.g. at subsystem initialization time) as the 3041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * basic block reordering that this affects can often generate 3051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * larger code. 3061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 307e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(2, 96) 3081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __predict_true(exp) __builtin_expect((exp) != 0, 1) 3091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __predict_false(exp) __builtin_expect((exp) != 0, 0) 3101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 3111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __predict_true(exp) (exp) 3121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __predict_false(exp) (exp) 3131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 3141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 315e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(2, 96) 3161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __noreturn __attribute__((__noreturn__)) 3171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __mallocfunc __attribute__((malloc)) 318a677907ee8ecca034318fdb97902fa73e7392c4fNick Kralevich#define __purefunc __attribute__((pure)) 3191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 3201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __noreturn 3211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __mallocfunc 322a677907ee8ecca034318fdb97902fa73e7392c4fNick Kralevich#define __purefunc 3231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 3241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 325e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(3, 1) 326a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#define __always_inline __attribute__((__always_inline__)) 327a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#else 328a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#define __always_inline 329a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes#endif 330a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 331e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(3, 4) 33224fad01755d33e6772ea3be56b702570bf257d55Elliott Hughes#define __wur __attribute__((__warn_unused_result__)) 33324fad01755d33e6772ea3be56b702570bf257d55Elliott Hughes#else 33424fad01755d33e6772ea3be56b702570bf257d55Elliott Hughes#define __wur 33524fad01755d33e6772ea3be56b702570bf257d55Elliott Hughes#endif 33624fad01755d33e6772ea3be56b702570bf257d55Elliott Hughes 337e0c56efddf55ad40cb35b2c22e1dd9b4b50df159Elliott Hughes#if __GNUC_PREREQ(4, 3) 338b24c0637d06fe0980b9e13a8d0c3e6f4dbda9cd5Nick Kralevich#define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg))) 339c13fb75ceabb47f8292be206db80b93889fccf66Elliott Hughes#define __warnattr(msg) __attribute__((__warning__(msg))) 340b24c0637d06fe0980b9e13a8d0c3e6f4dbda9cd5Nick Kralevich#else 341b24c0637d06fe0980b9e13a8d0c3e6f4dbda9cd5Nick Kralevich#define __errordecl(name, msg) extern void name(void) 342c13fb75ceabb47f8292be206db80b93889fccf66Elliott Hughes#define __warnattr(msg) 343b24c0637d06fe0980b9e13a8d0c3e6f4dbda9cd5Nick Kralevich#endif 344b24c0637d06fe0980b9e13a8d0c3e6f4dbda9cd5Nick Kralevich 3451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 3462cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes * Some BSD source needs these macros. 3472cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes * Originally they embedded the rcs versions of each source file 3482cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes * in the generated binary. We strip strings during build anyway,. 3493527fd6f0df794207215790321824b7844cc712dDavid 'Digit' Turner */ 3502cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __IDSTRING(_prefix,_s) /* nothing */ 3512cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __COPYRIGHT(_s) /* nothing */ 3522cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __FBSDID(_s) /* nothing */ 3532cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __RCSID(_s) /* nothing */ 3542cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __SCCSID(_s) /* nothing */ 3553527fd6f0df794207215790321824b7844cc712dDavid 'Digit' Turner 356f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes/* 357f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes * _BSD_SOURCE and _GNU_SOURCE are expected to be defined by callers before 358f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes * any standard header file is included. In those header files we test 359f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes * against __USE_BSD and __USE_GNU. glibc does this in <features.h> but we 360f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes * do it in <sys/cdefs.h> instead because that's where our existing 361f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes * _POSIX_C_SOURCE tests were, and we're already confident that <sys/cdefs.h> 362f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes * is included everywhere it should be. 363fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes * 364fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes * The _GNU_SOURCE test needs to come before any _BSD_SOURCE or _POSIX* tests 365fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes * because _GNU_SOURCE implies everything else. 366f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes */ 367f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes#if defined(_GNU_SOURCE) 368f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes# define __USE_GNU 1 369fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes# undef _POSIX_SOURCE 370fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes# define _POSIX_SOURCE 1 371fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes# undef _POSIX_C_SOURCE 372fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes# define _POSIX_C_SOURCE 200809L 373fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes# undef _BSD_SOURCE 374fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes# define _BSD_SOURCE 1 375fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes#endif 376fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes 377fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes#if defined(_BSD_SOURCE) 378fc8974b7aabd2e7c9884e8d5e3d84395461396ffElliott Hughes# define __USE_BSD 1 379f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes#endif 380f4c948a9e9b616c4f133f9495dacb105e51b3e49Elliott Hughes 38150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner/*- 38250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * POSIX.1 requires that the macros we test be defined before any standard 38350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * header file is included. 38450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * 38550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * Here's a quick run-down of the versions: 38650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * defined(_POSIX_SOURCE) 1003.1-1988 38750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * _POSIX_C_SOURCE == 1 1003.1-1990 38850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * _POSIX_C_SOURCE == 2 1003.2-1992 C Language Binding Option 38950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * _POSIX_C_SOURCE == 199309 1003.1b-1993 39050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * _POSIX_C_SOURCE == 199506 1003.1c-1995, 1003.1i-1995, 39150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * and the omnibus ISO/IEC 9945-1: 1996 39250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * _POSIX_C_SOURCE == 200112 1003.1-2001 39350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * _POSIX_C_SOURCE == 200809 1003.1-2008 39450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * 39550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * In addition, the X/Open Portability Guide, which is now the Single UNIX 39650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * Specification, defines a feature-test macro which indicates the version of 39750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * that specification, and which subsumes _POSIX_C_SOURCE. 39850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * 39950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * Our macros begin with two underscores to avoid namespace screwage. 40050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner */ 40150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner 40250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner/* Deal with IEEE Std. 1003.1-1990, in which _POSIX_C_SOURCE == 1. */ 40350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 1 40450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#undef _POSIX_C_SOURCE /* Probably illegal, but beyond caring now. */ 40550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define _POSIX_C_SOURCE 199009 40650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 40750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner 40850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner/* Deal with IEEE Std. 1003.2-1992, in which _POSIX_C_SOURCE == 2. */ 40950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE == 2 41050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#undef _POSIX_C_SOURCE 41150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define _POSIX_C_SOURCE 199209 41250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 41350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner 41450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner/* Deal with various X/Open Portability Guides and Single UNIX Spec. */ 41550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#ifdef _XOPEN_SOURCE 41650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#if _XOPEN_SOURCE - 0 >= 700 41750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __XSI_VISIBLE 700 41850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#undef _POSIX_C_SOURCE 41950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define _POSIX_C_SOURCE 200809 42050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif _XOPEN_SOURCE - 0 >= 600 42150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __XSI_VISIBLE 600 42250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#undef _POSIX_C_SOURCE 42350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define _POSIX_C_SOURCE 200112 42450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif _XOPEN_SOURCE - 0 >= 500 42550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __XSI_VISIBLE 500 42650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#undef _POSIX_C_SOURCE 42750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define _POSIX_C_SOURCE 199506 42850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 42950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 43050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner 43150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner/* 43250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * Deal with all versions of POSIX. The ordering relative to the tests above is 43350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * important. 43450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner */ 43550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#if defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) 43650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define _POSIX_C_SOURCE 198808 43750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 43850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#ifdef _POSIX_C_SOURCE 43950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#if _POSIX_C_SOURCE >= 200809 44050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 200809 44150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1999 44250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif _POSIX_C_SOURCE >= 200112 44350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 200112 44450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1999 44550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif _POSIX_C_SOURCE >= 199506 44650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 199506 44750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1990 44850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif _POSIX_C_SOURCE >= 199309 44950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 199309 45050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1990 45150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif _POSIX_C_SOURCE >= 199209 45250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 199209 45350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1990 45450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif _POSIX_C_SOURCE >= 199009 45550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 199009 45650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1990 45750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#else 45850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 198808 45950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 0 46050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif /* _POSIX_C_SOURCE */ 46150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#else 46250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner/*- 46350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * Deal with _ANSI_SOURCE: 46450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * If it is defined, and no other compilation environment is explicitly 46550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * requested, then define our internal feature-test macros to zero. This 46650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * makes no difference to the preprocessor (undefined symbols in preprocessing 46750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * expressions are defined to have value zero), but makes it more convenient for 46850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * a test program to print out the values. 46950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * 47050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * If a program mistakenly defines _ANSI_SOURCE and some other macro such as 47150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * _POSIX_C_SOURCE, we will assume that it wants the broader compilation 47250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * environment (and in fact we will never get here). 47350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner */ 47450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#if defined(_ANSI_SOURCE) /* Hide almost everything. */ 47550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 0 47650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __XSI_VISIBLE 0 47750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __BSD_VISIBLE 0 47850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1990 47950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#elif defined(_C99_SOURCE) /* Localism to specify strict C99 env. */ 48050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 0 48150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __XSI_VISIBLE 0 48250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __BSD_VISIBLE 0 48350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1999 48450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#else /* Default environment: show everything. */ 48550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __POSIX_VISIBLE 200809 48650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __XSI_VISIBLE 700 48750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __BSD_VISIBLE 1 48850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#define __ISO_C_VISIBLE 1999 48950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 49050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 49150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner 49250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner/* 49350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner * Default values. 49450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner */ 49550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#ifndef __XPG_VISIBLE 49650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner# define __XPG_VISIBLE 700 49750ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 49850ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#ifndef __POSIX_VISIBLE 49950ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner# define __POSIX_VISIBLE 200809 50050ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 50150ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#ifndef __ISO_C_VISIBLE 50250ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner# define __ISO_C_VISIBLE 1999 50350ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 50450ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#ifndef __BSD_VISIBLE 50550ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner# define __BSD_VISIBLE 1 50650ace4fec5e8cb5afcbc656a4556fa528adfd760David 'Digit' Turner#endif 5073527fd6f0df794207215790321824b7844cc712dDavid 'Digit' Turner 5081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define __BIONIC__ 1 50923d24394e72715ddf580726655c8ba3fbcf11bfeDavid 'Digit' Turner#include <android/api-level.h> 5101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 511caa15bfe2d6c065d2caff48583f18351bd96915fElliott Hughes/* glibc compatibility. */ 512caa15bfe2d6c065d2caff48583f18351bd96915fElliott Hughes#if __LP64__ 513caa15bfe2d6c065d2caff48583f18351bd96915fElliott Hughes#define __WORDSIZE 64 514caa15bfe2d6c065d2caff48583f18351bd96915fElliott Hughes#else 515caa15bfe2d6c065d2caff48583f18351bd96915fElliott Hughes#define __WORDSIZE 32 516caa15bfe2d6c065d2caff48583f18351bd96915fElliott Hughes#endif 517caa15bfe2d6c065d2caff48583f18351bd96915fElliott Hughes 518bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich/* 519bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich * When _FORTIFY_SOURCE is defined, automatic bounds checking is 520bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich * added to commonly used libc functions. If a buffer overrun is 521bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich * detected, the program is safely aborted. 522bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich * 523bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich * See 524bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich * http://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html for details. 525bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich */ 52616d1af167f8e36a9aa4a07ae77034ad519b00463Nick Kralevich#if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 && defined(__OPTIMIZE__) && __OPTIMIZE__ > 0 527890c8ed6ef773160cd6840a92e0d469fe530871fElliott Hughes#define __BIONIC_FORTIFY 1 5281aae9bd170883805f2e7975cd3dbd2502b083cc1Nick Kralevich#if _FORTIFY_SOURCE == 2 52978d6d9888c24c50f65d694dc8283afdcb58db84cNick Kralevich#define __bos(s) __builtin_object_size((s), 1) 5301aae9bd170883805f2e7975cd3dbd2502b083cc1Nick Kralevich#else 53178d6d9888c24c50f65d694dc8283afdcb58db84cNick Kralevich#define __bos(s) __builtin_object_size((s), 0) 5321aae9bd170883805f2e7975cd3dbd2502b083cc1Nick Kralevich#endif 533bd8e6749b78567af62ec126d7cc057386ebee25aNick Kralevich#define __bos0(s) __builtin_object_size((s), 0) 5341aae9bd170883805f2e7975cd3dbd2502b083cc1Nick Kralevich 5351aaa17802c92d99ae170245c2b2f15a6c27b133eNick Kralevich#if __GNUC_PREREQ(4,3) || __has_attribute(__artificial__) 5361aaa17802c92d99ae170245c2b2f15a6c27b133eNick Kralevich#define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) __attribute__((__artificial__)) 5371aaa17802c92d99ae170245c2b2f15a6c27b133eNick Kralevich#else 538884a3de60f442748a1d15c6a219f7058e03e38e2Nick Kralevich#define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline)) 53971a18dd435e96564539b5af71b8ea5093a2109a1Nick Kralevich#endif 5401aaa17802c92d99ae170245c2b2f15a6c27b133eNick Kralevich#endif 541890c8ed6ef773160cd6840a92e0d469fe530871fElliott Hughes#define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1) 54271a18dd435e96564539b5af71b8ea5093a2109a1Nick Kralevich 5432cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes/* Used to tag non-static symbols that are private and never exposed by the shared library. */ 5442cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __LIBC_HIDDEN__ __attribute__((visibility("hidden"))) 5452cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes 5462cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes/* Like __LIBC_HIDDEN__, but preserves binary compatibility for LP32. */ 5472cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#ifdef __LP64__ 5482cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __LIBC64_HIDDEN__ __LIBC_HIDDEN__ 5492cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#else 5502cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __LIBC64_HIDDEN__ __LIBC_ABI_PUBLIC__ 5512cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#endif 5522cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes 5532cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes/* Used to tag non-static symbols that are public and exposed by the shared library. */ 5542cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __LIBC_ABI_PUBLIC__ __attribute__((visibility ("default"))) 5552cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes 5562cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes/* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */ 5572cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes#define __RENAME(x) __asm__(#x) 5582cfb4e8e2e217ef0e4140dcbf9b3da809781158cElliott Hughes 5591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* !_SYS_CDEFS_H_ */ 560