Forward port changelog
[tor.git] / src / common / torint.h
blob7bebb1009dc2215b3285510d462c675edbc9f715
1 /* Copyright 2003 Roger Dingledine */
2 /* See LICENSE for licensing information */
3 /* $Id$ */
5 /**
6 * \file torint.h
7 * \brief Header file to define uint32_t and friends
8 **/
10 #ifndef __TORINT_H
11 #define __TORINT_H
12 #define TORINT_H_ID "$Id$"
14 #include "orconfig.h"
16 #ifdef HAVE_STDINT_H
17 #include <stdint.h>
18 #endif
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
21 #endif
22 #ifdef HAVE_LIMITS_H
23 #include <limits.h>
24 #endif
25 #ifdef HAVE_SYS_LIMITS_H
26 #include <sys/limits.h>
27 #endif
28 #ifdef HAVE_MACHINE_LIMITS_H
29 #ifndef __FreeBSD__
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
32 I include both. */
33 #include <machine/limits.h>
34 #endif
35 #endif
37 #if (SIZEOF_INT8_T != 0)
38 #define HAVE_INT8_T
39 #endif
40 #if (SIZEOF_INT16_T != 0)
41 #define HAVE_INT16_T
42 #endif
43 #if (SIZEOF_INT32_T != 0)
44 #define HAVE_INT32_T
45 #endif
46 #if (SIZEOF_INT64_T != 0)
47 #define HAVE_INT64_T
48 #endif
49 #if (SIZEOF_UINT8_T != 0)
50 #define HAVE_UINT8_T
51 #endif
52 #if (SIZEOF_UINT16_T != 0)
53 #define HAVE_UINT16_T
54 #endif
55 #if (SIZEOF_UINT32_T != 0)
56 #define HAVE_UINT32_T
57 #endif
58 #if (SIZEOF_UINT64_T != 0)
59 #define HAVE_UINT64_T
60 #endif
61 #if (SIZEOF_INTPTR_T != 0)
62 #define HAVE_INTPTR_T
63 #endif
64 #if (SIZEOF_UINTPTR_T != 0)
65 #define HAVE_UINTPTR_T
66 #endif
68 #if (SIZEOF_CHAR == 1)
69 #ifndef HAVE_INT8_T
70 typedef signed char int8_t;
71 #define HAVE_INT8_T
72 #endif
73 #ifndef HAVE_UINT8_T
74 typedef unsigned char uint8_t;
75 #define HAVE_UINT8_T
76 #endif
77 #endif
79 #if (SIZEOF_SHORT == 2)
80 #ifndef HAVE_INT16_T
81 typedef signed short int16_t;
82 #define HAVE_INT16_T
83 #endif
84 #ifndef HAVE_UINT16_T
85 typedef unsigned short uint16_t;
86 #define HAVE_UINT16_T
87 #endif
88 #endif
90 #if (SIZEOF_INT == 2)
91 #ifndef HAVE_INT16_T
92 typedef signed int int16_t;
93 #define HAVE_INT16_T
94 #endif
95 #ifndef HAVE_UINT16_T
96 typedef unsigned int uint16_t;
97 #define HAVE_UINT16_T
98 #endif
99 #elif (SIZEOF_INT == 4)
100 #ifndef HAVE_INT32_T
101 typedef signed int int32_t;
102 #define HAVE_INT32_T
103 #endif
104 #ifndef HAVE_UINT32_T
105 typedef unsigned int uint32_t;
106 #define HAVE_UINT32_T
107 #endif
108 #ifndef UINT32_MAX
109 #define UINT32_MAX 0xffffffffu
110 #endif
111 #endif
113 #if (SIZEOF_LONG == 4)
114 #ifndef HAVE_INT32_T
115 typedef signed long int32_t;
116 #define HAVE_INT32_T
117 #endif
118 #ifndef HAVE_UINT32_T
119 typedef unsigned long uint32_t;
120 #define HAVE_UINT32_T
121 #ifndef UINT32_MAX
122 #define UINT32_MAX 0xfffffffful
123 #endif
124 #endif
125 #elif (SIZEOF_LONG == 8)
126 #ifndef HAVE_INT64_T
127 typedef signed long int64_t;
128 #define HAVE_INT64_T
129 #endif
130 #ifndef HAVE_UINT32_T
131 typedef unsigned long uint64_t;
132 #define HAVE_UINT32_T
133 #endif
134 #ifndef UINT64_MAX
135 #define UINT64_MAX 0xfffffffffffffffful
136 #endif
137 #endif
139 #if (SIZEOF_LONG_LONG == 8)
140 #ifndef HAVE_INT64_T
141 typedef signed long long int64_t;
142 #define HAVE_INT64_T
143 #endif
144 #ifndef HAVE_UINT64_T
145 typedef unsigned long long uint64_t;
146 #define HAVE_UINT64_T
147 #endif
148 #ifndef UINT64_MAX
149 #define UINT64_MAX 0xffffffffffffffffull
150 #endif
151 #endif
153 #if (SIZEOF___INT64 == 8)
154 #ifndef HAVE_INT64_T
155 typedef signed __int64 int64_t;
156 #define HAVE_INT64_T
157 #endif
158 #ifndef HAVE_UINT64_T
159 typedef unsigned __int64 uint64_t;
160 #define HAVE_UINT64_T
161 #endif
162 #ifndef UINT64_MAX
163 #define UINT64_MAX 0xffffffffffffffffui64
164 #endif
165 #endif
167 #if (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8)
168 #ifndef HAVE_INTPTR_T
169 typedef int64_t intptr_t;
170 #endif
171 #ifndef HAVE_UINTPTR_T
172 typedef uint64_t uintptr_t;
173 #endif
174 #elif (SIZEOF_VOID_P > 2 && SIZEOF_VOID_P <= 4)
175 #ifndef HAVE_INTPTR_T
176 typedef int32_t intptr_t;
177 #endif
178 #ifndef HAVE_UINTPTR_T
179 typedef uint32_t uintptr_t;
180 #endif
181 #else
182 #error "void * is either >8 bytes or <= 2. In either case, I am confused."
183 #endif
185 #ifndef HAVE_INT8_T
186 #error "Missing type int8_t"
187 #endif
188 #ifndef HAVE_UINT8_T
189 #error "Missing type uint8_t"
190 #endif
191 #ifndef HAVE_INT16_T
192 #error "Missing type int16_t"
193 #endif
194 #ifndef HAVE_UINT16_T
195 #error "Missing type uint16_t"
196 #endif
197 #ifndef HAVE_INT32_T
198 #error "Missing type int32_t"
199 #endif
200 #ifndef HAVE_UINT32_T
201 #error "Missing type uint32_t"
202 #endif
203 #ifndef HAVE_INT64_T
204 #error "Missing type int64_t"
205 #endif
206 #ifndef HAVE_UINT64_T
207 #error "Missing type uint64_t"
208 #endif
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. */
213 #ifndef LONG_MAX
214 #if (SIZEOF_LONG == 4)
215 #define LONG_MAX 0x7fffffffL
216 #elif (SIZEOF_LONG == 8)
217 #define LONG_MAX 0x7fffffffffffffffL
218 #else
219 #error "Can't define LONG_MAX"
220 #endif
221 #endif
223 #ifndef UINT_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
230 #else
231 #error "Can't define UINT_MAX"
232 #endif
233 #endif
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 */