Rob Pike | 69b74c3 | 2008-06-12 13:26:16 -0700 | [diff] [blame] | 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 _SVID_SOURCE 1 |
| 44 | #if !defined(__APPLE__) && !defined(__OpenBSD__) |
| 45 | # define _XOPEN_SOURCE 1000 |
| 46 | # define _XOPEN_SOURCE_EXTENDED 1 |
| 47 | #endif |
| 48 | #if defined(__FreeBSD__) |
| 49 | # include <sys/cdefs.h> |
| 50 | /* for strtoll */ |
| 51 | # undef __ISO_C_VISIBLE |
| 52 | # define __ISO_C_VISIBLE 1999 |
| 53 | # undef __LONG_LONG_SUPPORTED |
| 54 | # define __LONG_LONG_SUPPORTED |
| 55 | #endif |
| 56 | #define _LARGEFILE64_SOURCE 1 |
| 57 | #define _FILE_OFFSET_BITS 64 |
| 58 | |
| 59 | #include <inttypes.h> |
| 60 | |
| 61 | #include <unistd.h> |
| 62 | #include <string.h> |
| 63 | #include <stdlib.h> |
| 64 | #include <stdarg.h> |
| 65 | #include <fcntl.h> |
| 66 | #include <assert.h> |
| 67 | #include <setjmp.h> |
| 68 | #include <stddef.h> |
| 69 | #include <math.h> |
| 70 | #include <ctype.h> /* for tolower */ |
Russ Cox | 491a3ca5 | 2010-07-28 18:21:50 -0700 | [diff] [blame] | 71 | #include <signal.h> |
Lucio De Re | 340251e | 2011-06-14 14:14:11 -0400 | [diff] [blame] | 72 | #include <time.h> |
Rob Pike | 69b74c3 | 2008-06-12 13:26:16 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * OS-specific crap |
| 76 | */ |
| 77 | #define _NEEDUCHAR 1 |
| 78 | #define _NEEDUSHORT 1 |
| 79 | #define _NEEDUINT 1 |
| 80 | #define _NEEDULONG 1 |
| 81 | |
Joe Poirier | bf3f768 | 2011-02-08 15:42:52 -0500 | [diff] [blame] | 82 | #ifdef _WIN32 |
Hector Chu | cd9d72b | 2009-11-30 11:53:11 -0800 | [diff] [blame] | 83 | typedef jmp_buf sigjmp_buf; |
| 84 | #endif |
Rob Pike | 69b74c3 | 2008-06-12 13:26:16 -0700 | [diff] [blame] | 85 | typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; |
| 86 | |
| 87 | #if defined(__linux__) |
| 88 | # include <sys/types.h> |
| 89 | # if defined(__Linux26__) |
| 90 | # include <pthread.h> |
| 91 | # define PLAN9PORT_USING_PTHREADS 1 |
| 92 | # endif |
| 93 | # if defined(__USE_MISC) |
| 94 | # undef _NEEDUSHORT |
| 95 | # undef _NEEDUINT |
| 96 | # undef _NEEDULONG |
| 97 | # endif |
| 98 | #elif defined(__sun__) |
| 99 | # include <sys/types.h> |
| 100 | # include <pthread.h> |
| 101 | # define PLAN9PORT_USING_PTHREADS 1 |
| 102 | # undef _NEEDUSHORT |
| 103 | # undef _NEEDUINT |
| 104 | # undef _NEEDULONG |
| 105 | # define nil 0 /* no cast to void* */ |
| 106 | #elif defined(__FreeBSD__) |
| 107 | # include <sys/types.h> |
| 108 | # include <osreldate.h> |
| 109 | # if __FreeBSD_version >= 500000 |
| 110 | # define PLAN9PORT_USING_PTHREADS 1 |
| 111 | # include <pthread.h> |
| 112 | # endif |
| 113 | # if !defined(_POSIX_SOURCE) |
| 114 | # undef _NEEDUSHORT |
| 115 | # undef _NEEDUINT |
| 116 | # endif |
| 117 | #elif defined(__APPLE__) |
| 118 | # include <sys/types.h> |
| 119 | # include <pthread.h> |
| 120 | # define PLAN9PORT_USING_PTHREADS 1 |
| 121 | # if __GNUC__ < 4 |
| 122 | # undef _NEEDUSHORT |
| 123 | # undef _NEEDUINT |
| 124 | # endif |
| 125 | # undef _ANSI_SOURCE |
| 126 | # undef _POSIX_C_SOURCE |
| 127 | # undef _XOPEN_SOURCE |
| 128 | # if !defined(NSIG) |
| 129 | # define NSIG 32 |
| 130 | # endif |
| 131 | # define _NEEDLL 1 |
| 132 | #elif defined(__NetBSD__) |
| 133 | # include <sched.h> |
| 134 | # include <sys/types.h> |
| 135 | # undef _NEEDUSHORT |
| 136 | # undef _NEEDUINT |
| 137 | # undef _NEEDULONG |
| 138 | #elif defined(__OpenBSD__) |
| 139 | # include <sys/types.h> |
| 140 | # undef _NEEDUSHORT |
| 141 | # undef _NEEDUINT |
| 142 | # undef _NEEDULONG |
Joe Poirier | bf3f768 | 2011-02-08 15:42:52 -0500 | [diff] [blame] | 143 | #elif defined(_WIN32) |
Rob Pike | 69b74c3 | 2008-06-12 13:26:16 -0700 | [diff] [blame] | 144 | #else |
| 145 | /* No idea what system this is -- try some defaults */ |
| 146 | # include <pthread.h> |
| 147 | # define PLAN9PORT_USING_PTHREADS 1 |
| 148 | #endif |
| 149 | |
| 150 | #ifndef O_DIRECT |
| 151 | #define O_DIRECT 0 |
| 152 | #endif |
| 153 | |
| 154 | typedef signed char schar; |
| 155 | |
| 156 | #ifdef _NEEDUCHAR |
| 157 | typedef unsigned char uchar; |
| 158 | #endif |
| 159 | #ifdef _NEEDUSHORT |
| 160 | typedef unsigned short ushort; |
| 161 | #endif |
| 162 | #ifdef _NEEDUINT |
| 163 | typedef unsigned int uint; |
| 164 | #endif |
| 165 | #ifdef _NEEDULONG |
| 166 | typedef unsigned long ulong; |
| 167 | #endif |
| 168 | typedef unsigned long long uvlong; |
| 169 | typedef long long vlong; |
| 170 | |
| 171 | typedef uint64_t u64int; |
| 172 | typedef int64_t s64int; |
| 173 | typedef uint8_t u8int; |
| 174 | typedef int8_t s8int; |
| 175 | typedef uint16_t u16int; |
| 176 | typedef int16_t s16int; |
| 177 | typedef uintptr_t uintptr; |
| 178 | typedef intptr_t intptr; |
| 179 | typedef uint32_t u32int; |
| 180 | typedef int32_t s32int; |
| 181 | |
Russ Cox | 9aad9fe | 2008-08-03 17:25:15 -0700 | [diff] [blame] | 182 | typedef s8int int8; |
| 183 | typedef u8int uint8; |
| 184 | typedef s16int int16; |
| 185 | typedef u16int uint16; |
| 186 | typedef s32int int32; |
| 187 | typedef u32int uint32; |
| 188 | typedef s64int int64; |
| 189 | typedef u64int uint64; |
| 190 | |
| 191 | |
Rob Pike | 69b74c3 | 2008-06-12 13:26:16 -0700 | [diff] [blame] | 192 | #undef _NEEDUCHAR |
| 193 | #undef _NEEDUSHORT |
| 194 | #undef _NEEDUINT |
| 195 | #undef _NEEDULONG |
| 196 | |
Lucio De Re | eb3f208 | 2011-07-25 13:45:44 -0400 | [diff] [blame] | 197 | #define getcallerpc(x) __builtin_return_address(0) |
| 198 | |
Russ Cox | 491a3ca5 | 2010-07-28 18:21:50 -0700 | [diff] [blame] | 199 | #ifndef SIGBUS |
| 200 | #define SIGBUS SIGSEGV /* close enough */ |
| 201 | #endif |
| 202 | |
Rob Pike | 69b74c3 | 2008-06-12 13:26:16 -0700 | [diff] [blame] | 203 | /* |
| 204 | * Funny-named symbols to tip off 9l to autolink. |
| 205 | */ |
| 206 | #define AUTOLIB(x) static int __p9l_autolib_ ## x = 1; |
| 207 | #define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x = 1; |
| 208 | |
| 209 | /* |
| 210 | * Gcc is too smart for its own good. |
| 211 | */ |
| 212 | #if defined(__GNUC__) |
| 213 | # undef strcmp /* causes way too many warnings */ |
Joe Poirier | bf3f768 | 2011-02-08 15:42:52 -0500 | [diff] [blame] | 214 | # if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__) && !defined(_WIN32)) |
Rob Pike | 69b74c3 | 2008-06-12 13:26:16 -0700 | [diff] [blame] | 215 | # undef AUTOLIB |
| 216 | # define AUTOLIB(x) int __p9l_autolib_ ## x __attribute__ ((weak)); |
| 217 | # undef AUTOFRAMEWORK |
| 218 | # define AUTOFRAMEWORK(x) int __p9l_autoframework_ ## x __attribute__ ((weak)); |
| 219 | # else |
| 220 | # undef AUTOLIB |
| 221 | # define AUTOLIB(x) static int __p9l_autolib_ ## x __attribute__ ((unused)); |
| 222 | # undef AUTOFRAMEWORK |
| 223 | # define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x __attribute__ ((unused)); |
| 224 | # endif |
| 225 | #endif |
| 226 | |
| 227 | #if defined(__cplusplus) |
| 228 | } |
| 229 | #endif |
| 230 | #endif |