summaryrefslogtreecommitdiff
path: root/lib/common/BoxPlatform.h
blob: 3b75f992b9ea7665beb8ba56a993c014d0b00088 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// --------------------------------------------------------------------------
//
// File
//		Name:    BoxPlatform.h
//		Purpose: Specifies what each platform supports in more detail, and includes
//				 extra files to get basic support for types.
//		Created: 2003/09/06
//
// --------------------------------------------------------------------------

#ifndef BOXPLATFORM__H
#define BOXPLATFORM__H

#define DIRECTORY_SEPARATOR			"/"
#define DIRECTORY_SEPARATOR_ASCHAR	'/'

#define PLATFORM_DEV_NULL			"/dev/null"


// Other flags which might be useful...
//
//	#define PLATFORM_BERKELEY_DB_NOT_SUPPORTED
//    -- dbopen etc not on this platform
//
//  #define PLATFORM_REGEX_NOT_SUPPORTED
//	  -- regex support not available on this platform


#ifdef PLATFORM_OPENBSD

	#include <sys/types.h>

	#define PLATFORM_HAVE_setproctitle

	#define PLATFORM_STATIC_TEMP_DIRECTORY_NAME	"/tmp"
	
	#define PLATFORM_HAVE_getpeereid

	#define PLATFORM_RANDOM_DEVICE	"/dev/arandom"

#endif // PLATFORM_OPENBSD

#ifdef PLATFORM_NETBSD

	#include <sys/types.h>

	#define PLATFORM_HAVE_setproctitle

	#define PLATFORM_NO_BUILT_IN_SWAP64

	#define PLATFORM_STATIC_TEMP_DIRECTORY_NAME	"/tmp"
	
	#define PLATFORM_KQUEUE_NOT_SUPPORTED

	#define PLATFORM_RANDOM_DEVICE	"/dev/urandom"

#endif

#ifdef PLATFORM_FREEBSD

	#include <sys/types.h>
	#include <netinet/in.h>

	#define PLATFORM_HAVE_setproctitle

	#define PLATFORM_NO_BUILT_IN_SWAP64

	#define PLATFORM_STATIC_TEMP_DIRECTORY_NAME	"/tmp"

	#define PLATFORM_HAVE_getpeereid

	#define PLATFORM_RANDOM_DEVICE  "/dev/urandom"

#endif // PLATFORM_FREEBSD

#ifdef PLATFORM_DARWIN

	#include <sys/types.h>
	#include <netdb.h>
	
	// types 'missing'
	#ifndef _SOCKLEN_T
		typedef int socklen_t;
	#endif
	typedef u_int8_t uint8_t;
	typedef signed char int8_t;
	typedef u_int64_t uint64_t;
	typedef u_int32_t uint32_t;
	typedef u_int16_t uint16_t;
	
	// poll() emulator on Darwin misses this declaration
	#define INFTIM		-1

	#define PLATFORM_STATIC_TEMP_DIRECTORY_NAME	"/tmp"
	
	#define PLATFORM_LCHOWN_NOT_SUPPORTED
	
	#define PLATFORM_READLINE_NOT_SUPPORTED

	#define PLATFORM_RANDOM_DEVICE	"/dev/random"
	
#endif // PLATFORM_DARWIN

#ifdef PLATFORM_LINUX
	
	#include <sys/types.h>

	// for ntohl etc...
	#include <netinet/in.h>

	// types 'missing'
	typedef u_int8_t uint8_t;
	typedef signed char int8_t;
	typedef u_int32_t uint32_t;
	typedef u_int16_t uint16_t;
	typedef u_int64_t uint64_t;

	// not defined in Linux, a BSD thing
	#define INFTIM -1

	#define LLONG_MAX    9223372036854775807LL
	#define LLONG_MIN    (-LLONG_MAX - 1LL)

	#define PLATFORM_STATIC_TEMP_DIRECTORY_NAME	"/tmp"

	#define PLATFORM_HAVE_getsockopt_SO_PEERCRED

	// load in installation specific linux configuration
	#include "../../local/_linux_platform.h"

	#define PLATFORM_KQUEUE_NOT_SUPPORTED
	#define PLATFORM_dirent_BROKEN_d_type
	#define PLATFORM_stat_SHORT_mtime
	#define PLATFORM_stat_NO_st_flags
	#define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
	#define PLATFORM_open_USE_flock
	#define PLATFORM_sockaddr_NO_len

	#define PLATFORM_RANDOM_DEVICE	"/dev/urandom"

	// If large file support is on, can't do the intercepts in the test/raidfile
	#if _FILE_OFFSET_BITS == 64
		#define PLATFORM_CLIB_FNS_INTERCEPTION_IMPOSSIBLE
	#endif

