blob: e604d3afc223b466ee9ac82e3d9612b7c04e8dc4 [file] [log] [blame]
rsc8ad51792004-03-25 23:03:57 +00001#ifndef _U_H_
2#define _U_H_ 1
3#if defined(__cplusplus)
4extern "C" {
5#endif
6
rsc39b30542004-12-25 22:00:27 +00007#define __BSD_VISIBLE 1 /* FreeBSD 5.x */
rscd08f4062005-07-27 13:06:50 +00008#if defined(__sun__)
9# define __EXTENSIONS__ 1 /* SunOS */
Brian L. Suartf12ab342008-07-20 04:51:03 -040010# if defined(__SunOS5_6__) || defined(__SunOS5_7__) || defined(__SunOS5_8__) || defined(__SunOS5_9__) || defined(__SunOS5_10__)
rscd08f4062005-07-27 13:06:50 +000011 /* NOT USING #define __MAKECONTEXT_V2_SOURCE 1 / * SunOS */
12# else
Brian L. Suartf12ab342008-07-20 04:51:03 -040013 /* What's left? */
rscd08f4062005-07-27 13:06:50 +000014# define __MAKECONTEXT_V2_SOURCE 1
15# endif
16#endif
rsc8ad51792004-03-25 23:03:57 +000017#define _BSD_SOURCE 1
rsc5ba33c02005-03-28 15:58:14 +000018#define _NETBSD_SOURCE 1 /* NetBSD */
rsc8ad51792004-03-25 23:03:57 +000019#define _SVID_SOURCE 1
rsc20e8b902005-07-20 23:40:47 +000020#if !defined(__APPLE__) && !defined(__OpenBSD__)
rsca8ec4912005-07-13 21:34:11 +000021# define _XOPEN_SOURCE 1000
22# define _XOPEN_SOURCE_EXTENDED 1
23#endif
rsc838874f2006-04-04 11:58:52 +000024#if defined(__FreeBSD__)
25# include <sys/cdefs.h>
26 /* for strtoll */
27# undef __ISO_C_VISIBLE
28# define __ISO_C_VISIBLE 1999
29# undef __LONG_LONG_SUPPORTED
30# define __LONG_LONG_SUPPORTED
31#endif
rsc8ad51792004-03-25 23:03:57 +000032#define _LARGEFILE64_SOURCE 1
33#define _FILE_OFFSET_BITS 64
rsc8ad51792004-03-25 23:03:57 +000034
rsc20e8b902005-07-20 23:40:47 +000035#include <inttypes.h>
rsc76e02e92005-07-19 17:40:50 +000036
rsc8ad51792004-03-25 23:03:57 +000037#include <unistd.h>
38#include <string.h>
39#include <stdlib.h>
40#include <stdarg.h>
41#include <fcntl.h>
42#include <assert.h>
43#include <setjmp.h>
44#include <stddef.h>
rsc8ad51792004-03-25 23:03:57 +000045#include <math.h>
rscc8af1ab2004-04-19 18:13:05 +000046#include <ctype.h> /* for tolower */
rsc8ad51792004-03-25 23:03:57 +000047
48/*
49 * OS-specific crap
50 */
51#define _NEEDUCHAR 1
52#define _NEEDUSHORT 1
53#define _NEEDUINT 1
54#define _NEEDULONG 1
55
56typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)];
57
58#if defined(__linux__)
59# include <sys/types.h>
rscaaa502d2005-03-15 16:12:51 +000060# if defined(__Linux26__)
61# include <pthread.h>
62# define PLAN9PORT_USING_PTHREADS 1
63# endif
rsc8ad51792004-03-25 23:03:57 +000064# if defined(__USE_MISC)
65# undef _NEEDUSHORT
66# undef _NEEDUINT
67# undef _NEEDULONG
rscc6687d42004-09-21 01:11:28 +000068# endif
rsc39b30542004-12-25 22:00:27 +000069#elif defined(__sun__)
rsc8ad51792004-03-25 23:03:57 +000070# include <sys/types.h>
rscaaa502d2005-03-15 16:12:51 +000071# include <pthread.h>
72# define PLAN9PORT_USING_PTHREADS 1
rsc8ad51792004-03-25 23:03:57 +000073# undef _NEEDUSHORT
74# undef _NEEDUINT
75# undef _NEEDULONG
rscaaa502d2005-03-15 16:12:51 +000076# define nil 0 /* no cast to void* */
rsc39b30542004-12-25 22:00:27 +000077#elif defined(__FreeBSD__)
rsc8ad51792004-03-25 23:03:57 +000078# include <sys/types.h>
wkj7ee1ac92004-12-29 01:32:42 +000079# include <osreldate.h>
rscaaa502d2005-03-15 16:12:51 +000080# if __FreeBSD_version >= 500000
81# define PLAN9PORT_USING_PTHREADS 1
82# include <pthread.h>
83# endif
rsc8ad51792004-03-25 23:03:57 +000084# if !defined(_POSIX_SOURCE)
85# undef _NEEDUSHORT
86# undef _NEEDUINT
87# endif
rsc39b30542004-12-25 22:00:27 +000088#elif defined(__APPLE__)
rsc8ad51792004-03-25 23:03:57 +000089# include <sys/types.h>
rscaaa502d2005-03-15 16:12:51 +000090# include <pthread.h>
91# define PLAN9PORT_USING_PTHREADS 1
rscbc7da022005-05-07 22:41:59 +000092# if __GNUC__ < 4
93# undef _NEEDUSHORT
94# undef _NEEDUINT
95# endif
96# undef _ANSI_SOURCE
97# undef _POSIX_C_SOURCE
rsca8ec4912005-07-13 21:34:11 +000098# undef _XOPEN_SOURCE
rscbc7da022005-05-07 22:41:59 +000099# if !defined(NSIG)
100# define NSIG 32
101# endif
rsc8ad51792004-03-25 23:03:57 +0000102# define _NEEDLL 1
rsc5ba33c02005-03-28 15:58:14 +0000103#elif defined(__NetBSD__)
104# include <sched.h>
105# include <sys/types.h>
106# undef _NEEDUSHORT
107# undef _NEEDUINT
108# undef _NEEDULONG
rsc52e61642005-05-01 18:40:01 +0000109#elif defined(__OpenBSD__)
rscceb21b82005-07-19 11:36:27 +0000110# include <sys/types.h>
rsc52e61642005-05-01 18:40:01 +0000111# undef _NEEDUSHORT
112# undef _NEEDUINT
113# undef _NEEDULONG
rsc39b30542004-12-25 22:00:27 +0000114#else
115 /* No idea what system this is -- try some defaults */
rscaaa502d2005-03-15 16:12:51 +0000116# include <pthread.h>
rsc39b30542004-12-25 22:00:27 +0000117# define PLAN9PORT_USING_PTHREADS 1
rsc8ad51792004-03-25 23:03:57 +0000118#endif
119
rsc39b30542004-12-25 22:00:27 +0000120#ifndef O_DIRECT
121#define O_DIRECT 0
122#endif
123
rsc8ad51792004-03-25 23:03:57 +0000124typedef signed char schar;
rsc785a7362004-04-19 05:52:43 +0000125
rsc8ad51792004-03-25 23:03:57 +0000126#ifdef _NEEDUCHAR
127 typedef unsigned char uchar;
128#endif
129#ifdef _NEEDUSHORT
130 typedef unsigned short ushort;
131#endif
132#ifdef _NEEDUINT
133 typedef unsigned int uint;
134#endif
135#ifdef _NEEDULONG
136 typedef unsigned long ulong;
137#endif
138typedef unsigned long long uvlong;
139typedef long long vlong;
rsc76e02e92005-07-19 17:40:50 +0000140
141typedef uint64_t u64int;
142typedef int64_t s64int;
143typedef uint8_t u8int;
144typedef int8_t s8int;
145typedef uint16_t u16int;
146typedef int16_t s16int;
147typedef uintptr_t uintptr;
Russ Cox949b59c2008-03-06 15:13:42 -0500148typedef intptr_t intptr;
rsc76e02e92005-07-19 17:40:50 +0000149typedef uint32_t u32int;
150typedef int32_t s32int;
rsc8ad51792004-03-25 23:03:57 +0000151
152#undef _NEEDUCHAR
153#undef _NEEDUSHORT
154#undef _NEEDUINT
155#undef _NEEDULONG
156
rsc1a0954a2005-01-04 21:18:08 +0000157/*
158 * Funny-named symbols to tip off 9l to autolink.
159 */
160#define AUTOLIB(x) static int __p9l_autolib_ ## x = 1;
rsc58c52402005-10-29 17:36:49 +0000161#define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x = 1;
rsc1a0954a2005-01-04 21:18:08 +0000162
rsc9b4de092005-01-06 23:06:03 +0000163/*
rscbc7da022005-05-07 22:41:59 +0000164 * Gcc is too smart for its own good.
rsc9b4de092005-01-06 23:06:03 +0000165 */
rscbc7da022005-05-07 22:41:59 +0000166#if defined(__GNUC__)
rscc54b8b62006-01-27 05:51:54 +0000167# undef strcmp /* causes way too many warnings */
rscbc7da022005-05-07 22:41:59 +0000168# if __GNUC__ >= 4 || (__GNUC__==3 && !defined(__APPLE_CC__))
rsc9b4de092005-01-06 23:06:03 +0000169# undef AUTOLIB
170# define AUTOLIB(x) int __p9l_autolib_ ## x __attribute__ ((weak));
rsc58c52402005-10-29 17:36:49 +0000171# undef AUTOFRAMEWORK
172# define AUTOFRAMEWORK(x) int __p9l_autoframework_ ## x __attribute__ ((weak));
wkj9d7a2e62005-05-02 18:08:03 +0000173# else
174# undef AUTOLIB
175# define AUTOLIB(x) static int __p9l_autolib_ ## x __attribute__ ((unused));
rsc58c52402005-10-29 17:36:49 +0000176# undef AUTOFRAMEWORK
177# define AUTOFRAMEWORK(x) static int __p9l_autoframework_ ## x __attribute__ ((unused));
rsc9b4de092005-01-06 23:06:03 +0000178# endif
179#endif
180
rsc8ad51792004-03-25 23:03:57 +0000181#if defined(__cplusplus)
182}
183#endif
184#endif