1 /* Copyright 2003 Roger Dingledine */
2 /* See LICENSE for licensing information */
7 * \brief Header file to define uint32_t and friends
12 #define TORINT_H_ID "$Id$"
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
25 #ifdef HAVE_SYS_LIMITS_H
26 #include <sys/limits.h>
28 #ifdef HAVE_MACHINE_LIMITS_H
30 /* FreeBSD has a bug where it complains that this file is obsolete,
31 and I should migrate to using sys/limits. It complains even when
33 #include <machine/limits.h>
37 #if (SIZEOF_INT8_T != 0)
40 #if (SIZEOF_INT16_T != 0)
43 #if (SIZEOF_INT32_T != 0)
46 #if (SIZEOF_INT64_T != 0)
49 #if (SIZEOF_UINT8_T != 0)
52 #if (SIZEOF_UINT16_T != 0)
55 #if (SIZEOF_UINT32_T != 0)
58 #if (SIZEOF_UINT64_T != 0)
61 #if (SIZEOF_INTPTR_T != 0)
64 #if (SIZEOF_UINTPTR_T != 0)
65 #define HAVE_UINTPTR_T
68 #if (SIZEOF_CHAR == 1)
70 typedef signed char int8_t;
74 typedef unsigned char uint8_t;
79 #if (SIZEOF_SHORT == 2)
81 typedef signed short int16_t;
85 typedef unsigned short uint16_t;
92 typedef signed int int16_t;
96 typedef unsigned int uint16_t;
99 #elif (SIZEOF_INT == 4)
101 typedef signed int int32_t;
104 #ifndef HAVE_UINT32_T
105 typedef unsigned int uint32_t;
106 #define HAVE_UINT32_T
109 #define UINT32_MAX 0xffffffffu
113 #if (SIZEOF_LONG == 4)
115 typedef signed long int32_t;
118 #ifndef HAVE_UINT32_T
119 typedef unsigned long uint32_t;
120 #define HAVE_UINT32_T
122 #define UINT32_MAX 0xfffffffful
125 #elif (SIZEOF_LONG == 8)
127 typedef signed long int64_t;
130 #ifndef HAVE_UINT32_T
131 typedef unsigned long uint64_t;
132 #define HAVE_UINT32_T
135 #define UINT64_MAX 0xfffffffffffffffful
139 #if (SIZEOF_LONG_LONG == 8)
141 typedef signed long long int64_t;
144 #ifndef HAVE_UINT64_T
145 typedef unsigned long long uint64_t;
146 #define HAVE_UINT64_T
149 #define UINT64_MAX 0xffffffffffffffffull
153 #if (SIZEOF___INT64 == 8)
155 typedef signed __int64
int64_t;
158 #ifndef HAVE_UINT64_T
159 typedef unsigned __int64
uint64_t;
160 #define HAVE_UINT64_T
163 #define UINT64_MAX 0xffffffffffffffffui64
167 #if (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8)
168 #ifndef HAVE_INTPTR_T
169 typedef int64_t intptr_t;
171 #ifndef HAVE_UINTPTR_T
172 typedef uint64_t uintptr_t;
174 #elif (SIZEOF_VOID_P > 2 && SIZEOF_VOID_P <= 4)
175 #ifndef HAVE_INTPTR_T
176 typedef int32_t intptr_t;
178 #ifndef HAVE_UINTPTR_T
179 typedef uint32_t uintptr_t;
182 #error "void * is either >8 bytes or <= 2. In either case, I am confused."
186 #error "Missing type int8_t"
189 #error "Missing type uint8_t"
192 #error "Missing type int16_t"
194 #ifndef HAVE_UINT16_T
195 #error "Missing type uint16_t"
198 #error "Missing type int32_t"
200 #ifndef HAVE_UINT32_T
201 #error "Missing type uint32_t"
204 #error "Missing type int64_t"
206 #ifndef HAVE_UINT64_T
207 #error "Missing type uint64_t"
210 /* XXXX This assumes a sane (2's-complement) representation. But if you
211 * aren't 2's complement, and you don't define LONG_MAX, then you're so
212 * bizarre that I want nothing to do with you. */
214 #if (SIZEOF_LONG == 4)
215 #define LONG_MAX 0x7fffffffL
216 #elif (SIZEOF_LONG == 8)
217 #define LONG_MAX 0x7fffffffffffffffL
219 #error "Can't define LONG_MAX"
224 #if (SIZEOF_INT == 2)
225 #define UINT_MAX 0xffffu
226 #elif (SIZEOF_INT == 4)
227 #define UINT_MAX 0xffffffffu
228 #elif (SIZEOF_INT == 8)
229 #define UINT_MAX 0xffffffffffffffffu
231 #error "Can't define UINT_MAX"
235 /* Any size_t larger than this amount is likely to be an underflow. */
236 #define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1))
238 #endif /* __TORINT_H */