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