#endif // PLATFORM_LINUX

#ifdef PLATFORM_SUNOS

	#include <sys/types.h>

	// for ntohl etc...
	#include <netinet/in.h>

	// types 'missing'
	typedef uint8_t u_int8_t;
//	typedef signed char int8_t;
	typedef uint32_t u_int32_t;
	typedef uint16_t u_int16_t;
	typedef uint64_t u_int64_t;

	// not defined in Solaris, a BSD thing
	#define INFTIM -1

	//#define LLONG_MAX    9223372036854775807LL
	//#define LLONG_MIN    (-LLONG_MAX - 1LL)

	#define PLATFORM_STATIC_TEMP_DIRECTORY_NAME	"/tmp"

	#define PLATFORM_BERKELEY_DB_NOT_SUPPORTED
	#define PLATFORM_KQUEUE_NOT_SUPPORTED       // This may be in Solaris 10
	#define PLATFORM_dirent_BROKEN_d_type       // Well, no d_type at all actually
	#define PLATFORM_stat_SHORT_mtime
	#define PLATFORM_stat_NO_st_flags
	#define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
	#define PLATFORM_open_USE_fcntl
	#define PLATFORM_sockaddr_NO_len

	#define PLATFORM_RANDOM_DEVICE	"/dev/urandom"

#endif // PLATFORM_SUNOS

#ifdef PLATFORM_CYGWIN

	#define PLATFORM_BERKELEY_DB_NOT_SUPPORTED

	#define PLATFORM_KQUEUE_NOT_SUPPORTED
	#define PLATFORM_dirent_BROKEN_d_type
	#define PLATFORM_stat_SHORT_mtime
	#define PLATFORM_stat_NO_st_flags
	#define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
	#define PLATFORM_open_USE_flock
	#define PLATFORM_sockaddr_NO_len
	#define PLATFORM_NO_BUILT_IN_SWAP64

	#define PLATFORM_STATIC_TEMP_DIRECTORY_NAME	"/tmp"

	#define PLATFORM_READLINE_NOT_SUPPORTED

	#define LLONG_MAX    9223372036854775807LL
	#define LLONG_MIN    (-LLONG_MAX - 1LL)

	#define INFTIM -1

	// File listing canonical interesting mount points.  
	#define MNTTAB          _PATH_MNTTAB   

	// File listing currently active mount points.  
	#define MOUNTED         _PATH_MOUNTED   

	#define __need_FILE

	// Extra includes
	#include <stdint.h>
	#include <stdlib.h>
	#include <netinet/in.h>
	#include <sys/socket.h>
	#include <sys/stat.h>
	#include <sys/types.h>
	#include <dirent.h>
	#include <stdio.h>
	#include <paths.h>

	// No easy random entropy source
	#define PLATFORM_RANDOM_DEVICE_NONE

#endif // PLATFORM_CYGWIN


// Check the processor type
#ifdef PLATFORM_SPARC
	#define PLATFORM_ALIGN_INT
#endif

#ifdef PLATFORM_ARM
	#define PLATFORM_ALIGN_INT
#endif


// Find out if credentials on UNIX sockets can be obtained
#ifndef PLATFORM_HAVE_getpeereid
	#ifndef PLATFORM_HAVE_getsockopt_SO_PEERCRED
		#define PLATFORM_CANNOT_FIND_PEER_UID_OF_UNIX_SOCKET
	#endif
#endif


// Compiler issues
#ifdef __GNUC__

	#ifdef PLATFORM_GCC3

		// GCC v3 doesn't like pragmas in #defines
		#define STRUCTURE_PATCKING_FOR_WIRE_USE_HEADERS
		
		// But fortunately, the STL allocations are much better behaved.
	
	#else
	
		// Force STL to use malloc() for memory allocation
		// -- slower, but doesn't gradually use more and more memory
		// HOWEVER -- this 'fix' is broken on some platforms. Lots of fun!
		#ifndef PLATFORM_STL_USE_MALLOC_BROKEN
			#define __USE_MALLOC
		#endif
		
		// set packing to one bytes (can't use push/pop on gcc)
		#define BEGIN_STRUCTURE_PACKING_FOR_WIRE	#pragma pack(1)
		
		// Use default packing
		#define END_STRUCTURE_PACKING_FOR_WIRE		#pragma pack()

	#endif

#else
	compiler not supported!
#endif


#endif // BOXPLATFORM__H