HaikuBuildCompatibility.h revision e883b3c9
1#ifndef HAIKU_BUILD_COMPATIBILITY_H
2#define HAIKU_BUILD_COMPATIBILITY_H
3
4/*!
5	This header is automatically included in all Haiku applications
6	that are built for BeOS or a Haiku host (which might not be compatible
7	with the current Haiku source anymore).
8	It will make BeOS/Haiku a bit more Haiku compatible, and slightly more
9	POSIX compatible, too. It is supposed to keep the BeOS compatibility
10	kludges in our source files at a minimum.
11*/
12
13#ifdef HAIKU_HOST_PLATFORM_DANO
14#	include <be_setup.h>
15#	include <be_errors.h>
16#	define _ERRORS_H
17		// this is what Haiku/BeOS is using
18#endif
19
20#ifdef HAIKU_TARGET_PLATFORM_LIBBE_TEST
21#	define _BE_ERRNO_H_
22		// this is what Dano/Zeta is using
23#	include <Errors.h>
24#endif
25
26#include <sys/stat.h>
27#include <sys/types.h>
28#include <SupportDefs.h>
29#include <TypeConstants.h>
30
31#include <string.h>
32
33// no addr_t under standard BeOS
34#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
35	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
36	typedef unsigned long haiku_build_addr_t;
37#	define addr_t haiku_build_addr_t
38#endif
39
40#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
41	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
42
43struct sockaddr_storage {
44	uint8	ss_len;			/* total length */
45	uint8	ss_family;		/* address family */
46	uint8	__ss_pad1[6];	/* align to quad */
47	uint64	__ss_pad2;		/* force alignment to 64 bit */
48	uint8	__ss_pad3[112];	/* pad to a total of 128 bytes */
49};
50
51typedef int socklen_t;
52
53#endif	// !HAIKU_HOST_PLATFORM_HAIKU
54
55#ifndef DEFFILEMODE
56#	define	DEFFILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
57#endif
58
59#ifndef FS_WRITE_FSINFO_NAME
60#	define	FS_WRITE_FSINFO_NAME	0x0001
61#endif
62
63#ifndef B_CURRENT_TEAM
64#	define B_CURRENT_TEAM	0
65#endif
66
67#ifndef SYMLOOP_MAX
68#	define SYMLOOP_MAX	(16)
69#endif
70
71#ifndef B_FIRST_REAL_TIME_PRIORITY
72#	define B_FIRST_REAL_TIME_PRIORITY B_REAL_TIME_DISPLAY_PRIORITY
73#endif
74
75#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
76	&& !defined(B_SPINLOCK_INITIALIZER)
77#	define B_SPINLOCK_INITIALIZER 0
78#endif
79
80#if defined(__GNUC__) && !defined(_PRINTFLIKE)
81#	define _PRINTFLIKE(_format_, _args_) \
82		__attribute__((format(__printf__, _format_, _args_)))
83#endif
84
85#if 0
86// NOTE: This is probably only needed on platforms which don't use ELF
87// as binary format. So could probably be removed completely.
88#if defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
89	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
90// BeOS version of BeBuild.h defines this
91#	define _IMPEXP_ROOT			__declspec(dllimport)
92#	define _IMPEXP_BE			__declspec(dllimport)
93#	define _IMPEXP_MEDIA		__declspec(dllimport)
94#	define _IMPEXP_TRACKER		__declspec(dllimport)
95#	define _IMPEXP_TRANSLATION	__declspec(dllimport)
96#	define _IMPEXP_DEVICE		__declspec(dllimport)
97#	define _IMPEXP_NET			__declspec(dllimport)
98#endif
99#endif
100
101#if defined(__cplusplus) && !defined(HAIKU_HOST_PLATFORM_HAIKU)
102class BBuffer;
103class BBufferConsumer;
104class BBufferGroup;
105class BContinuousParameter;
106class BControllable;
107class BFileInterface;
108class BMimeType;
109class BParameterWeb;
110class BRegion;
111class BTextView;
112class BTranslator;
113class BTimeSource;
114struct entry_ref;
115struct media_node;
116#endif
117
118#ifdef __cplusplus
119extern "C" {
120#endif
121
122extern void		atomic_set(int32* value, int32 newValue);
123extern int32	atomic_get_and_set(int32* value, int32 newValue);
124extern int32	atomic_test_and_set(int32 *value, int32 newValue,
125					int32 testAgainst);
126extern int32	atomic_get(int32 *value);
127extern void		atomic_set64(int64* value, int64 newValue);
128extern int64	atomic_get_and_set64(int64* value, int64 newValue);
129extern int64	atomic_test_and_set64(int64 *value, int64 newValue,
130					int64 testAgainst);
131extern int64	atomic_get64(int64 *value);
132extern int64	atomic_add64(int64 *value, int64 addValue);
133extern int64	atomic_and64(int64 *value, int64 andValue);
134extern int64	atomic_or64(int64 *value, int64 orValue);
135
136extern size_t	strnlen(const char *string, size_t count);
137
138extern size_t	strlcat(char *dest, const char *source, size_t length);
139extern size_t   strlcpy(char *dest, const char *source, size_t length);
140
141extern char		*strcasestr(const char *string, const char *searchString);
142
143extern float	roundf(float value);
144
145#ifdef __cplusplus
146}
147#endif
148
149// These are R1-specific extensions
150#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
151	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
152#	define B_TRANSLATION_MAKE_VERSION(major, minor, revision) \
153		((major << 8) | ((minor << 4) & 0xf0) | (revision & 0x0f))
154#	define B_TRANSLATION_MAJOR_VERSION(v) (v >> 8)
155#	define B_TRANSLATION_MINOR_VERSION(v) ((v >> 4) & 0xf)
156#	define B_TRANSLATION_REVISION_VERSION(v) (v & 0xf)
157#	ifndef USING_HAIKU_TYPE_CONSTANTS_H
158#		define B_LARGE_ICON_TYPE		'ICON'
159#		define B_MINI_ICON_TYPE			'MICN'
160#		define B_VECTOR_ICON_TYPE		'VICN'
161#		define B_BITMAP_NO_SERVER_LINK	0
162#		define B_BITMAP_SCALE_BILINEAR	0
163#	endif
164#endif	// HAIKU_TARGET_PLATFORM_LIBBE_TEST
165
166#if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE)
167#	define B_REDO						'REDO'
168#	define B_BAD_DATA					(B_NOT_ALLOWED + 1)
169#	define B_DOCUMENT_BACKGROUND_COLOR	B_PANEL_BACKGROUND_COLOR
170#	define B_DOCUMENT_TEXT_COLOR		B_MENU_ITEM_TEXT_COLOR
171#endif
172
173#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
174	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
175#	if !defined(B_NOT_SUPPORTED) && !defined(HAIKU_HOST_PLATFORM_DANO)
176#		define B_NOT_SUPPORTED			(B_ERROR)
177#	endif
178#	define B_KERNEL_READ_AREA			0
179#	define B_KERNEL_WRITE_AREA			0
180#endif
181
182#if defined(HAIKU_TARGET_PLATFORM_BONE) || defined(HAIKU_TARGET_PLATFORM_DANO)
183#	define IF_NAMESIZE IFNAMSIZ
184#	define ifc_value ifc_val
185#	define IFF_AUTO_CONFIGURED 0
186#endif
187
188#include <limits.h>
189
190#ifndef INT32_MAX
191#	define INT32_MAX INT_MAX
192#endif
193
194#ifndef INT64_MAX
195#	define INT64_MAX LONGLONG_MAX
196#endif
197
198#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
199	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
200#	define	B_MPEG_2_AUDIO_LAYER_1 (enum mpeg_id)0x201
201#	define	B_MPEG_2_AUDIO_LAYER_2 (enum mpeg_id)0x202
202#	define	B_MPEG_2_AUDIO_LAYER_3 (enum mpeg_id)0x203
203#	define	B_MPEG_2_VIDEO (enum mpeg_id)0x211
204#	define	B_MPEG_2_5_AUDIO_LAYER_1 (enum mpeg_id)0x301
205#	define	B_MPEG_2_5_AUDIO_LAYER_2 (enum mpeg_id)0x302
206#	define	B_MPEG_2_5_AUDIO_LAYER_3 (enum mpeg_id)0x303
207#endif
208
209// TODO: experimental API (keep in sync with Accelerant.h)
210#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
211	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
212typedef struct {
213	uint32	version;
214	char	vendor[128];
215	char	name[128];
216	char	serial_number[128];
217	uint32	product_id;
218	struct {
219		uint16	week;
220		uint16	year;
221	}		produced;
222	float	width;
223	float	height;
224	uint32	min_horizontal_frequency;	// in kHz
225	uint32	max_horizontal_frequency;
226	uint32	min_vertical_frequency;		// in Hz
227	uint32	max_vertical_frequency;
228	uint32	max_pixel_clock;			// in kHz
229} monitor_info;
230#endif // !HAIKU_HOST_PLATFORM_HAIKU
231
232
233#if !defined(B_HAIKU_32_BIT) && !defined(B_HAIKU_64_BIT)
234#	ifdef HAIKU_HOST_PLATFORM_64_BIT
235#		define B_HAIKU_64_BIT	1
236#	else
237#		define B_HAIKU_32_BIT	1
238#	endif
239#endif
240
241#ifndef B_PRId8
242#	define	__HAIKU_PRI_PREFIX_32		"l"
243#	define	__HAIKU_PRI_PREFIX_64		"ll"
244#	define	__HAIKU_PRI_PREFIX_ADDR		"l"
245
246	/* printf()/scanf() format strings for [u]int* types */
247#	define B_PRId8			"d"
248#	define B_PRIi8			"i"
249#	define B_PRId16			"d"
250#	define B_PRIi16			"i"
251#	define B_PRId32			__HAIKU_PRI_PREFIX_32 "d"
252#	define B_PRIi32			__HAIKU_PRI_PREFIX_32 "i"
253#	define B_PRId64			__HAIKU_PRI_PREFIX_64 "d"
254#	define B_PRIi64			__HAIKU_PRI_PREFIX_64 "i"
255#	define B_PRIu8			"u"
256#	define B_PRIo8			"o"
257#	define B_PRIx8			"x"
258#	define B_PRIX8			"X"
259#	define B_PRIu16			"u"
260#	define B_PRIo16			"o"
261#	define B_PRIx16			"x"
262#	define B_PRIX16			"X"
263#	define B_PRIu32			__HAIKU_PRI_PREFIX_32 "u"
264#	define B_PRIo32			__HAIKU_PRI_PREFIX_32 "o"
265#	define B_PRIx32			__HAIKU_PRI_PREFIX_32 "x"
266#	define B_PRIX32			__HAIKU_PRI_PREFIX_32 "X"
267#	define B_PRIu64			__HAIKU_PRI_PREFIX_64 "u"
268#	define B_PRIo64			__HAIKU_PRI_PREFIX_64 "o"
269#	define B_PRIx64			__HAIKU_PRI_PREFIX_64 "x"
270#	define B_PRIX64			__HAIKU_PRI_PREFIX_64 "X"
271
272#	define B_SCNd8 			"hhd"
273#	define B_SCNi8 			"hhi"
274#	define B_SCNd16			"hd"
275#	define B_SCNi16	 		"hi"
276#	define B_SCNd32 		__HAIKU_PRI_PREFIX_32 "d"
277#	define B_SCNi32	 		__HAIKU_PRI_PREFIX_32 "i"
278#	define B_SCNd64			__HAIKU_PRI_PREFIX_64 "d"
279#	define B_SCNi64 		__HAIKU_PRI_PREFIX_64 "i"
280#	define B_SCNu8 			"hhu"
281#	define B_SCNo8 			"hho"
282#	define B_SCNx8 			"hhx"
283#	define B_SCNu16			"hu"
284#	define B_SCNo16			"ho"
285#	define B_SCNx16			"hx"
286#	define B_SCNu32 		__HAIKU_PRI_PREFIX_32 "u"
287#	define B_SCNo32 		__HAIKU_PRI_PREFIX_32 "o"
288#	define B_SCNx32 		__HAIKU_PRI_PREFIX_32 "x"
289#	define B_SCNu64			__HAIKU_PRI_PREFIX_64 "u"
290#	define B_SCNo64			__HAIKU_PRI_PREFIX_64 "o"
291#	define B_SCNx64			__HAIKU_PRI_PREFIX_64 "x"
292
293	/* printf() format strings for some standard types */
294	/* size_t */
295#	define B_PRIuSIZE		__HAIKU_PRI_PREFIX_ADDR "u"
296#	define B_PRIoSIZE		__HAIKU_PRI_PREFIX_ADDR "o"
297#	define B_PRIxSIZE		__HAIKU_PRI_PREFIX_ADDR "x"
298#	define B_PRIXSIZE		__HAIKU_PRI_PREFIX_ADDR "X"
299	/* ssize_t */
300#	define B_PRIdSSIZE		__HAIKU_PRI_PREFIX_ADDR "d"
301#	define B_PRIiSSIZE		__HAIKU_PRI_PREFIX_ADDR "i"
302	/* addr_t */
303#	define B_PRIuADDR		__HAIKU_PRI_PREFIX_ADDR "u"
304#	define B_PRIoADDR		__HAIKU_PRI_PREFIX_ADDR "o"
305#	define B_PRIxADDR		__HAIKU_PRI_PREFIX_ADDR "x"
306#	define B_PRIXADDR		__HAIKU_PRI_PREFIX_ADDR "X"
307	/* off_t */
308#	define B_PRIdOFF		B_PRId64
309#	define B_PRIiOFF		B_PRIi64
310	/* dev_t */
311#	define B_PRIdDEV		B_PRId32
312#	define B_PRIiDEV		B_PRIi32
313	/* ino_t */
314#	define B_PRIdINO		B_PRId64
315#	define B_PRIiINO		B_PRIi64
316	/* time_t */
317#	define B_PRIdTIME		B_PRId32
318#	define B_PRIiTIME		B_PRIi32
319#endif	// !B_PRId8
320
321
322#endif	// HAIKU_BUILD_COMPATIBILITY_H
323