1 | /** @file
|
---|
2 | * IPRT - stdint.h wrapper (for backlevel compilers like MSC).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | *
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef __iprt_stdint_h
|
---|
32 | #define __iprt_stdint_h
|
---|
33 |
|
---|
34 | #include <iprt/cdefs.h>
|
---|
35 |
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * Use the stdint.h on systems that have one.
|
---|
39 | */
|
---|
40 | #if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
|
---|
41 | && !defined(_MSC_VER) \
|
---|
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 | # include <stdint.h>
|
---|
55 |
|
---|
56 | # if defined(RT_OS_DARWIN) && defined(KERNEL) && defined(RT_ARCH_AMD64)
|
---|
57 | /*
|
---|
58 | * Kludge to fix the incorrect 32-bit constant macros in
|
---|
59 | * Kernel.framework/Headers/stdin.h. uint32_t and int32_t are
|
---|
60 | * int not long as these macros use, which is significant when
|
---|
61 | * targeting AMD64. (10a222)
|
---|
62 | */
|
---|
63 | # undef INT32_C
|
---|
64 | # define INT32_C(Value) (Value)
|
---|
65 | # undef UINT32_C
|
---|
66 | # define UINT32_C(Value) (Value ## U)
|
---|
67 | # endif /* 64-bit darwin kludge. */
|
---|
68 |
|
---|
69 | #else /* No system stdint.h */
|
---|
70 |
|
---|
71 | /*
|
---|
72 | * Define the types we use.
|
---|
73 | * The linux kernel defines all these in linux/types.h, so skip it.
|
---|
74 | */
|
---|
75 | # if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
|
---|
76 | || defined(IPRT_NO_CRT) \
|
---|
77 | || defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
|
---|
78 | || defined(DOXGEN_RUNNING)
|
---|
79 |
|
---|
80 | /* Simplify the [u]int64_t type detection mess. */
|
---|
81 | # undef IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
|
---|
82 | # ifdef __IBMCPP__
|
---|
83 | # if __IBMCPP__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
|
---|
84 | # defined IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
|
---|
85 | # endif
|
---|
86 | # endif
|
---|
87 | # ifdef __IBMC__
|
---|
88 | # if __IBMC__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
|
---|
89 | # defined IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
|
---|
90 | # endif
|
---|
91 | # endif
|
---|
92 |
|
---|
93 | /* x-bit types */
|
---|
94 | # if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
95 | # if !defined(_INT8_T_DECLARED) && !defined(_INT8_T)
|
---|
96 | typedef signed char int8_t;
|
---|
97 | # endif
|
---|
98 | # if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T)
|
---|
99 | typedef unsigned char uint8_t;
|
---|
100 | # endif
|
---|
101 | # if !defined(_INT16_T_DECLARED) && !defined(_INT16_T)
|
---|
102 | typedef signed short int16_t;
|
---|
103 | # endif
|
---|
104 | # if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T)
|
---|
105 | typedef unsigned short uint16_t;
|
---|
106 | # endif
|
---|
107 | # if !defined(_INT32_T_DECLARED) && !defined(_INT32_T)
|
---|
108 | typedef signed int int32_t;
|
---|
109 | # endif
|
---|
110 | # if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T)
|
---|
111 | typedef unsigned int uint32_t;
|
---|
112 | # endif
|
---|
113 | # if defined(_MSC_VER)
|
---|
114 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
|
---|
115 | typedef signed _int64 int64_t;
|
---|
116 | # endif
|
---|
117 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
|
---|
118 | typedef unsigned _int64 uint64_t;
|
---|
119 | # endif
|
---|
120 | # elif defined(IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES)
|
---|
121 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
|
---|
122 | typedef struct { uint32_t lo; int32_t hi; } int64_t;
|
---|
123 | # endif
|
---|
124 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
|
---|
125 | typedef struct { uint32_t lo; uint32_t hi; } uint64_t;
|
---|
126 | # endif
|
---|
127 | # else /* Use long long for 64-bit types */
|
---|
128 | # if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
|
---|
129 | typedef signed long long int64_t;
|
---|
130 | # endif
|
---|
131 | # if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
|
---|
132 | typedef unsigned long long uint64_t;
|
---|
133 | # endif
|
---|
134 | # endif
|
---|
135 |
|
---|
136 | /* max integer types */
|
---|
137 | # if !defined(_INTMAX_T_DECLARED) && !defined(_INTMAX_T)
|
---|
138 | typedef int64_t intmax_t;
|
---|
139 | # endif
|
---|
140 | # if !defined(_UINTMAX_T_DECLARED) && !defined(_UINTMAX_T)
|
---|
141 | typedef uint64_t uintmax_t;
|
---|
142 | # endif
|
---|
143 |
|
---|
144 | # else
|
---|
145 | # error "PORTME: Add architecture. Don't forget to check the [U]INTx_C() and [U]INTMAX_MIN/MAX macros."
|
---|
146 | # endif
|
---|
147 |
|
---|
148 | # endif /* !linux kernel or stuff */
|
---|
149 |
|
---|
150 | /* pointer <-> integer types */
|
---|
151 | # if !defined(_MSC_VER) || defined(DOXYGEN_RUNNING)
|
---|
152 | # if ARCH_BITS == 32 \
|
---|
153 | || defined(RT_OS_LINUX) \
|
---|
154 | || defined(RT_OS_FREEBSD)
|
---|
155 | # if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T)
|
---|
156 | typedef signed long intptr_t;
|
---|
157 | # endif
|
---|
158 | # if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T)
|
---|
159 | typedef unsigned long uintptr_t;
|
---|
160 | # endif
|
---|
161 | # else
|
---|
162 | # if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T)
|
---|
163 | typedef int64_t intptr_t;
|
---|
164 | # endif
|
---|
165 | # if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T)
|
---|
166 | typedef uint64_t uintptr_t;
|
---|
167 | # endif
|
---|
168 | # endif
|
---|
169 | # endif /* !_MSC_VER */
|
---|
170 |
|
---|
171 | #endif /* no system stdint.h */
|
---|
172 |
|
---|
173 |
|
---|
174 | /*
|
---|
175 | * Make sure the [U]INTx_C(c) macros are present.
|
---|
176 | * For In C++ source the system stdint.h may have skipped these if it was
|
---|
177 | * included before we managed to define __STDC_CONSTANT_MACROS. (Kludge alert!)
|
---|
178 | */
|
---|
179 | #if !defined(INT8_C) \
|
---|
180 | || !defined(INT16_C) \
|
---|
181 | || !defined(INT32_C) \
|
---|
182 | || !defined(INT64_C) \
|
---|
183 | || !defined(INTMAX_C) \
|
---|
184 | || !defined(UINT8_C) \
|
---|
185 | || !defined(UINT16_C) \
|
---|
186 | || !defined(UINT32_C) \
|
---|
187 | || !defined(UINT64_C) \
|
---|
188 | || !defined(UINTMAX_C)
|
---|
189 | # define INT8_C(Value) (Value)
|
---|
190 | # define INT16_C(Value) (Value)
|
---|
191 | # define INT32_C(Value) (Value)
|
---|
192 | # define INT64_C(Value) (Value ## LL)
|
---|
193 | # define UINT8_C(Value) (Value)
|
---|
194 | # define UINT16_C(Value) (Value)
|
---|
195 | # define UINT32_C(Value) (Value ## U)
|
---|
196 | # define UINT64_C(Value) (Value ## ULL)
|
---|
197 | # define INTMAX_C(Value) INT64_C(Value)
|
---|
198 | # define UINTMAX_C(Value) UINT64_C(Value)
|
---|
199 | #endif
|
---|
200 |
|
---|
201 |
|
---|
202 | /*
|
---|
203 | * Make sure the INTx_MIN and [U]INTx_MAX macros are present.
|
---|
204 | * For In C++ source the system stdint.h may have skipped these if it was
|
---|
205 | * included before we managed to define __STDC_LIMIT_MACROS. (Kludge alert!)
|
---|
206 | */
|
---|
207 | #if !defined(INT8_MIN) \
|
---|
208 | || !defined(INT16_MIN) \
|
---|
209 | || !defined(INT32_MIN) \
|
---|
210 | || !defined(INT64_MIN) \
|
---|
211 | || !defined(INT8_MAX) \
|
---|
212 | || !defined(INT16_MAX) \
|
---|
213 | || !defined(INT32_MAX) \
|
---|
214 | || !defined(INT64_MAX) \
|
---|
215 | || !defined(UINT8_MAX) \
|
---|
216 | || !defined(UINT16_MAX) \
|
---|
217 | || !defined(UINT32_MAX) \
|
---|
218 | || !defined(UINT64_MAX)
|
---|
219 | # define INT8_MIN (INT8_C(-0x7f) - 1)
|
---|
220 | # define INT16_MIN (INT16_C(-0x7fff) - 1)
|
---|
221 | # define INT32_MIN (INT32_C(-0x7fffffff) - 1)
|
---|
222 | # define INT64_MIN (INT64_C(-0x7fffffffffffffff) - 1)
|
---|
223 | # define INT8_MAX INT8_C(0x7f)
|
---|
224 | # define INT16_MAX INT16_C(0x7fff)
|
---|
225 | # define INT32_MAX INT32_C(0x7fffffff)
|
---|
226 | # define INT64_MAX INT64_C(0x7fffffffffffffff)
|
---|
227 | # define UINT8_MAX UINT8_C(0xff)
|
---|
228 | # define UINT16_MAX UINT16_C(0xffff)
|
---|
229 | # define UINT32_MAX UINT32_C(0xffffffff)
|
---|
230 | # define UINT64_MAX UINT64_C(0xffffffffffffffff)
|
---|
231 |
|
---|
232 | # define INTMAX_MIN INT64_MIN
|
---|
233 | # define INTMAX_MAX INT64_MAX
|
---|
234 | # define UINTMAX_MAX UINT64_MAX
|
---|
235 | #endif
|
---|
236 |
|
---|
237 | #endif
|
---|
238 |
|
---|