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