github.com/hongwozai/go-src-1.4.3@v0.0.0-20191127132709-dc3fce3dbccb/include/u.h (about) 1 /* 2 Plan 9 from User Space include/u.h 3 http://code.swtch.com/plan9port/src/tip/include/u.h 4 5 Copyright 2001-2007 Russ Cox. All Rights Reserved. 6 7 Permission is hereby granted, free of charge, to any person obtaining a copy 8 of this software and associated documentation files (the "Software"), to deal 9 in the Software without restriction, including without limitation the rights 10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 copies of the Software, and to permit persons to whom the Software is 12 furnished to do so, subject to the following conditions: 13 14 The above copyright notice and this permission notice shall be included in 15 all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 THE SOFTWARE. 24 */ 25 26 #ifndef _U_H_ 27 #define _U_H_ 1 28 #if defined(__cplusplus) 29 extern "C" { 30 #endif 31 32 #define __BSD_VISIBLE 1 /* FreeBSD 5.x */ 33 #if defined(__sun__) 34 # define __EXTENSIONS__ 1 /* SunOS */ 35 # if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__) 36 /* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */ 37 # else 38 # define __MAKECONTEXT_V2_SOURCE 1 39 # endif 40 #endif 41 #define _BSD_SOURCE 1 42 #define _NETBSD_SOURCE 1 /* NetBSD */ 43 #define _DEFAULT_SOURCE 1 /* glibc > 2.19 */ 44 #define _SVID_SOURCE 1 45 #if !defined(__APPLE__) && !defined(__OpenBSD__) 46 # define _XOPEN_SOURCE 1000 47 # define _XOPEN_SOURCE_EXTENDED 1 48 #endif 49 #if defined(__FreeBSD__) 50 # include <sys/cdefs.h> 51 /* for strtoll */ 52 # undef __ISO_C_VISIBLE 53 # define __ISO_C_VISIBLE 1999 54 # undef __LONG_LONG_SUPPORTED 55 # define __LONG_LONG_SUPPORTED 56 #endif 57 #define _LARGEFILE64_SOURCE 1 58 #define _FILE_OFFSET_BITS 64 59 60 #include <inttypes.h> 61 62 #include <unistd.h> 63 #include <string.h> 64 #include <stdlib.h> 65 #include <stdarg.h> 66 #include <fcntl.h> 67 #include <assert.h> 68 #include <setjmp.h> 69 #include <stddef.h> 70 #include <math.h> 71 #include <ctype.h> /* for tolower */ 72 #include <signal.h> 73 #include <time.h> 74 75 /* 76 * OS-specific crap 77 */ 78 #define _NEEDUCHAR 1 79 #define _NEEDUSHORT 1 80 #define _NEEDUINT 1 81 #define _NEEDULONG 1 82 83 #ifdef _WIN32 84 typedef jmp_buf sigjmp_buf; 85 #endif 86 typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; 87 88 #if defined(__linux__) 89 # include <sys/types.h> 90 # if defined(__Linux26__) 91 # include <pthread.h> 92 # define PLAN9PORT_USING_PTHREADS 1 93 # endif 94 # if defined(__USE_MISC) 95 # undef _NEEDUSHORT 96 # undef _NEEDUINT 97 # undef _NEEDULONG 98 # endif 99 #elif defined(__sun__) 100 # include <sys/types.h> 101 # include <pthread.h> 102 # define PLAN9PORT_USING_PTHREADS 1 103 # undef _NEEDUSHORT 104 # undef _NEEDUINT 105 # undef _NEEDULONG 106 # define nil 0 /* no cast to void* */ 107 #elif defined(__FreeBSD__) 108 # include <sys/types.h> 109 # include <osreldate.h> 110 # if __FreeBSD_version >= 500000 111 # define PLAN9PORT_USING_PTHREADS 1 112 # include <pthread.h> 113 # endif 114 # if !defined(_POSIX_SOURCE) 115 # undef _NEEDUSHORT 116 # undef _NEEDUINT 117 # endif 118 #elif defined(__APPLE__) 119 # include <sys/types.h> 120 # include <pthread.h> 121 # define PLAN9PORT_USING_PTHREADS 1 122 # if __GNUC__ < 4 123 # undef _NEEDUSHORT 124 # undef _NEEDUINT 125 # endif 126 # undef _ANSI_SOURCE 127 # undef _POSIX_C_SOURCE 128 # undef _XOPEN_SOURCE 129 # if !defined(NSIG) 130 # define NSIG 32 131 # endif 132 # define _NEEDLL 1 133 #elif defined(__NetBSD__) 134 # include <sched.h> 135 # include <sys/types.h> 136 # undef _NEEDUSHORT 137 # undef _NEEDUINT 138 # undef _NEEDULONG 139 #elif defined(__OpenBSD__) 140 # include <sys/types.h> 141 # undef _NEEDUSHORT 142 # undef _NEEDUINT 143 # undef _NEEDULONG 144 #elif defined(_WIN32) 145 #else 146 /* No idea what system this is -- try some defaults */ 147 # include <pthread.h> 148 # define PLAN9PORT_USING_PTHREADS 1 149 #endif 150 151 #ifndef O_DIRECT 152 #define O_DIRECT 0 153 #endif 154 155 typedef signed char schar; 156 157 #ifdef _NEEDUCHAR 158 typedef unsigned char uchar; 159 #endif 160 #ifdef _NEEDUSHORT 161 typedef unsigned short ushort; 162 #endif 163 #ifdef _NEEDUINT 164 typedef unsigned int uint; 165 #endif 166 #ifdef _NEEDULONG 167 typedef unsigned long ulong; 168 #endif 169 typedef unsigned long long uvlong; 170 typedef long long vlong; 171 172 typedef uint64_t u64int; 173 typedef int64_t s64int; 174 typedef uint8_t u8int; 175 typedef int8_t s8int; 176 typedef uint16_t u16int; 177 typedef int16_t s16int; 178 typedef uintptr_t uintptr; 179 typedef intptr_t intptr; 180 typedef uint32_t u32int; 181 typedef int32_t s32int; 182 183 typedef s8int int8; 184 typedef u8int uint8; 185 typedef s16int int16; 186 typedef u16int uint16; 187 typedef s32int int32; 188 typedef u32int uint32; 189 typedef s64int int64; 190 typedef u64int uint64; 191 192 typedef float float32; 193 typedef double float64; 194 195 #undef _NEEDUCHAR 196 #undef _NEEDUSHORT 197 #undef _NEEDUINT 198 #undef _NEEDULONG 199 200 #define getcallerpc(x) __builtin_return_address(0) 201 202 #ifndef SIGBUS 203 #define SIGBUS SIGSEGV /* close enough */ 204 #endif 205 206 /* 207 * Funny-named symbols to tip off 9l to autolink. 208 */ 209 #define AUTOLIB(x) static int __p9l_autolib_ ## x = 1; 210 #define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x = 1; 211 212 /* 213 * Gcc is too smart for its own good. 214 */ 215 #if defined(__GNUC__) 216 # undef strcmp /* causes way too many warnings */ 217 # if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__) && !defined(_WIN32)) 218 # undef AUTOLIB 219 # define AUTOLIB(x) int __p9l_autolib_ ## x __attribute__ ((weak)); 220 # undef AUTOFRAMEWORK 221 # define AUTOFRAMEWORK(x) int __p9l_autoframework_ ## x __attribute__ ((weak)); 222 # else 223 # undef AUTOLIB 224 # define AUTOLIB(x) static int __p9l_autolib_ ## x __attribute__ ((unused)); 225 # undef AUTOFRAMEWORK 226 # define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x __attribute__ ((unused)); 227 # endif 228 #endif 229 230 #if defined(__cplusplus) 231 } 232 #endif 233 #endif