1 /* Copyright (c) 2003, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
9 * \brief Integer definitions used throughout Tor.
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
24 #ifdef HAVE_SYS_LIMITS_H
25 #include <sys/limits.h>
29 #if SIZEOF_SIZE_T == 8
30 #define SIZE_MAX UINT64_MAX
31 #elif SIZEOF_SIZE_T == 4
32 #define SIZE_MAX UINT32_MAX
34 #error "Can't define SIZE_MAX"
35 #endif /* SIZEOF_SIZE_T == 8 || ... */
36 #endif /* !defined(SIZE_MAX) */
39 #if SIZEOF_SIZE_T == 8
40 typedef int64_t ssize_t
;
41 #elif SIZEOF_SIZE_T == 4
42 typedef int32_t ssize_t
;
44 #error "Can't define ssize_t."
45 #endif /* SIZEOF_SIZE_T == 8 || ... */
46 #endif /* !defined(HAVE_SSIZE_T) */
48 /* This assumes a sane (2's-complement) representation. But if you
49 * aren't 2's complement, and you don't define LONG_MAX, then you're so
50 * bizarre that I want nothing to do with you. */
51 #ifndef USING_TWOS_COMPLEMENT
52 #error "Your platform doesn't use 2's complement arithmetic."
57 #if (SIZEOF_TIME_T == SIZEOF_INT)
58 #define TIME_MAX ((time_t)INT_MAX)
59 #elif (SIZEOF_TIME_T == SIZEOF_LONG)
60 #define TIME_MAX ((time_t)LONG_MAX)
61 #elif (SIZEOF_TIME_T == 8)
62 #define TIME_MAX ((time_t)INT64_MAX)
64 #error "Can't define TIME_MAX"
65 #endif /* (SIZEOF_TIME_T == SIZEOF_INT) || ... */
67 #endif /* !defined(TIME_MAX) */
71 #if (SIZEOF_TIME_T == SIZEOF_INT)
72 #define TIME_MIN ((time_t)INT_MIN)
73 #elif (SIZEOF_TIME_T == SIZEOF_LONG)
74 #define TIME_MIN ((time_t)LONG_MIN)
75 #elif (SIZEOF_TIME_T == 8)
76 #define TIME_MIN ((time_t)INT64_MIN)
78 #error "Can't define TIME_MIN"
79 #endif /* (SIZEOF_TIME_T == SIZEOF_INT) || ... */
81 #endif /* !defined(TIME_MIN) */
84 #if (SIZEOF_SIZE_T == 4)
85 #define SIZE_MAX UINT32_MAX
86 #elif (SIZEOF_SIZE_T == 8)
87 #define SIZE_MAX UINT64_MAX
89 #error "Can't define SIZE_MAX"
90 #endif /* (SIZEOF_SIZE_T == 4) || ... */
91 #endif /* !defined(SIZE_MAX) */
95 # define TOR_PRIuSZ PRIu64
97 # define TOR_PRIuSZ PRIu32
99 #else /* !defined(_WIN32) */
100 # define TOR_PRIuSZ "zu"
101 #endif /* defined(_WIN32) */
105 # define TOR_PRIdSZ PRId64
107 # define TOR_PRIdSZ PRId32
109 #else /* !defined(_WIN32) */
110 # define TOR_PRIdSZ "zd"
111 #endif /* defined(_WIN32) */
114 #if (SIZEOF_SIZE_T == 4)
115 #define SSIZE_MAX INT32_MAX
116 #elif (SIZEOF_SIZE_T == 8)
117 #define SSIZE_MAX INT64_MAX
119 #error "Can't define SSIZE_MAX"
120 #endif /* (SIZEOF_SIZE_T == 4) || ... */
121 #endif /* !defined(SSIZE_MAX) */
123 /** Any ssize_t larger than this amount is likely to be an underflow. */
124 #define SSIZE_T_CEILING ((ssize_t)(SSIZE_MAX-16))
125 /** Any size_t larger than this amount is likely to be an underflow. */
126 #define SIZE_T_CEILING ((size_t)(SSIZE_MAX-16))
128 #if SIZEOF_INT > SIZEOF_VOID_P
129 #error "sizeof(int) > sizeof(void *) - Can't build Tor here."
132 #if SIZEOF_UNSIGNED_INT > SIZEOF_VOID_P
133 #error "sizeof(unsigned int) > sizeof(void *) - Can't build Tor here."
136 #endif /* !defined(TOR_TORINT_H) */