Debian Codegraph @

common/types.h

raw symbols SCIP
1 /*
2 * Type and type-support definitions
3 *
4 * Copyright (C) 2012-2025, Joachim Metz <[email protected]>
5 *
6 * Refer to AUTHORS for acknowledgements.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #if !defined( _TYPES_H )
23 #define _TYPES_H
24
25 #include "common.h"
26
27 #if defined( HAVE_LIMITS_H ) || defined( WINAPI )
28 #include <limits.h>
29 #endif
30
31 /* Make sure to include inttypes.h or stdint.h before
32 * PRI definitions are defined
33 */
34 #include <libvhdi/types.h>
35
36 #if defined( WINAPI ) && ( defined( _UNICODE ) || defined( UNICODE ) )
37
38 #define HAVE_WIDE_SYSTEM_CHARACTER 1
39
40 /* The system character type is wide
41 * A system string contains either UTF-16 or UTF-32
42 */
43 typedef wchar_t system_character_t;
44 typedef wint_t system_integer_t;
45
46 #define PRIc_SYSTEM "lc"
47 #define PRIs_SYSTEM "ls"
48
49 #else
50
51 /* The system character type is narrow
52 * A system string contains either UTF-8 or extended ASCII with a codepage
53 */
54 typedef char system_character_t;
55 typedef int system_integer_t;
56
57 #define PRIc_SYSTEM "c"
58 #define PRIs_SYSTEM "s"
59
60 #endif /* defined( WINAPI ) && ( defined( _UNICODE ) || defined( UNICODE ) ) */
61
62 /* Fallback for systems without PRI definitions
63 * Do not define when pyconfig.h has been included via python.h
64 */
65 #if !defined( HAVE_PYCONFIG_H )
66
67 #if !defined( PRId8 )
68 #define PRId8 "d"
69 #endif
70
71 #if !defined( PRId16 )
72 #define PRId16 "d"
73 #endif
74
75 #if !defined( PRId32 )
76 #if defined( WINAPI )
77 #define PRId32 "I32d"
78
79 #else
80 #define PRId32 "d"
81
82 #endif
83 #endif /* !defined( PRId32 ) */
84
85 #if !defined( PRId64 )
86 #if defined( WINAPI )
87 #define PRId64 "I64d"
88
89 #elif __WORDSIZE == 64
90 #define PRId64 "ld"
91
92 #else
93 #define PRId64 "lld"
94
95 #endif
96 #endif /* !defined( PRId64 ) */
97
98 #if !defined( PRIi8 )
99 #define PRIi8 "i"
100 #endif
101
102 #if !defined( PRIi16 )
103 #define PRIi16 "i"
104 #endif
105
106 #if !defined( PRIi32 )
107 #if defined( WINAPI )
108 #define PRIi32 "I32i"
109
110 #else
111 #define PRIi32 "i"
112
113 #endif
114 #endif /* !defined( PRIi32 ) */
115
116 #if !defined( PRIi64 )
117 #if defined( WINAPI )
118 #define PRIi64 "I64i"
119
120 #elif __WORDSIZE == 64
121 #define PRIi64 "li"
122
123 #else
124 #define PRIi64 "lli"
125
126 #endif
127 #endif /* !defined( PRIi64 ) */
128
129 #if !defined( PRIu8 )
130 #define PRIu8 "u"
131 #endif
132
133 #if !defined( PRIu16 )
134 #define PRIu16 "u"
135 #endif
136
137 #if !defined( PRIu32 )
138 #if defined( WINAPI )
139 #define PRIu32 "I32u"
140
141 #else
142 #define PRIu32 "u"
143
144 #endif
145 #endif /* !defined( PRIu32 ) */
146
147 #if !defined( PRIu64 )
148 #if defined( WINAPI )
149 #define PRIu64 "I64u"
150
151 #elif __WORDSIZE == 64
152 #define PRIu64 "lu"
153
154 #else
155 #define PRIu64 "llu"
156
157 #endif
158 #endif /* !defined( PRIu64 ) */
159
160 #if !defined( PRIo8 )
161 #define PRIo8 "o"
162 #endif
163
164 #if !defined( PRIo16 )
165 #define PRIo16 "o"
166 #endif
167
168 #if !defined( PRIo32 )
169 #if defined( WINAPI )
170 #define PRIo32 "I32o"
171
172 #else
173 #define PRIo32 "o"
174
175 #endif
176 #endif /* !defined( PRIo32 ) */
177
178 #if !defined( PRIo64 )
179 #if defined( WINAPI )
180 #define PRIo64 "I64o"
181
182 #elif __WORDSIZE == 64
183 #define PRIo64 "lo"
184
185 #else
186 #define PRIo64 "llo"
187
188 #endif
189 #endif /* !defined( PRIo64 ) */
190
191 #if !defined( PRIx8 )
192 #define PRIx8 "x"
193 #endif
194
195 #if !defined( PRIx16 )
196 #define PRIx16 "x"
197 #endif
198
199 #if !defined( PRIx32 )
200 #if defined( WINAPI )
201 #define PRIx32 "I32x"
202
203 #else
204 #define PRIx32 "x"
205
206 #endif
207 #endif /* !defined( PRIx32 ) */
208
209 #if !defined( PRIx64 )
210 #if defined( WINAPI )
211 #define PRIx64 "I64x"
212
213 #elif __WORDSIZE == 64
214 #define PRIx64 "lx"
215
216 #else
217 #define PRIx64 "llx"
218
219 #endif
220 #endif /* !defined( PRIx64 ) */
221
222 #endif /* !defined( HAVE_PYCONFIG_H ) */
223
224 /* Fallback for systems without printf %jd definition
225 */
226 #if defined( HAVE_PRINTF_JD )
227 #define PRIjd "jd"
228 #define PRIji "ji"
229 #define PRIju "ju"
230 #define PRIjx "jx"
231
232 #elif SIZEOF_OFF_T == 8
233 #define PRIjd PRId64
234 #define PRIji PRIi64
235 #define PRIju PRIu64
236 #define PRIjx PRIx64
237
238 #else
239 #define PRIjd PRId32
240 #define PRIji PRIi32
241 #define PRIju PRIu32
242 #define PRIjx PRIx32
243
244 #endif /* defined( HAVE_PRINTF_JD ) */
245
246 /* Fallback for systems without printf %zd definition
247 */
248 #if defined( HAVE_PRINTF_ZD )
249 #define PRIzd "zd"
250 #define PRIzi "zi"
251 #define PRIzu "zu"
252 #define PRIzx "zx"
253
254 #elif defined( _MSC_VER )
255 #define PRIzd "Id"
256 #define PRIzi "Ii"
257 #define PRIzu "Iu"
258 #define PRIzx "Ix"
259
260 #elif SIZEOF_SIZE_T == 8
261 #define PRIzd PRId64
262 #define PRIzi PRIi64
263 #define PRIzu PRIu64
264 #define PRIzx PRIx64
265
266 #else
267 #define PRIzd PRId32
268 #define PRIzi PRIi32
269 #define PRIzu PRIu32
270 #define PRIzx PRIx32
271
272 #endif /* defined( HAVE_PRINTF_ZD ) */
273
274 /* Fallback for systems without (U)INTx_MAX definitions
275 */
276
277 /* The maximum signed 8-bit integer is 127 (0x7f)
278 */
279 #if !defined( INT8_MAX )
280 #define INT8_MAX (0x7f)
281 #endif
282
283 /* The maximum unsigned 8-bit integer is 256 (0xff)
284 */
285 #if !defined( UINT8_MAX )
286 #define UINT8_MAX (0xff)
287 #endif
288
289 /* The maximum signed 16-bit integer is 32767 (0x7ffff)
290 */
291 #if !defined( INT16_MAX )
292 #define INT16_MAX (0x7fff)
293 #endif
294
295 /* The maximum unsigned 16-bit integer is 65535 (0xffff)
296 */
297 #if !defined( UINT16_MAX )
298 #define UINT16_MAX (0xffff)
299 #endif
300
301 /* The maximum signed 32-bit integer is 2147483647 (0x7fffffff)
302 */
303 #if !defined( INT32_MAX )
304 #define INT32_MAX (0x7fffffffL)
305 #endif
306
307 /* The maximum unsigned 32-bit integer is 4294967295 (0xffffffff)
308 */
309 #if !defined( UINT32_MAX )
310 #define UINT32_MAX (0xffffffffUL)
311 #endif
312
313 /* The minimum signed 64-bit integer is -9223372036854775808 (0x8000000000000000)
314 */
315 #if !defined( INT64_MIN )
316 #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 )
317 #define INT64_MIN (0x8000000000000000UL)
318 #else
319 #define INT64_MIN (0x8000000000000000ULL)
320 #endif
321 #endif /* !defined( INT64_MIN ) */
322
323 /* The maximum signed 64-bit integer is 9223372036854775807 (0x7fffffffffffffff)
324 */
325 #if !defined( INT64_MAX )
326 #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 )
327 #define INT64_MAX (0x7fffffffffffffffUL)
328 #else
329 #define INT64_MAX (0x7fffffffffffffffULL)
330 #endif
331 #endif /* !defined( INT64_MAX ) */
332
333 /* The maximum unsigned 64-bit integer is 18446744073709551615 (0xffffffffffffffff)
334 */
335 #if !defined( UINT64_MAX )
336 #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x0560 )
337 #define UINT64_MAX (0xffffffffffffffffUL)
338 #else
339 #define UINT64_MAX (0xffffffffffffffffULL)
340 #endif
341 #endif /* !defined( UINT64_MAX ) */
342
343 /* The maximum signed integer
344 */
345 #if !defined( INT_MAX )
346 #define INT_MAX INT32_MAX
347 #endif
348
349 /* The maximum unsigned integer
350 */
351 #if !defined( UINT_MAX )
352 #define UINT_MAX UINT32_MAX
353 #endif
354
355 /* The maximum signed long integer
356 */
357 #if !defined( LONG_MAX )
358 #define LONG_MAX INT32_MAX
359 #endif
360
361 /* The maximum unsigned long integer
362 */
363 #if !defined( ULONG_MAX )
364 #define ULONG_MAX UINT32_MAX
365 #endif
366
367 /* The maximum signed size type is platform dependent
368 */
369 #if !defined( SSIZE_MAX )
370
371 #if defined( WINAPI )
372
373 #if defined( _WIN64 )
374 #define SSIZE_MAX INT64_MAX
375 #else
376 #define SSIZE_MAX INT32_MAX
377 #endif
378
379 #else
380
381 #if __WORDSIZE == 64
382 #define SSIZE_MAX INT64_MAX
383 #else
384 #define SSIZE_MAX INT32_MAX
385 #endif
386
387 #endif /* WINAPI */
388
389 #endif /* SSIZE_MAX */
390
391 #endif /* !defined( _TYPES_H ) */
392