HaikuBuildCompatibility.h revision 9e616c6b
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 size_t	strnlen(const char *string, size_t count);
123
124extern size_t	strlcat(char *dest, const char *source, size_t length);
125extern size_t   strlcpy(char *dest, const char *source, size_t length);
126
127extern char		*strcasestr(const char *string, const char *searchString);
128
129extern float	roundf(float value);
130
131#ifdef __cplusplus
132}
133#endif
134
135// These are R1-specific extensions
136#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
137	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
138#	define B_TRANSLATION_MAKE_VERSION(major, minor, revision) \
139		((major << 8) | ((minor << 4) & 0xf0) | (revision & 0x0f))
140#	define B_TRANSLATION_MAJOR_VERSION(v) (v >> 8)
141#	define B_TRANSLATION_MINOR_VERSION(v) ((v >> 4) & 0xf)
142#	define B_TRANSLATION_REVISION_VERSION(v) (v & 0xf)
143#	ifndef USING_HAIKU_TYPE_CONSTANTS_H
144#		define B_LARGE_ICON_TYPE		'ICON'
145#		define B_MINI_ICON_TYPE			'MICN'
146#		define B_VECTOR_ICON_TYPE		'VICN'
147#		define B_BITMAP_NO_SERVER_LINK	0
148#		define B_BITMAP_SCALE_BILINEAR	0
149#	endif
150#endif	// HAIKU_TARGET_PLATFORM_LIBBE_TEST
151
152#if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE)
153#	define B_REDO						'REDO'
154#	define B_BAD_DATA					(B_NOT_ALLOWED + 1)
155#	define B_DOCUMENT_BACKGROUND_COLOR	B_PANEL_BACKGROUND_COLOR
156#	define B_DOCUMENT_TEXT_COLOR		B_MENU_ITEM_TEXT_COLOR
157#endif
158
159#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
160	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
161#	if !defined(B_NOT_SUPPORTED) && !defined(HAIKU_HOST_PLATFORM_DANO)
162#		define B_NOT_SUPPORTED			(B_ERROR)
163#	endif
164#	define B_KERNEL_READ_AREA			0
165#	define B_KERNEL_WRITE_AREA			0
166#endif
167
168#if defined(HAIKU_TARGET_PLATFORM_BONE) || defined(HAIKU_TARGET_PLATFORM_DANO)
169#	define IF_NAMESIZE IFNAMSIZ
170#	define ifc_value ifc_val
171#	define IFF_AUTO_CONFIGURED 0
172#endif
173
174#include <limits.h>
175
176#ifndef INT32_MAX
177#	define INT32_MAX INT_MAX
178#endif
179
180#ifndef INT64_MAX
181#	define INT64_MAX LONGLONG_MAX
182#endif
183
184#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
185	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
186#	define	B_MPEG_2_AUDIO_LAYER_1 (enum mpeg_id)0x201
187#	define	B_MPEG_2_AUDIO_LAYER_2 (enum mpeg_id)0x202
188#	define	B_MPEG_2_AUDIO_LAYER_3 (enum mpeg_id)0x203
189#	define	B_MPEG_2_VIDEO (enum mpeg_id)0x211
190#	define	B_MPEG_2_5_AUDIO_LAYER_1 (enum mpeg_id)0x301
191#	define	B_MPEG_2_5_AUDIO_LAYER_2 (enum mpeg_id)0x302
192#	define	B_MPEG_2_5_AUDIO_LAYER_3 (enum mpeg_id)0x303
193#endif
194
195// TODO: experimental API (keep in sync with Accelerant.h)
196#if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
197	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
198typedef struct {
199	uint32	version;
200	char	vendor[128];
201	char	name[128];
202	char	serial_number[128];
203	uint32	product_id;
204	struct {
205		uint16	week;
206		uint16	year;
207	}		produced;
208	float	width;
209	float	height;
210	uint32	min_horizontal_frequency;	// in kHz
211	uint32	max_horizontal_frequency;
212	uint32	min_vertical_frequency;		// in Hz
213	uint32	max_vertical_frequency;
214	uint32	max_pixel_clock;			// in kHz
215} monitor_info;
216#endif // !HAIKU_HOST_PLATFORM_HAIKU
217
218
219#if !defined(B_HAIKU_32_BIT) && !defined(B_HAIKU_64_BIT)
220#	ifdef HAIKU_HOST_PLATFORM_64_BIT
221#		define B_HAIKU_64_BIT	1
222#	else
223#		define B_HAIKU_32_BIT	1
224#	endif
225#endif
226
227#ifndef B_PRId8
228#	define	__HAIKU_PRI_PREFIX_32		"l"
229#	define	__HAIKU_PRI_PREFIX_64		"ll"
230#	define	__HAIKU_PRI_PREFIX_ADDR		"l"
231
232	/* printf()/scanf() format strings for [u]int* types */
233#	define B_PRId8			"d"
234#	define B_PRIi8			"i"
235#	define B_PRId16			"d"
236#	define B_PRIi16			"i"
237#	define B_PRId32			__HAIKU_PRI_PREFIX_32 "d"
238#	define B_PRIi32			__HAIKU_PRI_PREFIX_32 "i"
239#	define B_PRId64			__HAIKU_PRI_PREFIX_64 "d"
240#	define B_PRIi64			__HAIKU_PRI_PREFIX_64 "i"
241#	define B_PRIu8			"u"
242#	define B_PRIo8			"o"
243#	define B_PRIx8			"x"
244#	define B_PRIX8			"X"
245#	define B_PRIu16			"u"
246#	define B_PRIo16			"o"
247#	define B_PRIx16			"x"
248#	define B_PRIX16			"X"
249#	define B_PRIu32			__HAIKU_PRI_PREFIX_32 "u"
250#	define B_PRIo32			__HAIKU_PRI_PREFIX_32 "o"
251#	define B_PRIx32			__HAIKU_PRI_PREFIX_32 "x"
252#	define B_PRIX32			__HAIKU_PRI_PREFIX_32 "X"
253#	define B_PRIu64			__HAIKU_PRI_PREFIX_64 "u"
254#	define B_PRIo64			__HAIKU_PRI_PREFIX_64 "o"
255#	define B_PRIx64			__HAIKU_PRI_PREFIX_64 "x"
256#	define B_PRIX64			__HAIKU_PRI_PREFIX_64 "X"
257
258#	define B_SCNd8 			"hhd"
259#	define B_SCNi8 			"hhi"
260#	define B_SCNd16			"hd"
261#	define B_SCNi16	 		"hi"
262#	define B_SCNd32 		__HAIKU_PRI_PREFIX_32 "d"
263#	define B_SCNi32	 		__HAIKU_PRI_PREFIX_32 "i"
264#	define B_SCNd64			__HAIKU_PRI_PREFIX_64 "d"
265#	define B_SCNi64 		__HAIKU_PRI_PREFIX_64 "i"
266#	define B_SCNu8 			"hhu"
267#	define B_SCNo8 			"hho"
268#	define B_SCNx8 			"hhx"
269#	define B_SCNu16			"hu"
270#	define B_SCNo16			"ho"
271#	define B_SCNx16			"hx"
272#	define B_SCNu32 		__HAIKU_PRI_PREFIX_32 "u"
273#	define B_SCNo32 		__HAIKU_PRI_PREFIX_32 "o"
274#	define B_SCNx32 		__HAIKU_PRI_PREFIX_32 "x"
275#	define B_SCNu64			__HAIKU_PRI_PREFIX_64 "u"
276#	define B_SCNo64			__HAIKU_PRI_PREFIX_64 "o"
277#	define B_SCNx64			__HAIKU_PRI_PREFIX_64 "x"
278
279	/* printf() format strings for some standard types */
280	/* size_t */
281#	define B_PRIuSIZE		__HAIKU_PRI_PREFIX_ADDR "u"
282#	define B_PRIoSIZE		__HAIKU_PRI_PREFIX_ADDR "o"
283#	define B_PRIxSIZE		__HAIKU_PRI_PREFIX_ADDR "x"
284#	define B_PRIXSIZE		__HAIKU_PRI_PREFIX_ADDR "X"
285	/* ssize_t */
286#	define B_PRIdSSIZE		__HAIKU_PRI_PREFIX_ADDR "d"
287#	define B_PRIiSSIZE		__HAIKU_PRI_PREFIX_ADDR "i"
288	/* addr_t */
289#	define B_PRIuADDR		__HAIKU_PRI_PREFIX_ADDR "u"
290#	define B_PRIoADDR		__HAIKU_PRI_PREFIX_ADDR "o"
291#	define B_PRIxADDR		__HAIKU_PRI_PREFIX_ADDR "x"
292#	define B_PRIXADDR		__HAIKU_PRI_PREFIX_ADDR "X"
293	/* off_t */
294#	define B_PRIdOFF		B_PRId64
295#	define B_PRIiOFF		B_PRIi64
296	/* dev_t */
297#	define B_PRIdDEV		B_PRId32
298#	define B_PRIiDEV		B_PRIi32
299	/* ino_t */
300#	define B_PRIdINO		B_PRId64
301#	define B_PRIiINO		B_PRIi64
302	/* time_t */
303#	define B_PRIdTIME		B_PRId32
304#	define B_PRIiTIME		B_PRIi32
305#endif	// !B_PRId8
306
307
308#endif	// HAIKU_BUILD_COMPATIBILITY_H
309