xref: /haiku/headers/build/os/support/SupportDefs.h (revision c90684742e7361651849be4116d0e5de3a817194)
1 /*
2  * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Author:
6  *		Erik Jaesler (erik@cgsoftware.com)
7  */
8 #ifndef _SUPPORT_DEFS_H
9 #define _SUPPORT_DEFS_H
10 
11 
12 #include <config_build/types.h>
13 
14 #include <BeBuild.h>
15 #include <Errors.h>
16 
17 #include <inttypes.h>
18 #include <sys/types.h>
19 
20 
21 /* fixed-size integer types */
22 typedef	__haiku_int8			int8;
23 typedef __haiku_uint8			uint8;
24 typedef	__haiku_int16			int16;
25 typedef __haiku_uint16			uint16;
26 typedef	__haiku_int32			int32;
27 typedef __haiku_uint32			uint32;
28 typedef	__haiku_int64			int64;
29 typedef __haiku_uint64			uint64;
30 
31 /* shorthand types */
32 typedef volatile int8   		vint8;
33 typedef volatile uint8			vuint8;
34 typedef volatile int16			vint16;
35 typedef volatile uint16			vuint16;
36 typedef volatile int32			vint32;
37 typedef volatile uint32			vuint32;
38 typedef volatile int64			vint64;
39 typedef volatile uint64			vuint64;
40 
41 typedef volatile long			vlong;
42 typedef volatile int			vint;
43 typedef volatile short			vshort;
44 typedef volatile char			vchar;
45 
46 typedef volatile unsigned long	vulong;
47 typedef volatile unsigned int	vuint;
48 typedef volatile unsigned short	vushort;
49 typedef volatile unsigned char	vuchar;
50 
51 typedef unsigned char			uchar;
52 typedef unsigned short          unichar;
53 
54 /* descriptive types */
55 typedef int32					status_t;
56 typedef int64					bigtime_t;
57 typedef uint32					type_code;
58 typedef uint32					perform_code;
59 
60 #ifdef HAIKU_HOST_PLATFORM_64_BIT
61 typedef uint64					phys_addr_t;
62 #else
63 typedef uint32					phys_addr_t;
64 #endif
65 typedef phys_addr_t				phys_size_t;
66 
67 typedef	addr_t					generic_addr_t;
68 typedef	size_t					generic_size_t;
69 
70 
71 /* printf()/scanf() format strings for [u]int* types */
72 #define B_PRId8			PRId8
73 #define B_PRIi8			PRIi8
74 #define B_PRId16		PRId16
75 #define B_PRIi16		PRIi16
76 #define B_PRId32		PRId32
77 #define B_PRIi32		PRIi32
78 #define B_PRId64		PRId64
79 #define B_PRIi64		PRIi64
80 #define B_PRIu8			PRIu8
81 #define B_PRIo8			PRIo8
82 #define B_PRIx8			PRIx8
83 #define B_PRIX8			PRIX8
84 #define B_PRIu16		PRIu16
85 #define B_PRIo16		PRIo16
86 #define B_PRIx16		PRIx16
87 #define B_PRIX16		PRIX16
88 #define B_PRIu32		PRIu32
89 #define B_PRIo32		PRIo32
90 #define B_PRIx32		PRIx32
91 #define B_PRIX32		PRIX32
92 #define B_PRIu64		PRIu64
93 #define B_PRIo64		PRIo64
94 #define B_PRIx64		PRIx64
95 #define B_PRIX64		PRIX64
96 
97 #define B_SCNd8 		SCNd8
98 #define B_SCNi8 		SCNi8
99 #define B_SCNd16		SCNd16
100 #define B_SCNi16 		SCNi16
101 #define B_SCNd32 		SCNd32
102 #define B_SCNi32 		SCNi32
103 #define B_SCNd64		SCNd64
104 #define B_SCNi64 		SCNi64
105 #define B_SCNu8 		SCNu8
106 #define B_SCNo8 		SCNo8
107 #define B_SCNx8 		SCNx8
108 #define B_SCNu16		SCNu16
109 #define B_SCNu16		SCNu16
110 #define B_SCNx16		SCNx16
111 #define B_SCNu32 		SCNu32
112 #define B_SCNo32 		SCNo32
113 #define B_SCNx32 		SCNx32
114 #define B_SCNu64		SCNu64
115 #define B_SCNo64		SCNo64
116 #define B_SCNx64		SCNx64
117 
118 
119 /* printf() format strings for some standard types */
120 /* addr_t, size_t, ssize_t */
121 #ifdef HAIKU_HOST_PLATFORM_64_BIT
122 #	define B_PRIuADDR	B_PRIu64
123 #	define B_PRIoADDR	B_PRIo64
124 #	define B_PRIxADDR	B_PRIx64
125 #	define B_PRIXADDR	B_PRIX64
126 #	define B_PRIuSIZE	B_PRIu64
127 #	define B_PRIoSIZE	B_PRIo64
128 #	define B_PRIxSIZE	B_PRIx64
129 #	define B_PRIXSIZE	B_PRIX64
130 #	define B_PRIdSSIZE	B_PRId64
131 #	define B_PRIiSSIZE	B_PRIi64
132 #else
133 #	define B_PRIuADDR	B_PRIu32
134 #	define B_PRIoADDR	B_PRIo32
135 #	define B_PRIxADDR	B_PRIx32
136 #	define B_PRIXADDR	B_PRIX32
137 #	define B_PRIuSIZE	B_PRIu32
138 #	define B_PRIoSIZE	B_PRIo32
139 #	define B_PRIxSIZE	B_PRIx32
140 #	define B_PRIXSIZE	B_PRIX32
141 #	define B_PRIdSSIZE	B_PRId32
142 #	define B_PRIiSSIZE	B_PRIi32
143 #endif
144 /* phys_addr_t */
145 #ifdef HAIKU_HOST_PLATFORM_64_BIT
146 #	define B_PRIuPHYSADDR	B_PRIu64
147 #	define B_PRIoPHYSADDR	B_PRIo64
148 #	define B_PRIxPHYSADDR	B_PRIx64
149 #	define B_PRIXPHYSADDR	B_PRIX64
150 #else
151 #	define B_PRIuPHYSADDR	B_PRIu32
152 #	define B_PRIoPHYSADDR	B_PRIo32
153 #	define B_PRIxPHYSADDR	B_PRIx32
154 #	define B_PRIXPHYSADDR	B_PRIX32
155 #endif
156 /* generic_addr_t */
157 #define B_PRIuGENADDR	B_PRIuADDR
158 #define B_PRIoGENADDR	B_PRIoADDR
159 #define B_PRIxGENADDR	B_PRIxADDR
160 #define B_PRIXGENADDR	B_PRIXADDR
161 /* off_t */
162 #define B_PRIdOFF		B_PRId64
163 #define B_PRIiOFF		B_PRIi64
164 /* dev_t */
165 #define B_PRIdDEV		B_PRId32
166 #define B_PRIiDEV		B_PRIi32
167 /* ino_t */
168 #define B_PRIdINO		B_PRId64
169 #define B_PRIiINO		B_PRIi64
170 /* time_t */
171 #define B_PRIdTIME		B_PRId32
172 #define B_PRIiTIME		B_PRIi32
173 
174 
175 /* Empty string ("") */
176 #ifdef __cplusplus
177 extern const char *B_EMPTY_STRING;
178 #endif
179 
180 
181 /* min and max comparisons */
182 #ifndef __cplusplus
183 #	ifndef min
184 #		define min(a,b) ((a)>(b)?(b):(a))
185 #	endif
186 #	ifndef max
187 #		define max(a,b) ((a)>(b)?(a):(b))
188 #	endif
189 #endif
190 
191 /* min() and max() are functions in C++ */
192 #define min_c(a,b) ((a)>(b)?(b):(a))
193 #define max_c(a,b) ((a)>(b)?(a):(b))
194 
195 
196 /* Grandfathering */
197 #ifndef __cplusplus
198 #	include <stdbool.h>
199 #endif
200 
201 #ifndef NULL
202 #	define NULL (0)
203 #endif
204 
205 
206 #ifdef __cplusplus
207 extern "C" {
208 #endif
209 
210 /* Atomic functions; previous value is returned */
211 extern int32	atomic_set(vint32 *value, int32 newValue);
212 extern int32	atomic_test_and_set(vint32 *value, int32 newValue, int32 testAgainst);
213 extern int32	atomic_add(vint32 *value, int32 addValue);
214 extern int32	atomic_and(vint32 *value, int32 andValue);
215 extern int32	atomic_or(vint32 *value, int32 orValue);
216 extern int32	atomic_get(vint32 *value);
217 
218 extern int64	atomic_set64(vint64 *value, int64 newValue);
219 extern int64	atomic_test_and_set64(vint64 *value, int64 newValue, int64 testAgainst);
220 extern int64	atomic_add64(vint64 *value, int64 addValue);
221 extern int64	atomic_and64(vint64 *value, int64 andValue);
222 extern int64	atomic_or64(vint64 *value, int64 orValue);
223 extern int64	atomic_get64(vint64 *value);
224 
225 /* Other stuff */
226 extern void*	get_stack_frame(void);
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 /* Obsolete or discouraged API */
233 
234 /* use 'true' and 'false' */
235 #ifndef FALSE
236 #	define FALSE	0
237 #endif
238 #ifndef TRUE
239 #	define TRUE		1
240 #endif
241 
242 #endif	/* _SUPPORT_DEFS_H */
243