VirtualBox

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

Last change on this file since 35199 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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