xref: /haiku/headers/build/HaikuBuildCompatibility.h (revision 73ad2473e7874b3702cf5b0fdf4c81b747812ed9)
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 
43 struct 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 
51 typedef 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 #ifndef B_SPINLOCK_INITIALIZER
76 #	define B_SPINLOCK_INITIALIZER 0
77 #endif
78 
79 #if defined(__GNUC__) && !defined(_PRINTFLIKE)
80 #	define _PRINTFLIKE(_format_, _args_) \
81 		__attribute__((format(__printf__, _format_, _args_)))
82 #endif
83 
84 #if 0
85 // NOTE: This is probably only needed on platforms which don't use ELF
86 // as binary format. So could probably be removed completely.
87 #if defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
88 	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
89 // BeOS version of BeBuild.h defines this
90 #	define _IMPEXP_ROOT			__declspec(dllimport)
91 #	define _IMPEXP_BE			__declspec(dllimport)
92 #	define _IMPEXP_MEDIA		__declspec(dllimport)
93 #	define _IMPEXP_TRACKER		__declspec(dllimport)
94 #	define _IMPEXP_TRANSLATION	__declspec(dllimport)
95 #	define _IMPEXP_DEVICE		__declspec(dllimport)
96 #	define _IMPEXP_NET			__declspec(dllimport)
97 #endif
98 #endif
99 
100 #if defined(__cplusplus) && !defined(HAIKU_HOST_PLATFORM_HAIKU)
101 class BBuffer;
102 class BBufferConsumer;
103 class BBufferGroup;
104 class BContinuousParameter;
105 class BControllable;
106 class BFileInterface;
107 class BMimeType;
108 class BParameterWeb;
109 class BRegion;
110 class BTextView;
111 class BTranslator;
112 class BTimeSource;
113 struct entry_ref;
114 struct media_node;
115 #endif
116 
117 #ifdef __cplusplus
118 extern "C" {
119 #endif
120 
121 extern void		atomic_set(int32* value, int32 newValue);
122 extern int32	atomic_get_and_set(int32* value, int32 newValue);
123 extern int32	atomic_test_and_set(int32 *value, int32 newValue,
124 					int32 testAgainst);
125 extern int32	atomic_get(int32 *value);
126 extern void		atomic_set64(int64* value, int64 newValue);
127 extern int64	atomic_get_and_set64(int64* value, int64 newValue);
128 extern int64	atomic_test_and_set64(int64 *value, int64 newValue,
129 					int64 testAgainst);
130 extern int64	atomic_get64(int64 *value);
131 extern int64	atomic_add64(int64 *value, int64 addValue);
132 extern int64	atomic_and64(int64 *value, int64 andValue);
133 extern int64	atomic_or64(int64 *value, int64 orValue);
134 
135 extern size_t	strnlen(const char *string, size_t count);
136 
137 extern size_t	strlcat(char *dest, const char *source, size_t length);
138 extern size_t   strlcpy(char *dest, const char *source, size_t length);
139 
140 extern char		*strcasestr(const char *string, const char *searchString);
141 
142 extern float	roundf(float value);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 // These are R1-specific extensions
149 #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
150 	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
151 #	define B_TRANSLATION_MAKE_VERSION(major, minor, revision) \
152 		((major << 8) | ((minor << 4) & 0xf0) | (revision & 0x0f))
153 #	define B_TRANSLATION_MAJOR_VERSION(v) (v >> 8)
154 #	define B_TRANSLATION_MINOR_VERSION(v) ((v >> 4) & 0xf)
155 #	define B_TRANSLATION_REVISION_VERSION(v) (v & 0xf)
156 #	ifndef USING_HAIKU_TYPE_CONSTANTS_H
157 #		define B_LARGE_ICON_TYPE		'ICON'
158 #		define B_MINI_ICON_TYPE			'MICN'
159 #		define B_VECTOR_ICON_TYPE		'VICN'
160 #		define B_BITMAP_NO_SERVER_LINK	0
161 #		define B_BITMAP_SCALE_BILINEAR	0
162 #	endif
163 #endif	// HAIKU_TARGET_PLATFORM_LIBBE_TEST
164 
165 #if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE)
166 #	define B_REDO						'REDO'
167 #	define B_BAD_DATA					(B_NOT_ALLOWED + 1)
168 #	define B_DOCUMENT_BACKGROUND_COLOR	B_PANEL_BACKGROUND_COLOR
169 #	define B_DOCUMENT_TEXT_COLOR		B_MENU_ITEM_TEXT_COLOR
170 #endif
171 
172 #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
173 	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
174 #	if !defined(B_NOT_SUPPORTED) && !defined(HAIKU_HOST_PLATFORM_DANO)
175 #		define B_NOT_SUPPORTED			(B_ERROR)
176 #	endif
177 #	define B_KERNEL_READ_AREA			0
178 #	define B_KERNEL_WRITE_AREA			0
179 #endif
180 
181 #if defined(HAIKU_TARGET_PLATFORM_BONE) || defined(HAIKU_TARGET_PLATFORM_DANO)
182 #	define IF_NAMESIZE IFNAMSIZ
183 #	define ifc_value ifc_val
184 #	define IFF_AUTO_CONFIGURED 0
185 #endif
186 
187 #include <limits.h>
188 
189 #ifndef INT32_MAX
190 #	define INT32_MAX INT_MAX
191 #endif
192 
193 #ifndef INT64_MAX
194 #	define INT64_MAX LONGLONG_MAX
195 #endif
196 
197 #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
198 	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
199 #	define	B_MPEG_2_AUDIO_LAYER_1 (enum mpeg_id)0x201
200 #	define	B_MPEG_2_AUDIO_LAYER_2 (enum mpeg_id)0x202
201 #	define	B_MPEG_2_AUDIO_LAYER_3 (enum mpeg_id)0x203
202 #	define	B_MPEG_2_VIDEO (enum mpeg_id)0x211
203 #	define	B_MPEG_2_5_AUDIO_LAYER_1 (enum mpeg_id)0x301
204 #	define	B_MPEG_2_5_AUDIO_LAYER_2 (enum mpeg_id)0x302
205 #	define	B_MPEG_2_5_AUDIO_LAYER_3 (enum mpeg_id)0x303
206 #endif
207 
208 // TODO: experimental API (keep in sync with Accelerant.h)
209 #if !defined(HAIKU_TARGET_PLATFORM_LIBBE_TEST) \
210 	&& !defined(HAIKU_HOST_PLATFORM_HAIKU)
211 typedef struct {
212 	uint32	version;
213 	char	vendor[128];
214 	char	name[128];
215 	char	serial_number[128];
216 	uint32	product_id;
217 	struct {
218 		uint16	week;
219 		uint16	year;
220 	}		produced;
221 	float	width;
222 	float	height;
223 	uint32	min_horizontal_frequency;	// in kHz
224 	uint32	max_horizontal_frequency;
225 	uint32	min_vertical_frequency;		// in Hz
226 	uint32	max_vertical_frequency;
227 	uint32	max_pixel_clock;			// in kHz
228 } monitor_info;
229 #endif // !HAIKU_HOST_PLATFORM_HAIKU
230 
231 
232 #if !defined(B_HAIKU_32_BIT) && !defined(B_HAIKU_64_BIT)
233 #	ifdef HAIKU_HOST_PLATFORM_64_BIT
234 #		define B_HAIKU_64_BIT	1
235 #	else
236 #		define B_HAIKU_32_BIT	1
237 #	endif
238 #endif
239 
240 #ifndef B_PRId8
241 #	define	__HAIKU_PRI_PREFIX_32		"l"
242 #	define	__HAIKU_PRI_PREFIX_64		"ll"
243 #	define	__HAIKU_PRI_PREFIX_ADDR		"l"
244 
245 	/* printf()/scanf() format strings for [u]int* types */
246 #	define B_PRId8			"d"
247 #	define B_PRIi8			"i"
248 #	define B_PRId16			"d"
249 #	define B_PRIi16			"i"
250 #	define B_PRId32			__HAIKU_PRI_PREFIX_32 "d"
251 #	define B_PRIi32			__HAIKU_PRI_PREFIX_32 "i"
252 #	define B_PRId64			__HAIKU_PRI_PREFIX_64 "d"
253 #	define B_PRIi64			__HAIKU_PRI_PREFIX_64 "i"
254 #	define B_PRIu8			"u"
255 #	define B_PRIo8			"o"
256 #	define B_PRIx8			"x"
257 #	define B_PRIX8			"X"
258 #	define B_PRIu16			"u"
259 #	define B_PRIo16			"o"
260 #	define B_PRIx16			"x"
261 #	define B_PRIX16			"X"
262 #	define B_PRIu32			__HAIKU_PRI_PREFIX_32 "u"
263 #	define B_PRIo32			__HAIKU_PRI_PREFIX_32 "o"
264 #	define B_PRIx32			__HAIKU_PRI_PREFIX_32 "x"
265 #	define B_PRIX32			__HAIKU_PRI_PREFIX_32 "X"
266 #	define B_PRIu64			__HAIKU_PRI_PREFIX_64 "u"
267 #	define B_PRIo64			__HAIKU_PRI_PREFIX_64 "o"
268 #	define B_PRIx64			__HAIKU_PRI_PREFIX_64 "x"
269 #	define B_PRIX64			__HAIKU_PRI_PREFIX_64 "X"
270 
271 #	define B_SCNd8 			"hhd"
272 #	define B_SCNi8 			"hhi"
273 #	define B_SCNd16			"hd"
274 #	define B_SCNi16	 		"hi"
275 #	define B_SCNd32 		__HAIKU_PRI_PREFIX_32 "d"
276 #	define B_SCNi32	 		__HAIKU_PRI_PREFIX_32 "i"
277 #	define B_SCNd64			__HAIKU_PRI_PREFIX_64 "d"
278 #	define B_SCNi64 		__HAIKU_PRI_PREFIX_64 "i"
279 #	define B_SCNu8 			"hhu"
280 #	define B_SCNo8 			"hho"
281 #	define B_SCNx8 			"hhx"
282 #	define B_SCNu16			"hu"
283 #	define B_SCNo16			"ho"
284 #	define B_SCNx16			"hx"
285 #	define B_SCNu32 		__HAIKU_PRI_PREFIX_32 "u"
286 #	define B_SCNo32 		__HAIKU_PRI_PREFIX_32 "o"
287 #	define B_SCNx32 		__HAIKU_PRI_PREFIX_32 "x"
288 #	define B_SCNu64			__HAIKU_PRI_PREFIX_64 "u"
289 #	define B_SCNo64			__HAIKU_PRI_PREFIX_64 "o"
290 #	define B_SCNx64			__HAIKU_PRI_PREFIX_64 "x"
291 
292 	/* printf() format strings for some standard types */
293 	/* size_t */
294 #	define B_PRIuSIZE		__HAIKU_PRI_PREFIX_ADDR "u"
295 #	define B_PRIoSIZE		__HAIKU_PRI_PREFIX_ADDR "o"
296 #	define B_PRIxSIZE		__HAIKU_PRI_PREFIX_ADDR "x"
297 #	define B_PRIXSIZE		__HAIKU_PRI_PREFIX_ADDR "X"
298 	/* ssize_t */
299 #	define B_PRIdSSIZE		__HAIKU_PRI_PREFIX_ADDR "d"
300 #	define B_PRIiSSIZE		__HAIKU_PRI_PREFIX_ADDR "i"
301 	/* addr_t */
302 #	define B_PRIuADDR		__HAIKU_PRI_PREFIX_ADDR "u"
303 #	define B_PRIoADDR		__HAIKU_PRI_PREFIX_ADDR "o"
304 #	define B_PRIxADDR		__HAIKU_PRI_PREFIX_ADDR "x"
305 #	define B_PRIXADDR		__HAIKU_PRI_PREFIX_ADDR "X"
306 	/* off_t */
307 #	define B_PRIdOFF		B_PRId64
308 #	define B_PRIiOFF		B_PRIi64
309 	/* dev_t */
310 #	define B_PRIdDEV		B_PRId32
311 #	define B_PRIiDEV		B_PRIi32
312 	/* ino_t */
313 #	define B_PRIdINO		B_PRId64
314 #	define B_PRIiINO		B_PRIi64
315 	/* time_t */
316 #	define B_PRIdTIME		B_PRId32
317 #	define B_PRIiTIME		B_PRIi32
318 #endif	// !B_PRId8
319 
320 
321 #endif	// HAIKU_BUILD_COMPATIBILITY_H
322