1 | /** @file
|
---|
2 | * IPRT - stdint.h wrapper (for backlevel compilers like MSC).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2009-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_stdint_h
|
---|
27 | #define IPRT_INCLUDED_stdint_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/cdefs.h>
|
---|
33 |
|
---|
34 |
|
---|
35 | /*
|
---|
36 | * Use the stdint.h on systems that have one.
|
---|
37 | */
|
---|
38 | #if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
|
---|
39 | && !(defined(RT_OS_FREEBSD) && defined(_KERNEL)) \
|
---|
40 | && !(defined(RT_OS_NETBSD) && defined(_KERNEL)) \
|
---|
41 | && RT_MSC_PREREQ_EX(RT_MSC_VER_VS2010, 1 /*non-msc*/) \
|
---|
42 | && !defined(__IBMC__) \
|
---|
43 | && !defined(__IBMCPP__) \
|
---|
44 | && !defined(IPRT_NO_CRT) \
|
---|
45 | && !defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
|
---|
46 | && !defined(DOXYGEN_RUNNING)
|
---|
47 |
|
---|
48 | # ifndef __STDC_CONSTANT_MACROS
|
---|
49 | # define __STDC_CONSTANT_MACROS
|
---|
50 | # endif
|
---|
51 | # ifndef __STDC_LIMIT_MACROS
|
---|
52 | # define __STDC_LIMIT_MACROS
|
---|
53 | # endif
|
---|
54 | # ifdef _MSC_VER
|
---|
55 | # pragma warning(push)
|
---|
56 | # pragma warning(disable:4668)
|
---|
57 | # endif
|
---|
58 | # include <stdint.h>
|
---|
59 | # ifdef _MSC_VER
|
---|
60 | # pragma warning(pop)
|
---|
61 | # endif
|
---|
62 |
|
---|
63 | # if defined(RT_OS_DARWIN) && defined(KERNEL) && defined(RT_ARCH_AMD64)
|
---|
64 | /*
|
---|
65 | * Kludge to fix the incorrect 32-bit constant macros in
|
---|
66 | * Kernel.framework/Headers/stdin.h. uint32_t and int32_t are
|
---|
67 | * int not long as these macros use, which is significant when
|
---|
68 | * targeting AMD64. (10a222)
|
---|
69 | */
|
---|
70 | # undef INT32_C
|
---|
71 | # define INT32_C(Value) (Value)
|
---|
72 | # undef UINT32_C
|
---|
73 | # define UINT32_C(Value) (Value ## U)
|
---|
74 | # endif /* 64-bit darwin kludge. */
|
---|
75 |
|
---|
76 | #elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
|
---|
77 |
|
---|
78 | # ifndef __STDC_CONSTANT_MACROS
|
---|
79 | # define __STDC_CONSTANT_MACROS
|
---|
80 | # endif
|
---|
81 | # ifndef __STDC_LIMIT_MACROS
|
---|
82 | # define __STDC_LIMIT_MACROS
|
---|
83 | # endif
|
---|
84 | # include <sys/stdint.h>
|
---|
85 |
|
---|
86 | #elif defined(RT_OS_NETBSD) && defined(_KERNEL)
|
---|
87 |
|
---|
88 | # ifndef __STDC_CONSTANT_MACROS
|
---|
89 | # define __STDC_CONSTANT_MACROS
|
---|
90 | # endif
|
---|
91 | # ifndef __STDC_LIMIT_MACROS
|
---|
92 | # define __STDC_LIMIT_MACROS
|
---|
93 | # endif
|
---|
94 | # include <sys/stdint.h>
|
---|
95 |
|
---|
96 | #else /* No system stdint.h */
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * Define the types we use.
|
---|
100 | * The linux kernel defines all these in linux/types.h, so skip it.
|
---|
101 | */
|
---|
102 | # if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
|
---|
103 | || defined(IPRT_NO_CRT) \
|
---|
104 | || defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
|
---|
105 | || defined(DOXGEN_RUNNING)
|
---|
106 |
|
---|
107 | /* Simplify the [u]int64_t type detection mess. */
|
---|
108 | # undef IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
|
---|
109 | # ifdef __IBMCPP__
|
---|
110 | # if __IBMCPP__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
|
---|
111 | # define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
|
---|
112 | # endif
|
---|
113 | # endif
|
---|
114 | # ifdef __IBMC__
|
---|
115 | # if __IBMC__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
|
---|
116 | # define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
|
---|
117 | # endif
|
---|
118 | # endif
|
---|
119 |
|
---|
120 | /* x-bit types */
|
---|
121 | # if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) \
|
---|
122 | || defined(RT_ARCH_ARM32) || defined(RT_ARCH_ARM64) \
|
---|
123 | || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
|
---|
124 | # if !defined(_INT8_T_DECLARED) && !defined(_INT8_T)
|
---|
125 | typedef signed char int8_t;
|
---|
126 | # endif
|
---|
127 | # if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T)
|
---|
128 | typedef unsigned char uint8_t;
|
---|
129 | # endif
|
---|
130 | # if !defined(_INT16_T_DECLARED) && !defined(_INT16_T)
|
---|
131 | typedef signed short int16_t;
|
---|
132 | # endif
|
---|
133 | # if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T)
|
---|
134 | typedef unsigned short uint16_t;
|
---|
135 | # endif
|
---|
136 | # if !defined(_INT32_T_DECLARED) && !defined(_INT32_T)
|
---|
137 | # if ARCH_BITS != 16
|
---|
138 | typedef signed int int32_t;
|
---|
139 | # else
|
---|
140 | typedef signed long int32_t;
|
---|
141 | # endif
|
---|
142 | # endif
|
---|
143 | # if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T)
|
---|
144 | # if ARCH_BITS != 16
|
---|
145 | typedef unsigned int uint32_t;
|
---|
146 | # else
|
---|
147 | typedef unsigned long uint32_t;
|
---|
148 | # endif
|
---|
149 | # endif
|
---|
150 | # if defined(_MSC_VER)
|
---|
151 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
|
---|
152 | typedef signed _int64 int64_t;
|
---|
153 | # endif
|
---|
154 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
|
---|
155 | typedef unsigned _int64 uint64_t;
|
---|
156 | # endif
|
---|
157 | # elif defined(__WATCOMC__)
|
---|
158 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
|
---|
159 | typedef signed __int64 int64_t;
|
---|
160 | # endif
|
---|
161 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
|
---|
162 | typedef unsigned __int64 uint64_t;
|
---|
163 | # endif
|
---|
164 | # elif defined(IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES)
|
---|
165 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
|
---|
166 | typedef struct { uint32_t lo; int32_t hi; } int64_t;
|
---|
167 | # endif
|
---|
168 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
|
---|
169 | typedef struct { uint32_t lo; uint32_t hi; } uint64_t;
|
---|
170 | # endif
|
---|
171 | # else /* Use long long for 64-bit types */
|
---|
172 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
|
---|
173 | typedef signed long long int64_t;
|
---|
174 | # endif
|
---|
175 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
|
---|
176 | typedef unsigned long long uint64_t;
|
---|
177 | # endif
|
---|
178 | # endif
|
---|
179 |
|
---|
180 | /* max integer types */
|
---|
181 | # if !defined(_INTMAX_T_DECLARED) && !defined(_INTMAX_T)
|
---|
182 | typedef int64_t intmax_t;
|
---|
183 | # endif
|
---|
184 | # if !defined(_UINTMAX_T_DECLARED) && !defined(_UINTMAX_T)
|
---|
185 | typedef uint64_t uintmax_t;
|
---|
186 | # endif
|
---|
187 |
|
---|
188 | /* smallest minimum-width integer types - assumes to be the same as above! */
|
---|
189 | typedef int8_t int_least8_t;
|
---|
190 | typedef uint8_t uint_least8_t;
|
---|
191 | # define INT_LEAST8_MIN INT8_MIN
|
---|
192 | # define INT_LEAST8_MAX INT8_MAX
|
---|
193 | # define UINT_LEAST8_MAX UINT8_MAX
|
---|
194 | typedef int16_t int_least16_t;
|
---|
195 | typedef uint16_t uint_least16_t;
|
---|
196 | # define INT_LEAST16_MIN INT16_MIN
|
---|
197 | # define INT_LEAST16_MAX INT16_MAX
|
---|
198 | # define UINT_LEAST16_MAX UINT16_MAX
|
---|
199 | typedef int32_t int_least32_t;
|
---|
200 | typedef uint32_t uint_least32_t;
|
---|
201 | # define INT_LEAST32_MIN INT32_MIN
|
---|
202 | # define INT_LEAST32_MAX INT32_MAX
|
---|
203 | # define UINT_LEAST32_MAX UINT32_MAX
|
---|
204 | typedef int64_t int_least64_t;
|
---|
205 | typedef uint64_t uint_least64_t;
|
---|
206 | # define INT_LEAST64_MIN INT64_MIN
|
---|
207 | # define INT_LEAST64_MAX INT64_MAX
|
---|
208 | # define UINT_LEAST64_MAX UINT64_MAX
|
---|
209 |
|
---|
210 | /* fastest minimum-width integer types */
|
---|
211 | typedef signed char int_fast8_t;
|
---|
212 | typedef unsigned char uint_fast8_t;
|
---|
213 | # define INT_FAST8_MIN INT8_MIN
|
---|
214 | # define INT_FAST8_MAX INT8_MAX
|
---|
215 | # define UINT_FAST8_MAX UINT8_MAX
|
---|
216 | typedef signed int int_fast16_t;
|
---|
217 | typedef unsigned int uint_fast16_t;
|
---|
218 | # if ARCH_BITS == 16
|
---|
219 | # define INT_FAST16_MIN INT16_MIN
|
---|
220 | # define INT_FAST16_MAX INT16_MAX
|
---|
221 | # define UINT_FAST16_MAX UINT16_MAX
|
---|
222 | # else
|
---|
223 | # define INT_FAST16_MIN INT32_MIN
|
---|
224 | # define INT_FAST16_MAX INT32_MAX
|
---|
225 | # define UINT_FAST16_MAX UINT32_MAX
|
---|
226 | # endif
|
---|
227 | typedef int32_t int_fast32_t;
|
---|
228 | typedef uint32_t uint_fast32_t;
|
---|
229 | # define INT_FAST32_MIN INT32_MIN
|
---|
230 | # define INT_FAST32_MAX INT32_MAX
|
---|
231 | # define UINT_FAST32_MAX UINT32_MAX
|
---|
232 | typedef int64_t int_fast64_t;
|
---|
233 | typedef uint64_t uint_fast64_t;
|
---|
234 | # define INT_FAST64_MIN INT64_MIN
|
---|
235 | # define INT_FAST64_MAX INT64_MAX
|
---|
236 | # define UINT_FAST64_MAX UINT64_MAX
|
---|
237 |
|
---|
238 | # else
|
---|
239 | # error "PORTME: Add architecture. Don't forget to check the [U]INTx_C() and [U]INTMAX_MIN/MAX macros."
|
---|
240 | # endif
|
---|
241 |
|
---|
242 | # endif /* !linux kernel or stuff */
|
---|
243 |
|
---|
244 | /* pointer <-> integer types */
|
---|
245 | # if (!defined(_MSC_VER) && !defined(__WATCOMC__)) || defined(DOXYGEN_RUNNING)
|
---|
246 | # if ARCH_BITS == 32 \
|
---|
247 | || defined(RT_OS_LINUX) \
|
---|
248 | || defined(RT_OS_FREEBSD)
|
---|
249 | # if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
|
---|
250 | typedef signed long intptr_t;
|
---|
251 | # endif
|
---|
252 | # if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
|
---|
253 | typedef unsigned long uintptr_t;
|
---|
254 | # endif
|
---|
255 | # else
|
---|
256 | # if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T) && !defined(_INTPTR_T_DEFINED)
|
---|
257 | typedef int64_t intptr_t;
|
---|
258 | # endif
|
---|
259 | # if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T) && !defined(_UINTPTR_T_DEFINED)
|
---|
260 | typedef uint64_t uintptr_t;
|
---|
261 | # endif
|
---|
262 | # endif
|
---|
263 | # endif /* !_MSC_VER */
|
---|
264 |
|
---|
265 | #endif /* no system stdint.h */
|
---|
266 |
|
---|
267 |
|
---|
268 | /*
|
---|
269 | * Make sure the [U]INTx_C(c) macros are present.
|
---|
270 | * For In C++ source the system stdint.h may have skipped these if it was
|
---|
271 | * included before we managed to define __STDC_CONSTANT_MACROS. (Kludge alert!)
|
---|
272 | */
|
---|
273 | #if !defined(INT8_C) \
|
---|
274 | || !defined(INT16_C) \
|
---|
275 | || !defined(INT32_C) \
|
---|
276 | || !defined(INT64_C) \
|
---|
277 | || !defined(INTMAX_C) \
|
---|
278 | || !defined(UINT8_C) \
|
---|
279 | || !defined(UINT16_C) \
|
---|
280 | || !defined(UINT32_C) \
|
---|
281 | || !defined(UINT64_C) \
|
---|
282 | || !defined(UINTMAX_C)
|
---|
283 | # define INT8_C(Value) (Value)
|
---|
284 | # define INT16_C(Value) (Value)
|
---|
285 | # define UINT8_C(Value) (Value)
|
---|
286 | # define UINT16_C(Value) (Value)
|
---|
287 | # if ARCH_BITS != 16
|
---|
288 | # define INT32_C(Value) (Value)
|
---|
289 | # define UINT32_C(Value) (Value ## U)
|
---|
290 | # define INT64_C(Value) (Value ## LL)
|
---|
291 | # define UINT64_C(Value) (Value ## ULL)
|
---|
292 | # else
|
---|
293 | # define INT32_C(Value) (Value ## L)
|
---|
294 | # define UINT32_C(Value) (Value ## UL)
|
---|
295 | # define INT64_C(Value) (Value ## LL)
|
---|
296 | # define UINT64_C(Value) (Value ## ULL)
|
---|
297 | # endif
|
---|
298 | # define INTMAX_C(Value) INT64_C(Value)
|
---|
299 | # define UINTMAX_C(Value) UINT64_C(Value)
|
---|
300 | #endif
|
---|
301 |
|
---|
302 |
|
---|
303 | /*
|
---|
304 | * Make sure the INTx_MIN and [U]INTx_MAX macros are present.
|
---|
305 | * For In C++ source the system stdint.h may have skipped these if it was
|
---|
306 | * included before we managed to define __STDC_LIMIT_MACROS. (Kludge alert!)
|
---|
307 | */
|
---|
308 | #if !defined(INT8_MIN) \
|
---|
309 | || !defined(INT16_MIN) \
|
---|
310 | || !defined(INT32_MIN) \
|
---|
311 | || !defined(INT64_MIN) \
|
---|
312 | || !defined(INT8_MAX) \
|
---|
313 | || !defined(INT16_MAX) \
|
---|
314 | || !defined(INT32_MAX) \
|
---|
315 | || !defined(INT64_MAX) \
|
---|
316 | || !defined(UINT8_MAX) \
|
---|
317 | || !defined(UINT16_MAX) \
|
---|
318 | || !defined(UINT32_MAX) \
|
---|
319 | || !defined(UINT64_MAX)
|
---|
320 | # define INT8_MIN (INT8_C(-0x7f) - 1)
|
---|
321 | # define INT16_MIN (INT16_C(-0x7fff) - 1)
|
---|
322 | # define INT32_MIN (INT32_C(-0x7fffffff) - 1)
|
---|
323 | # define INT64_MIN (INT64_C(-0x7fffffffffffffff) - 1)
|
---|
324 | # define INT8_MAX INT8_C(0x7f)
|
---|
325 | # define INT16_MAX INT16_C(0x7fff)
|
---|
326 | # define INT32_MAX INT32_C(0x7fffffff)
|
---|
327 | # define INT64_MAX INT64_C(0x7fffffffffffffff)
|
---|
328 | # define UINT8_MAX UINT8_C(0xff)
|
---|
329 | # define UINT16_MAX UINT16_C(0xffff)
|
---|
330 | # define UINT32_MAX UINT32_C(0xffffffff)
|
---|
331 | # define UINT64_MAX UINT64_C(0xffffffffffffffff)
|
---|
332 |
|
---|
333 | # define INTMAX_MIN INT64_MIN
|
---|
334 | # define INTMAX_MAX INT64_MAX
|
---|
335 | # define UINTMAX_MAX UINT64_MAX
|
---|
336 | #endif
|
---|
337 |
|
---|
338 | #endif /* !IPRT_INCLUDED_stdint_h */
|
---|
339 |
|
---|