00001
00002
00003
00004
00005
00011 #ifndef _TOR_TORINT_H
00012 #define _TOR_TORINT_H
00013
00014 #include "orconfig.h"
00015
00016 #ifdef HAVE_STDINT_H
00017 #include <stdint.h>
00018 #endif
00019 #ifdef HAVE_SYS_TYPES_H
00020 #include <sys/types.h>
00021 #endif
00022 #ifdef HAVE_LIMITS_H
00023 #include <limits.h>
00024 #endif
00025 #ifdef HAVE_SYS_LIMITS_H
00026 #include <sys/limits.h>
00027 #endif
00028 #ifdef HAVE_MACHINE_LIMITS_H
00029 #if !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__)
00030
00031
00032
00033
00034
00035
00036 #include <machine/limits.h>
00037 #endif
00038 #endif
00039 #ifdef HAVE_INTTYPES_H
00040 #include <inttypes.h>
00041 #endif
00042
00043 #if (SIZEOF_INT8_T != 0)
00044 #define HAVE_INT8_T
00045 #endif
00046 #if (SIZEOF_INT16_T != 0)
00047 #define HAVE_INT16_T
00048 #endif
00049 #if (SIZEOF_INT32_T != 0)
00050 #define HAVE_INT32_T
00051 #endif
00052 #if (SIZEOF_INT64_T != 0)
00053 #define HAVE_INT64_T
00054 #endif
00055 #if (SIZEOF_UINT8_T != 0)
00056 #define HAVE_UINT8_T
00057 #endif
00058 #if (SIZEOF_UINT16_T != 0)
00059 #define HAVE_UINT16_T
00060 #endif
00061 #if (SIZEOF_UINT32_T != 0)
00062 #define HAVE_UINT32_T
00063 #endif
00064 #if (SIZEOF_UINT64_T != 0)
00065 #define HAVE_UINT64_T
00066 #endif
00067 #if (SIZEOF_INTPTR_T != 0)
00068 #define HAVE_INTPTR_T
00069 #endif
00070 #if (SIZEOF_UINTPTR_T != 0)
00071 #define HAVE_UINTPTR_T
00072 #endif
00073
00074 #if (SIZEOF_CHAR == 1)
00075 #ifndef HAVE_INT8_T
00076 typedef signed char int8_t;
00077 #define HAVE_INT8_T
00078 #endif
00079 #ifndef HAVE_UINT8_T
00080 typedef unsigned char uint8_t;
00081 #define HAVE_UINT8_T
00082 #endif
00083 #endif
00084
00085 #if (SIZEOF_SHORT == 2)
00086 #ifndef HAVE_INT16_T
00087 typedef signed short int16_t;
00088 #define HAVE_INT16_T
00089 #endif
00090 #ifndef HAVE_UINT16_T
00091 typedef unsigned short uint16_t;
00092 #define HAVE_UINT16_T
00093 #endif
00094 #endif
00095
00096 #if (SIZEOF_INT == 2)
00097 #ifndef HAVE_INT16_T
00098 typedef signed int int16_t;
00099 #define HAVE_INT16_T
00100 #endif
00101 #ifndef HAVE_UINT16_T
00102 typedef unsigned int uint16_t;
00103 #define HAVE_UINT16_T
00104 #endif
00105 #elif (SIZEOF_INT == 4)
00106 #ifndef HAVE_INT32_T
00107 typedef signed int int32_t;
00108 #define HAVE_INT32_T
00109 #endif
00110 #ifndef HAVE_UINT32_T
00111 typedef unsigned int uint32_t;
00112 #define HAVE_UINT32_T
00113 #endif
00114 #ifndef UINT32_MAX
00115 #define UINT32_MAX 0xffffffffu
00116 #endif
00117 #ifndef INT32_MAX
00118 #define INT32_MAX 0x7fffffffu
00119 #endif
00120 #ifndef INT32_MIN
00121 #define INT32_MIN (-2147483647-1)
00122 #endif
00123 #endif
00124
00125 #if (SIZEOF_LONG == 4)
00126 #ifndef HAVE_INT32_T
00127 typedef signed long int32_t;
00128 #define HAVE_INT32_T
00129 #endif
00130 #ifndef HAVE_UINT32_T
00131 typedef unsigned long uint32_t;
00132 #define HAVE_UINT32_T
00133 #ifndef UINT32_MAX
00134 #define UINT32_MAX 0xfffffffful
00135 #endif
00136 #endif
00137 #elif (SIZEOF_LONG == 8)
00138 #ifndef HAVE_INT64_T
00139 typedef signed long int64_t;
00140 #define HAVE_INT64_T
00141 #endif
00142 #ifndef HAVE_UINT32_T
00143 typedef unsigned long uint64_t;
00144 #define HAVE_UINT32_T
00145 #endif
00146 #ifndef UINT64_MAX
00147 #define UINT64_MAX 0xfffffffffffffffful
00148 #endif
00149 #endif
00150
00151 #if (SIZEOF_LONG_LONG == 8)
00152 #ifndef HAVE_INT64_T
00153 typedef signed long long int64_t;
00154 #define HAVE_INT64_T
00155 #endif
00156 #ifndef HAVE_UINT64_T
00157 typedef unsigned long long uint64_t;
00158 #define HAVE_UINT64_T
00159 #endif
00160 #ifndef UINT64_MAX
00161 #define UINT64_MAX 0xffffffffffffffffull
00162 #endif
00163 #ifndef INT64_MAX
00164 #define INT64_MAX 0x7fffffffffffffffll
00165 #endif
00166 #endif
00167
00168 #if (SIZEOF___INT64 == 8)
00169 #ifndef HAVE_INT64_T
00170 typedef signed __int64 int64_t;
00171 #define HAVE_INT64_T
00172 #endif
00173 #ifndef HAVE_UINT64_T
00174 typedef unsigned __int64 uint64_t;
00175 #define HAVE_UINT64_T
00176 #endif
00177 #ifndef UINT64_MAX
00178 #define UINT64_MAX 0xffffffffffffffffui64
00179 #endif
00180 #ifndef INT64_MAX
00181 #define INT64_MAX 0x7fffffffffffffffi64
00182 #endif
00183 #endif
00184
00185 #ifndef HAVE_SSIZE_T
00186 #if SIZEOF_SIZE_T == 8
00187 typedef int64_t ssize_t;
00188 #elif SIZEOF_SIZE_T == 4
00189 typedef int32_t ssize_t;
00190 #else
00191 #error "Can't define ssize_t."
00192 #endif
00193 #endif
00194
00195 #if (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8)
00196 #ifndef HAVE_INTPTR_T
00197 typedef int64_t intptr_t;
00198 #endif
00199 #ifndef HAVE_UINTPTR_T
00200 typedef uint64_t uintptr_t;
00201 #endif
00202 #elif (SIZEOF_VOID_P > 2 && SIZEOF_VOID_P <= 4)
00203 #ifndef HAVE_INTPTR_T
00204 typedef int32_t intptr_t;
00205 #endif
00206 #ifndef HAVE_UINTPTR_T
00207 typedef uint32_t uintptr_t;
00208 #endif
00209 #else
00210 #error "void * is either >8 bytes or <= 2. In either case, I am confused."
00211 #endif
00212
00213 #ifndef HAVE_INT8_T
00214 #error "Missing type int8_t"
00215 #endif
00216 #ifndef HAVE_UINT8_T
00217 #error "Missing type uint8_t"
00218 #endif
00219 #ifndef HAVE_INT16_T
00220 #error "Missing type int16_t"
00221 #endif
00222 #ifndef HAVE_UINT16_T
00223 #error "Missing type uint16_t"
00224 #endif
00225 #ifndef HAVE_INT32_T
00226 #error "Missing type int32_t"
00227 #endif
00228 #ifndef HAVE_UINT32_T
00229 #error "Missing type uint32_t"
00230 #endif
00231 #ifndef HAVE_INT64_T
00232 #error "Missing type int64_t"
00233 #endif
00234 #ifndef HAVE_UINT64_T
00235 #error "Missing type uint64_t"
00236 #endif
00237
00238
00239
00240
00241 #ifndef USING_TWOS_COMPLEMENT
00242 #error "Seems that your platform doesn't use 2's complement arithmetic. Argh."
00243 #endif
00244 #ifndef LONG_MAX
00245 #if (SIZEOF_LONG == 4)
00246 #define LONG_MAX 0x7fffffffL
00247 #elif (SIZEOF_LONG == 8)
00248 #define LONG_MAX 0x7fffffffffffffffL
00249 #else
00250 #error "Can't define LONG_MAX"
00251 #endif
00252 #endif
00253
00254 #ifndef INT_MAX
00255 #if (SIZEOF_INT == 4)
00256 #define INT_MAX 0x7fffffffL
00257 #elif (SIZEOF_INT == 8)
00258 #define INT_MAX 0x7fffffffffffffffL
00259 #else
00260 #error "Can't define INT_MAX"
00261 #endif
00262 #endif
00263
00264 #ifndef UINT_MAX
00265 #if (SIZEOF_INT == 2)
00266 #define UINT_MAX 0xffffu
00267 #elif (SIZEOF_INT == 4)
00268 #define UINT_MAX 0xffffffffu
00269 #elif (SIZEOF_INT == 8)
00270 #define UINT_MAX 0xffffffffffffffffu
00271 #else
00272 #error "Can't define UINT_MAX"
00273 #endif
00274 #endif
00275
00276 #ifndef SHORT_MAX
00277 #if (SIZEOF_SHORT == 2)
00278 #define SHORT_MAX 0x7fff
00279 #elif (SIZEOF_SHORT == 4)
00280 #define SHORT_MAX 0x7fffffff
00281 #else
00282 #error "Can't define SHORT_MAX"
00283 #endif
00284 #endif
00285
00286 #ifndef TIME_MAX
00287
00288 #ifdef TIME_T_IS_SIGNED
00289
00290 #if (SIZEOF_TIME_T == SIZEOF_INT)
00291 #define TIME_MAX ((time_t)INT_MAX)
00292 #elif (SIZEOF_TIME_T == SIZEOF_LONG)
00293 #define TIME_MAX ((time_t)LONG_MAX)
00294 #elif (SIZEOF_TIME_T == 8)
00295 #define TIME_MAX ((time_t)INT64_MAX)
00296 #else
00297 #error "Can't define (signed) TIME_MAX"
00298 #endif
00299
00300 #else
00301
00302 #if (SIZEOF_TIME_T == 4)
00303 #define TIME_MAX ((time_t)UINT32_MAX)
00304 #elif (SIZEOF_TIME_T == 8)
00305 #define TIME_MAX ((time_t)UINT64_MAX)
00306 #else
00307 #error "Can't define (unsigned) TIME_MAX"
00308 #endif
00309 #endif
00310 #endif
00311
00312 #ifndef SIZE_T_MAX
00313 #if (SIZEOF_SIZE_T == 4)
00314 #define SIZE_T_MAX UINT32_MAX
00315 #elif (SIZEOF_SIZE_T == 8)
00316 #define SIZE_T_MAX UINT64_MAX
00317 #else
00318 #error "Can't define SIZE_T_MAX"
00319 #endif
00320 #endif
00321
00322 #ifndef SSIZE_T_MAX
00323 #if (SIZEOF_SIZE_T == 4)
00324 #define SSIZE_T_MAX INT32_MAX
00325 #elif (SIZEOF_SIZE_T == 8)
00326 #define SSIZE_T_MAX INT64_MAX
00327 #else
00328 #error "Can't define SSIZE_T_MAX"
00329 #endif
00330 #endif
00331
00332
00333 #define SIZE_T_CEILING (sizeof(char)<<(sizeof(size_t)*8 - 1))
00334
00335 #endif
00336