torint.h 4.5 KB

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