torint.h 4.6 KB

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