blob: 44bfcd63b23120d7844fcfed49d6fdb2d2042b09 [file] [log] [blame]
Rob Pike69b74c32008-06-12 13:26:16 -07001/*
2Plan 9 from User Space include/u.h
3http://code.swtch.com/plan9port/src/tip/include/u.h
4
5Copyright 2001-2007 Russ Cox. All Rights Reserved.
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in
15all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23THE SOFTWARE.
24*/
25
26#ifndef _U_H_
27#define _U_H_ 1
28#if defined(__cplusplus)
29extern "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 Cox491a3ca52010-07-28 18:21:50 -070071#include <signal.h>
Lucio De Re340251e2011-06-14 14:14:11 -040072#include <time.h>
Rob Pike69b74c32008-06-12 13:26:16 -070073
74/*
75 * OS-specific crap
76 */
77#define _NEEDUCHAR 1
78#define _NEEDUSHORT 1
79#define _NEEDUINT 1
80#define _NEEDULONG 1
81
Joe Poirierbf3f7682011-02-08 15:42:52 -050082#ifdef _WIN32
Hector Chucd9d72b2009-11-30 11:53:11 -080083typedef jmp_buf sigjmp_buf;
84#endif
Rob Pike69b74c32008-06-12 13:26:16 -070085typedef 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 Poirierbf3f7682011-02-08 15:42:52 -0500143#elif defined(_WIN32)
Rob Pike69b74c32008-06-12 13:26:16 -0700144#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
154typedef 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
168typedef unsigned long long uvlong;
169typedef long long vlong;
170
171typedef uint64_t u64int;
172typedef int64_t s64int;
173typedef uint8_t u8int;
174typedef int8_t s8int;
175typedef uint16_t u16int;
176typedef int16_t s16int;
177typedef uintptr_t uintptr;
178typedef intptr_t intptr;
179typedef uint32_t u32int;
180typedef int32_t s32int;
181
Russ Cox9aad9fe2008-08-03 17:25:15 -0700182typedef s8int int8;
183typedef u8int uint8;
184typedef s16int int16;
185typedef u16int uint16;
186typedef s32int int32;
187typedef u32int uint32;
188typedef s64int int64;
189typedef u64int uint64;
190
191
Rob Pike69b74c32008-06-12 13:26:16 -0700192#undef _NEEDUCHAR
193#undef _NEEDUSHORT
194#undef _NEEDUINT
195#undef _NEEDULONG
196
Lucio De Reeb3f2082011-07-25 13:45:44 -0400197#define getcallerpc(x) __builtin_return_address(0)
198
Russ Cox491a3ca52010-07-28 18:21:50 -0700199#ifndef SIGBUS
200#define SIGBUS SIGSEGV /* close enough */
201#endif
202
Rob Pike69b74c32008-06-12 13:26:16 -0700203/*
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 Poirierbf3f7682011-02-08 15:42:52 -0500214# if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__) && !defined(_WIN32))
Rob Pike69b74c32008-06-12 13:26:16 -0700215# 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