VirtualBox

source: vbox/trunk/include/iprt/stdint.h@ 63413

Last change on this file since 63413 was 62943, checked in by vboxsync, 8 years ago

iptr/stdint.h: NetBSD support.
From Haomai Wang GSoC project with additional changes by Arto Huusko.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/** @file
2 * IPRT - stdint.h wrapper (for backlevel compilers like MSC).
3 */
4
5/*
6 * Copyright (C) 2009-2016 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_stdint_h
27#define __iprt_stdint_h
28
29#include <iprt/cdefs.h>
30
31
32/*
33 * Use the stdint.h on systems that have one.
34 */
35#if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
36 && !(defined(RT_OS_FREEBSD) && defined(_KERNEL)) \
37 && !(defined(RT_OS_NETBSD) && defined(_KERNEL)) \
38 && RT_MSC_PREREQ_EX(RT_MSC_VER_VS2010, 1 /*non-msc*/) \
39 && !defined(__IBMC__) \
40 && !defined(__IBMCPP__) \
41 && !defined(IPRT_NO_CRT) \
42 && !defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
43 && !defined(DOXYGEN_RUNNING)
44
45# ifndef __STDC_CONSTANT_MACROS
46# define __STDC_CONSTANT_MACROS
47# endif
48# ifndef __STDC_LIMIT_MACROS
49# define __STDC_LIMIT_MACROS
50# endif
51# ifdef _MSC_VER
52# pragma warning(push)
53# pragma warning(disable:4668)
54# endif
55# include <stdint.h>
56# ifdef _MSC_VER
57# pragma warning(pop)
58# endif
59
60# if defined(RT_OS_DARWIN) && defined(KERNEL) && defined(RT_ARCH_AMD64)
61 /*
62 * Kludge to fix the incorrect 32-bit constant macros in
63 * Kernel.framework/Headers/stdin.h. uint32_t and int32_t are
64 * int not long as these macros use, which is significant when
65 * targeting AMD64. (10a222)
66 */
67# undef INT32_C
68# define INT32_C(Value) (Value)
69# undef UINT32_C
70# define UINT32_C(Value) (Value ## U)
71# endif /* 64-bit darwin kludge. */
72
73#elif defined(RT_OS_FREEBSD) && defined(_KERNEL)
74
75# ifndef __STDC_CONSTANT_MACROS
76# define __STDC_CONSTANT_MACROS
77# endif
78# ifndef __STDC_LIMIT_MACROS
79# define __STDC_LIMIT_MACROS
80# endif
81# include <sys/stdint.h>
82
83#elif defined(RT_OS_NETBSD) && defined(_KERNEL)
84
85# ifndef __STDC_CONSTANT_MACROS
86# define __STDC_CONSTANT_MACROS
87# endif
88# ifndef __STDC_LIMIT_MACROS
89# define __STDC_LIMIT_MACROS
90# endif
91# include <sys/stdint.h>
92
93#else /* No system stdint.h */
94
95/*
96 * Define the types we use.
97 * The linux kernel defines all these in linux/types.h, so skip it.
98 */
99# if !(defined(RT_OS_LINUX) && defined(__KERNEL__)) \
100 || defined(IPRT_NO_CRT) \
101 || defined(IPRT_DONT_USE_SYSTEM_STDINT_H) \
102 || defined(DOXGEN_RUNNING)
103
104 /* Simplify the [u]int64_t type detection mess. */
105# undef IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
106# ifdef __IBMCPP__
107# if __IBMCPP__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
108# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
109# endif
110# endif
111# ifdef __IBMC__
112# if __IBMC__ < 350 && (defined(__WINDOWS__) || defined(_AIX) || defined(__OS2__))
113# define IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES
114# endif
115# endif
116
117 /* x-bit types */
118# if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86) || defined(RT_ARCH_SPARC) || defined(RT_ARCH_SPARC64)
119# if !defined(_INT8_T_DECLARED) && !defined(_INT8_T)
120typedef signed char int8_t;
121# endif
122# if !defined(_UINT8_T_DECLARED) && !defined(_UINT8_T)
123typedef unsigned char uint8_t;
124# endif
125# if !defined(_INT16_T_DECLARED) && !defined(_INT16_T)
126typedef signed short int16_t;
127# endif
128# if !defined(_UINT16_T_DECLARED) && !defined(_UINT16_T)
129typedef unsigned short uint16_t;
130# endif
131# if !defined(_INT32_T_DECLARED) && !defined(_INT32_T)
132# if ARCH_BITS != 16
133typedef signed int int32_t;
134# else
135typedef signed long int32_t;
136# endif
137# endif
138# if !defined(_UINT32_T_DECLARED) && !defined(_UINT32_T)
139# if ARCH_BITS != 16
140typedef unsigned int uint32_t;
141# else
142typedef unsigned long uint32_t;
143# endif
144# endif
145# if defined(_MSC_VER)
146# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
147typedef signed _int64 int64_t;
148# endif
149# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
150typedef unsigned _int64 uint64_t;
151# endif
152# elif defined(__WATCOMC__)
153# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
154typedef signed __int64 int64_t;
155# endif
156# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
157typedef unsigned __int64 uint64_t;
158# endif
159# elif defined(IPRT_STDINT_USE_STRUCT_FOR_64_BIT_TYPES)
160# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
161typedef struct { uint32_t lo; int32_t hi; } int64_t;
162# endif
163# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
164typedef struct { uint32_t lo; uint32_t hi; } uint64_t;
165# endif
166# else /* Use long long for 64-bit types */
167# if !defined(_INT64_T_DECLARED) && !defined(_INT64_T)
168typedef signed long long int64_t;
169# endif
170# if !defined(_UINT64_T_DECLARED) && !defined(_UINT64_T)
171typedef unsigned long long uint64_t;
172# endif
173# endif
174
175 /* max integer types */
176# if !defined(_INTMAX_T_DECLARED) && !defined(_INTMAX_T)
177typedef int64_t intmax_t;
178# endif
179# if !defined(_UINTMAX_T_DECLARED) && !defined(_UINTMAX_T)
180typedef uint64_t uintmax_t;
181# endif
182
183# else
184# error "PORTME: Add architecture. Don't forget to check the [U]INTx_C() and [U]INTMAX_MIN/MAX macros."
185# endif
186
187# endif /* !linux kernel or stuff */
188
189 /* pointer <-> integer types */
190# if !defined(_MSC_VER) || defined(DOXYGEN_RUNNING)
191# if ARCH_BITS == 32 \
192 || defined(RT_OS_LINUX) \
193 || defined(RT_OS_FREEBSD)
194# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T)
195typedef signed long intptr_t;
196# endif
197# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T)
198typedef unsigned long uintptr_t;
199# endif
200# else
201# if !defined(_INTPTR_T_DECLARED) && !defined(_INTPTR_T)
202typedef int64_t intptr_t;
203# endif
204# if !defined(_UINTPTR_T_DECLARED) && !defined(_UINTPTR_T)
205typedef uint64_t uintptr_t;
206# endif
207# endif
208# endif /* !_MSC_VER */
209
210#endif /* no system stdint.h */
211
212
213/*
214 * Make sure the [U]INTx_C(c) macros are present.
215 * For In C++ source the system stdint.h may have skipped these if it was
216 * included before we managed to define __STDC_CONSTANT_MACROS. (Kludge alert!)
217 */
218#if !defined(INT8_C) \
219 || !defined(INT16_C) \
220 || !defined(INT32_C) \
221 || !defined(INT64_C) \
222 || !defined(INTMAX_C) \
223 || !defined(UINT8_C) \
224 || !defined(UINT16_C) \
225 || !defined(UINT32_C) \
226 || !defined(UINT64_C) \
227 || !defined(UINTMAX_C)
228# define INT8_C(Value) (Value)
229# define INT16_C(Value) (Value)
230# define UINT8_C(Value) (Value)
231# define UINT16_C(Value) (Value)
232# if ARCH_BITS != 16
233# define INT32_C(Value) (Value)
234# define UINT32_C(Value) (Value ## U)
235# define INT64_C(Value) (Value ## LL)
236# define UINT64_C(Value) (Value ## ULL)
237# else
238# define INT32_C(Value) (Value ## L)
239# define UINT32_C(Value) (Value ## UL)
240# define INT64_C(Value) (Value ## LL)
241# define UINT64_C(Value) (Value ## ULL)
242# endif
243# define INTMAX_C(Value) INT64_C(Value)
244# define UINTMAX_C(Value) UINT64_C(Value)
245#endif
246
247
248/*
249 * Make sure the INTx_MIN and [U]INTx_MAX macros are present.
250 * For In C++ source the system stdint.h may have skipped these if it was
251 * included before we managed to define __STDC_LIMIT_MACROS. (Kludge alert!)
252 */
253#if !defined(INT8_MIN) \
254 || !defined(INT16_MIN) \
255 || !defined(INT32_MIN) \
256 || !defined(INT64_MIN) \
257 || !defined(INT8_MAX) \
258 || !defined(INT16_MAX) \
259 || !defined(INT32_MAX) \
260 || !defined(INT64_MAX) \
261 || !defined(UINT8_MAX) \
262 || !defined(UINT16_MAX) \
263 || !defined(UINT32_MAX) \
264 || !defined(UINT64_MAX)
265# define INT8_MIN (INT8_C(-0x7f) - 1)
266# define INT16_MIN (INT16_C(-0x7fff) - 1)
267# define INT32_MIN (INT32_C(-0x7fffffff) - 1)
268# define INT64_MIN (INT64_C(-0x7fffffffffffffff) - 1)
269# define INT8_MAX INT8_C(0x7f)
270# define INT16_MAX INT16_C(0x7fff)
271# define INT32_MAX INT32_C(0x7fffffff)
272# define INT64_MAX INT64_C(0x7fffffffffffffff)
273# define UINT8_MAX UINT8_C(0xff)
274# define UINT16_MAX UINT16_C(0xffff)
275# define UINT32_MAX UINT32_C(0xffffffff)
276# define UINT64_MAX UINT64_C(0xffffffffffffffff)
277
278# define INTMAX_MIN INT64_MIN
279# define INTMAX_MAX INT64_MAX
280# define UINTMAX_MAX UINT64_MAX
281#endif
282
283#endif
284
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette