aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-11-02 14:22:21 -0400
committerNick Mathewson <nickm@torproject.org>2012-11-02 14:22:21 -0400
commit1bfda600c338cd8f7d6b9acc7613b5567e6ee03f (patch)
treec975c6ff132d9aa2b7431a82c51b041722b55f3a /src/common/compat.h
parent07656d70ed3bd71fa1eec229c823187864494e9c (diff)
downloadtor-1bfda600c338cd8f7d6b9acc7613b5567e6ee03f.tar.gz
tor-1bfda600c338cd8f7d6b9acc7613b5567e6ee03f.zip
Add a TOR_SOCKET_T_FORMAT construction for logging sockets.
We need this since win64 has a 64-bit SOCKET type. Based on a patch from yayooo for 7260, forward-ported to 0.2.4.
Diffstat (limited to 'src/common/compat.h')
-rw-r--r--src/common/compat.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/compat.h b/src/common/compat.h
index 9ad03d33c5..9c544fa309 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -239,6 +239,19 @@ size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
#define I64_FORMAT "%lld"
#endif
+#if (SIZEOF_INTPTR_T == SIZEOF_INT)
+#define INTPTR_T_FORMAT "%d"
+#define INTPTR_PRINTF_ARG(x) ((int)(x))
+#elif (SIZEOF_INTPTR_T == SIZEOF_LONG)
+#define INTPTR_T_FORMAT "%ld"
+#define INTPTR_PRINTF_ARG(x) ((long)(x))
+#elif (SIZEOF_INTPTR_T == 8)
+#define INTPTR_T_FORMAT I64_FORMAT
+#define INTPTR_PRINTF_ARG(x) I64_PRINTF_ARG(x)
+#else
+#error Unknown: SIZEOF_INTPTR_T
+#endif
+
/** Represents an mmaped file. Allocated via tor_mmap_file; freed with
* tor_munmap_file. */
typedef struct tor_mmap_t {
@@ -403,11 +416,13 @@ typedef int socklen_t;
* any inadvertant checks for the socket being <= 0 or > 0 will probably
* still work. */
#define tor_socket_t intptr_t
+#define TOR_SOCKET_T_FORMAT INTPTR_T_FORMAT
#define SOCKET_OK(s) ((SOCKET)(s) != INVALID_SOCKET)
#define TOR_INVALID_SOCKET INVALID_SOCKET
#else
/** Type used for a network socket. */
#define tor_socket_t int
+#define TOR_SOCKET_T_FORMAT "%d"
/** Macro: true iff 's' is a possible value for a valid initialized socket. */
#define SOCKET_OK(s) ((s) >= 0)
/** Error/uninitialized value for a tor_socket_t. */