compat.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /* Copyright (c) 2003-2004, Roger Dingledinex
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2008, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef _TOR_COMPAT_H
  6. #define _TOR_COMPAT_H
  7. #include "orconfig.h"
  8. #include "torint.h"
  9. #ifdef MS_WINDOWS
  10. #define WIN32_WINNT 0x400
  11. #define _WIN32_WINNT 0x400
  12. #define WIN32_LEAN_AND_MEAN
  13. #if defined(_MSC_VER) && (_MSC_VER < 1300)
  14. #include <winsock.h>
  15. #else
  16. #include <winsock2.h>
  17. #include <ws2tcpip.h>
  18. #endif
  19. #endif
  20. #ifdef HAVE_SYS_TYPES_H
  21. #include <sys/types.h>
  22. #endif
  23. #ifdef HAVE_SYS_TIME_H
  24. #include <sys/time.h>
  25. #endif
  26. #ifdef HAVE_TIME_H
  27. #include <time.h>
  28. #endif
  29. #ifdef HAVE_STRING_H
  30. #include <string.h>
  31. #endif
  32. #ifdef HAVE_CTYPE_H
  33. #include <ctype.h>
  34. #endif
  35. #ifdef HAVE_PTHREAD_H
  36. #include <pthread.h>
  37. #endif
  38. #include <stdarg.h>
  39. #ifdef HAVE_SYS_RESOURCE_H
  40. #include <sys/resource.h>
  41. #endif
  42. #ifdef HAVE_SYS_SOCKET_H
  43. #include <sys/socket.h>
  44. #endif
  45. #ifdef HAVE_SYS_TYPES_H
  46. #include <sys/types.h>
  47. #endif
  48. #ifdef HAVE_NETINET_IN_H
  49. #include <netinet/in.h>
  50. #endif
  51. #ifdef HAVE_NETINET6_IN6_H
  52. #include <netinet6/in6.h>
  53. #endif
  54. #ifndef NULL_REP_IS_ZERO_BYTES
  55. #error "It seems your platform does not represent NULL as zero. We can't cope."
  56. #endif
  57. #if 'a'!=97 || 'z'!=122 || 'A'!=65 || ' '!=32
  58. #error "It seems that you encode characters in something other than ASCII."
  59. #endif
  60. /* ===== Compiler compatibility */
  61. /* GCC can check printf types on arbitrary functions. */
  62. #ifdef __GNUC__
  63. #define CHECK_PRINTF(formatIdx, firstArg) \
  64. __attribute__ ((format(printf, formatIdx, firstArg)))
  65. #else
  66. #define CHECK_PRINTF(formatIdx, firstArg)
  67. #endif
  68. /* inline is __inline on windows. */
  69. #ifdef MS_WINDOWS
  70. #define INLINE __inline
  71. #else
  72. #define INLINE inline
  73. #endif
  74. /* Try to get a reasonable __func__ substitute in place. */
  75. #if defined(_MSC_VER)
  76. /* MSVC compilers before VC7 don't have __func__ at all; later ones call it
  77. * __FUNCTION__. */
  78. #if _MSC_VER < 1300
  79. #define __func__ "???"
  80. #else
  81. #define __func__ __FUNCTION__
  82. #endif
  83. #else
  84. /* For platforms where autoconf works, make sure __func__ is defined
  85. * sanely. */
  86. #ifndef HAVE_MACRO__func__
  87. #ifdef HAVE_MACRO__FUNCTION__
  88. #define __func__ __FUNCTION__
  89. #elif HAVE_MACRO__FUNC__
  90. #define __func__ __FUNC__
  91. #else
  92. #define __func__ "???"
  93. #endif
  94. #endif /* ifndef MAVE_MACRO__func__ */
  95. #endif /* if not windows */
  96. #if defined(_MSC_VER) && (_MSC_VER < 1300)
  97. /* MSVC versions before 7 apparently don't believe that you can cast uint64_t
  98. * to double and really mean it. */
  99. extern INLINE double U64_TO_DBL(uint64_t x) {
  100. int64_t i = (int64_t) x;
  101. return (i < 0) ? ((double) INT64_MAX) : (double) i;
  102. }
  103. #define DBL_TO_U64(x) ((uint64_t)(int64_t) (x))
  104. #else
  105. #define U64_TO_DBL(x) ((double) (x))
  106. #define DBL_TO_U64(x) ((uint64_t) (x))
  107. #endif
  108. /* GCC has several useful attributes. */
  109. #if defined(__GNUC__) && __GNUC__ >= 3
  110. #define ATTR_NORETURN __attribute__((noreturn))
  111. #define ATTR_PURE __attribute__((pure))
  112. #define ATTR_CONST __attribute__((const))
  113. #define ATTR_MALLOC __attribute__((malloc))
  114. #define ATTR_NORETURN __attribute__((noreturn))
  115. /* Alas, nonnull is not at present a good idea for us. We'd like to get
  116. * warnings when we pass NULL where we shouldn't (which nonnull does, albeit
  117. * spottily), but we don't want to tell the compiler to make optimizations
  118. * with the assumption that the argument can't be NULL (since this would make
  119. * many of our checks go away, and make our code less robust against
  120. * programming errors). Unfortunately, nonnull currently does both of these
  121. * things, and there's no good way to split them up.
  122. *
  123. * #define ATTR_NONNULL(x) __attribute__((nonnull x)) */
  124. #define ATTR_NONNULL(x)
  125. /** Macro: Evaluates to <b>exp</b> and hints the compiler that the value
  126. * of <b>exp</b> will probably be true.
  127. *
  128. * In other words, "if (PREDICT_LIKELY(foo))" is the same as "if (foo)",
  129. * except that it tells the compiler that the branch will be taken most of the
  130. * time. This can generate slightly better code with some CPUs.
  131. */
  132. #define PREDICT_LIKELY(exp) __builtin_expect(!!(exp), 1)
  133. /** Macro: Evaluates to <b>exp</b> and hints the compiler that the value
  134. * of <b>exp</b> will probably be false.
  135. *
  136. * In other words, "if (PREDICT_UNLIKELY(foo))" is the same as "if (foo)",
  137. * except that it tells the compiler that the branch will usually not be
  138. * taken. This can generate slightly better code with some CPUs.
  139. */
  140. #define PREDICT_UNLIKELY(exp) __builtin_expect(!!(exp), 0)
  141. #else
  142. #define ATTR_NORETURN
  143. #define ATTR_PURE
  144. #define ATTR_CONST
  145. #define ATTR_MALLOC
  146. #define ATTR_NORETURN
  147. #define ATTR_NONNULL(x)
  148. #define PREDICT_LIKELY(exp) (exp)
  149. #define PREDICT_UNLIKELY(exp) (exp)
  150. #endif
  151. /** Expands to a syntactically valid empty statement. */
  152. #define STMT_NIL (void)0
  153. #ifdef __GNUC__
  154. /** STMT_BEGIN and STMT_END are used to wrap blocks inside macros so that
  155. * the macro can be used as if it were a single C statement. */
  156. #define STMT_BEGIN (void) ({
  157. #define STMT_END })
  158. #elif defined(sun) || defined(__sun__)
  159. #define STMT_BEGIN if (1) {
  160. #define STMT_END } else STMT_NIL
  161. #else
  162. #define STMT_BEGIN do {
  163. #define STMT_END } while (0)
  164. #endif
  165. /* ===== String compatibility */
  166. #ifdef MS_WINDOWS
  167. /* Windows names string functions differently from most other platforms. */
  168. #define strncasecmp strnicmp
  169. #define strcasecmp stricmp
  170. #endif
  171. #ifndef HAVE_STRLCAT
  172. size_t strlcat(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
  173. #endif
  174. #ifndef HAVE_STRLCPY
  175. size_t strlcpy(char *dst, const char *src, size_t siz) ATTR_NONNULL((1,2));
  176. #endif
  177. #ifdef _MSC_VER
  178. /** Casts the uint64_t value in <b>a</b> to the right type for an argument
  179. * to printf. */
  180. #define U64_PRINTF_ARG(a) (a)
  181. /** Casts the uint64_t* value in <b>a</b> to the right type for an argument
  182. * to scanf. */
  183. #define U64_SCANF_ARG(a) (a)
  184. /** Expands to a literal uint64_t-typed constant for the value <b>n</b>. */
  185. #define U64_LITERAL(n) (n ## ui64)
  186. #else
  187. #define U64_PRINTF_ARG(a) ((long long unsigned int)(a))
  188. #define U64_SCANF_ARG(a) ((long long unsigned int*)(a))
  189. #define U64_LITERAL(n) (n ## llu)
  190. #endif
  191. #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
  192. /** The formatting string used to put a uint64_t value in a printf() or
  193. * scanf() function. See also U64_PRINTF_ARG and U64_SCANF_ARG. */
  194. #define U64_FORMAT "%I64u"
  195. #else
  196. #define U64_FORMAT "%llu"
  197. #endif
  198. /** Represents an mmaped file. Allocated via tor_mmap_file; freed with
  199. * tor_munmap_file. */
  200. typedef struct tor_mmap_t {
  201. const char *data; /**< Mapping of the file's contents. */
  202. size_t size; /**< Size of the file. */
  203. /* None of the fields below should be accessed from outside compat.c */
  204. #ifdef HAVE_SYS_MMAN_H
  205. size_t mapping_size; /**< Size of the actual mapping. (This is this file
  206. * size, rounded up to the nearest page.) */
  207. #elif defined MS_WINDOWS
  208. HANDLE file_handle;
  209. HANDLE mmap_handle;
  210. #endif
  211. } tor_mmap_t;
  212. tor_mmap_t *tor_mmap_file(const char *filename) ATTR_NONNULL((1));
  213. void tor_munmap_file(tor_mmap_t *handle) ATTR_NONNULL((1));
  214. int tor_snprintf(char *str, size_t size, const char *format, ...)
  215. CHECK_PRINTF(3,4) ATTR_NONNULL((1,3));
  216. int tor_vsnprintf(char *str, size_t size, const char *format, va_list args)
  217. ATTR_NONNULL((1,3));
  218. const void *tor_memmem(const void *haystack, size_t hlen, const void *needle,
  219. size_t nlen) ATTR_PURE ATTR_NONNULL((1,3));
  220. static const void *tor_memstr(const void *haystack, size_t hlen,
  221. const char *needle) ATTR_PURE ATTR_NONNULL((1,3));
  222. static INLINE const void *
  223. tor_memstr(const void *haystack, size_t hlen, const char *needle)
  224. {
  225. return tor_memmem(haystack, hlen, needle, strlen(needle));
  226. }
  227. /* This cast-to-uchar, then-cast-to-int business is needed to compile and
  228. * run properly on some Solarises. */
  229. #define TOR_ISALPHA(c) isalpha((int)(unsigned char)(c))
  230. #define TOR_ISALNUM(c) isalnum((int)(unsigned char)(c))
  231. #define TOR_ISSPACE(c) isspace((int)(unsigned char)(c))
  232. #define TOR_ISXDIGIT(c) isxdigit((int)(unsigned char)(c))
  233. #define TOR_ISDIGIT(c) isdigit((int)(unsigned char)(c))
  234. #define TOR_ISPRINT(c) isprint((int)(unsigned char)(c))
  235. #define TOR_ISLOWER(c) islower((int)(unsigned char)(c))
  236. #define TOR_ISUPPER(c) isupper((int)(unsigned char)(c))
  237. #define TOR_TOLOWER(c) ((char)tolower((int)(unsigned char)(c)))
  238. #define TOR_TOUPPER(c) ((char)toupper((int)(unsigned char)(c)))
  239. #ifdef MS_WINDOWS
  240. #define _SHORT_FILE_ (tor_fix_source_file(__FILE__))
  241. const char *tor_fix_source_file(const char *fname);
  242. #else
  243. #define _SHORT_FILE_ (__FILE__)
  244. #define tor_fix_source_file(s) (s)
  245. #endif
  246. /* ===== Time compatibility */
  247. #if !defined(HAVE_GETTIMEOFDAY) && !defined(HAVE_STRUCT_TIMEVAL_TV_SEC)
  248. struct timeval {
  249. time_t tv_sec;
  250. unsigned int tv_usec;
  251. };
  252. #endif
  253. void tor_gettimeofday(struct timeval *timeval);
  254. #ifdef HAVE_LOCALTIME_R
  255. #define tor_localtime_r localtime_r
  256. #else
  257. struct tm *tor_localtime_r(const time_t *timep, struct tm *result);
  258. #endif
  259. #ifdef HAVE_GMTIME_R
  260. #define tor_gmtime_r gmtime_r
  261. #else
  262. struct tm *tor_gmtime_r(const time_t *timep, struct tm *result);
  263. #endif
  264. /* ===== File compatibility */
  265. int replace_file(const char *from, const char *to);
  266. int touch_file(const char *fname);
  267. typedef struct tor_lockfile_t tor_lockfile_t;
  268. tor_lockfile_t *tor_lockfile_lock(const char *filename, int blocking,
  269. int *locked_out);
  270. void tor_lockfile_unlock(tor_lockfile_t *lockfile);
  271. off_t tor_fd_getpos(int fd);
  272. int tor_fd_seekend(int fd);
  273. #ifdef MS_WINDOWS
  274. #define PATH_SEPARATOR "\\"
  275. #else
  276. #define PATH_SEPARATOR "/"
  277. #endif
  278. /* ===== Net compatibility */
  279. #if (SIZEOF_SOCKLEN_T == 0)
  280. typedef int socklen_t;
  281. #endif
  282. int tor_close_socket(int s);
  283. int tor_open_socket(int domain, int type, int protocol);
  284. int tor_accept_socket(int sockfd, struct sockaddr *addr, socklen_t *len);
  285. int get_n_open_sockets(void);
  286. #define tor_socket_send(s, buf, len, flags) send(s, buf, len, flags)
  287. #define tor_socket_recv(s, buf, len, flags) recv(s, buf, len, flags)
  288. /* Define struct in6_addr on platforms that do not have it. Generally,
  289. * these platforms are ones without IPv6 support, but we want to have
  290. * a working in6_addr there anyway, so we can use it to parse IPv6
  291. * addresses. */
  292. #if !defined(HAVE_STRUCT_IN6_ADDR)
  293. struct in6_addr
  294. {
  295. union {
  296. uint8_t u6_addr8[16];
  297. uint16_t u6_addr16[8];
  298. uint32_t u6_addr32[4];
  299. } in6_u;
  300. #define s6_addr in6_u.u6_addr8
  301. #define s6_addr16 in6_u.u6_addr16
  302. #define s6_addr32 in6_u.u6_addr32
  303. };
  304. #endif
  305. #if defined(__APPLE__) || defined(__darwin__) || defined(__FreeBSD__) \
  306. || defined(__NetBSD__) || defined(__OpenBSD__)
  307. /* Many BSD variants seem not to define these. */
  308. #ifndef s6_addr16
  309. #define s6_addr16 __u6_addr.__u6_addr16
  310. #endif
  311. #ifndef s6_addr32
  312. #define s6_addr32 __u6_addr.__u6_addr32
  313. #endif
  314. #endif
  315. #ifndef HAVE_SA_FAMILY_T
  316. typedef uint16_t sa_family_t;
  317. #endif
  318. /* Apparently, MS and Solaris don't define s6_addr16 or s6_addr32. */
  319. #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR32
  320. #define S6_ADDR32(x) ((uint32_t*)(x).s6_addr32)
  321. #else
  322. #define S6_ADDR32(x) ((uint32_t*)((char*)&(x).s6_addr))
  323. #endif
  324. #ifdef HAVE_STRUCT_IN6_ADDR_S6_ADDR16
  325. #define S6_ADDR16(x) ((uint16_t*)(x).s6_addr16)
  326. #else
  327. #define S6_ADDR16(x) ((uint16_t*)((char*)&(x).s6_addr))
  328. #endif
  329. /* Define struct sockaddr_in6 on platforms that do not have it. See notes
  330. * on struct in6_addr. */
  331. #if !defined(HAVE_STRUCT_SOCKADDR_IN6)
  332. struct sockaddr_in6 {
  333. sa_family_t sin6_family;
  334. uint16_t sin6_port;
  335. // uint32_t sin6_flowinfo;
  336. struct in6_addr sin6_addr;
  337. // uint32_t sin6_scope_id;
  338. };
  339. #endif
  340. int tor_inet_aton(const char *cp, struct in_addr *addr) ATTR_NONNULL((1,2));
  341. const char *tor_inet_ntop(int af, const void *src, char *dst, size_t len);
  342. int tor_inet_pton(int af, const char *src, void *dst);
  343. int tor_lookup_hostname(const char *name, uint32_t *addr) ATTR_NONNULL((1,2));
  344. void set_socket_nonblocking(int socket);
  345. int tor_socketpair(int family, int type, int protocol, int fd[2]);
  346. int network_init(void);
  347. /* For stupid historical reasons, windows sockets have an independent
  348. * set of errnos, and an independent way to get them. Also, you can't
  349. * always believe WSAEWOULDBLOCK. Use the macros below to compare
  350. * errnos against expected values, and use tor_socket_errno to find
  351. * the actual errno after a socket operation fails.
  352. */
  353. #if defined(MS_WINDOWS)
  354. /** Return true if e is EAGAIN or the local equivalent. */
  355. #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN || (e) == WSAEWOULDBLOCK)
  356. /** Return true if e is EINPROGRESS or the local equivalent. */
  357. #define ERRNO_IS_EINPROGRESS(e) ((e) == WSAEINPROGRESS)
  358. /** Return true if e is EINPROGRESS or the local equivalent as returned by
  359. * a call to connect(). */
  360. #define ERRNO_IS_CONN_EINPROGRESS(e) \
  361. ((e) == WSAEINPROGRESS || (e)== WSAEINVAL || (e) == WSAEWOULDBLOCK)
  362. /** Return true if e is EAGAIN or another error indicating that a call to
  363. * accept() has no pending connections to return. */
  364. #define ERRNO_IS_ACCEPT_EAGAIN(e) ERRNO_IS_EAGAIN(e)
  365. /** Return true if e is EMFILE or another error indicating that a call to
  366. * accept() has failed because we're out of fds or something. */
  367. #define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \
  368. ((e) == WSAEMFILE || (e) == WSAENOBUFS)
  369. /** Return true if e is EADDRINUSE or the local equivalent. */
  370. #define ERRNO_IS_EADDRINUSE(e) ((e) == WSAEADDRINUSE)
  371. int tor_socket_errno(int sock);
  372. const char *tor_socket_strerror(int e);
  373. #else
  374. #define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN)
  375. #define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS)
  376. #define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS)
  377. #define ERRNO_IS_ACCEPT_EAGAIN(e) ((e) == EAGAIN || (e) == ECONNABORTED)
  378. #define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \
  379. ((e) == EMFILE || (e) == ENFILE || (e) == ENOBUFS || (e) == ENOMEM)
  380. #define ERRNO_IS_EADDRINUSE(e) ((e) == EADDRINUSE)
  381. #define tor_socket_errno(sock) (errno)
  382. #define tor_socket_strerror(e) strerror(e)
  383. #endif
  384. /** Specified SOCKS5 status codes. */
  385. typedef enum {
  386. SOCKS5_SUCCEEDED = 0x00,
  387. SOCKS5_GENERAL_ERROR = 0x01,
  388. SOCKS5_NOT_ALLOWED = 0x02,
  389. SOCKS5_NET_UNREACHABLE = 0x03,
  390. SOCKS5_HOST_UNREACHABLE = 0x04,
  391. SOCKS5_CONNECTION_REFUSED = 0x05,
  392. SOCKS5_TTL_EXPIRED = 0x06,
  393. SOCKS5_COMMAND_NOT_SUPPORTED = 0x07,
  394. SOCKS5_ADDRESS_TYPE_NOT_SUPPORTED = 0x08,
  395. } socks5_reply_status_t;
  396. /* ===== OS compatibility */
  397. const char *get_uname(void);
  398. uint16_t get_uint16(const char *cp) ATTR_PURE ATTR_NONNULL((1));
  399. uint32_t get_uint32(const char *cp) ATTR_PURE ATTR_NONNULL((1));
  400. void set_uint16(char *cp, uint16_t v) ATTR_NONNULL((1));
  401. void set_uint32(char *cp, uint32_t v) ATTR_NONNULL((1));
  402. /* These uint8 variants are defined to make the code more uniform. */
  403. #define get_uint8(cp) (*(const uint8_t*)(cp))
  404. static void set_uint8(char *cp, uint8_t v);
  405. static INLINE void
  406. set_uint8(char *cp, uint8_t v)
  407. {
  408. *(uint8_t*)cp = v;
  409. }
  410. #if !defined(HAVE_RLIM_T)
  411. typedef unsigned long rlim_t;
  412. #endif
  413. int set_max_file_descriptors(rlim_t limit, int *max);
  414. int switch_id(const char *user);
  415. #ifdef HAVE_PWD_H
  416. char *get_user_homedir(const char *username);
  417. #endif
  418. int spawn_func(void (*func)(void *), void *data);
  419. void spawn_exit(void) ATTR_NORETURN;
  420. #if defined(ENABLE_THREADS) && defined(MS_WINDOWS)
  421. #define USE_WIN32_THREADS
  422. #define TOR_IS_MULTITHREADED 1
  423. #elif (defined(ENABLE_THREADS) && defined(HAVE_PTHREAD_H) && \
  424. defined(HAVE_PTHREAD_CREATE))
  425. #define USE_PTHREADS
  426. #define TOR_IS_MULTITHREADED 1
  427. #else
  428. #undef TOR_IS_MULTITHREADED
  429. #endif
  430. /* Because we use threads instead of processes on most platforms (Windows,
  431. * Linux, etc), we need locking for them. On platforms with poor thread
  432. * support or broken gethostbyname_r, these functions are no-ops. */
  433. /** A generic lock structure for multithreaded builds. */
  434. typedef struct tor_mutex_t {
  435. #if defined(USE_WIN32_THREADS)
  436. CRITICAL_SECTION mutex;
  437. #elif defined(USE_PTHREADS)
  438. pthread_mutex_t mutex;
  439. #else
  440. int _unused;
  441. #endif
  442. } tor_mutex_t;
  443. #ifdef TOR_IS_MULTITHREADED
  444. tor_mutex_t *tor_mutex_new(void);
  445. void tor_mutex_init(tor_mutex_t *m);
  446. void tor_mutex_acquire(tor_mutex_t *m);
  447. void tor_mutex_release(tor_mutex_t *m);
  448. void tor_mutex_free(tor_mutex_t *m);
  449. void tor_mutex_uninit(tor_mutex_t *m);
  450. unsigned long tor_get_thread_id(void);
  451. void tor_threads_init(void);
  452. #else
  453. #define tor_mutex_new() ((tor_mutex_t*)tor_malloc(sizeof(int)))
  454. #define tor_mutex_init(m) STMT_NIL
  455. #define tor_mutex_acquire(m) STMT_NIL
  456. #define tor_mutex_release(m) STMT_NIL
  457. #define tor_mutex_free(m) STMT_BEGIN tor_free(m); STMT_END
  458. #define tor_mutex_uninit(m) STMT_NIL
  459. #define tor_get_thread_id() (1UL)
  460. #define tor_threads_init() STMT_NIL
  461. #endif
  462. #ifdef TOR_IS_MULTITHREADED
  463. #if 0
  464. typedef struct tor_cond_t tor_cond_t;
  465. tor_cond_t *tor_cond_new(void);
  466. void tor_cond_free(tor_cond_t *cond);
  467. int tor_cond_wait(tor_cond_t *cond, tor_mutex_t *mutex);
  468. void tor_cond_signal_one(tor_cond_t *cond);
  469. void tor_cond_signal_all(tor_cond_t *cond);
  470. #endif
  471. #endif
  472. /* Platform-specific helpers. */
  473. #ifdef MS_WINDOWS
  474. char *format_win32_error(DWORD err);
  475. #endif
  476. /*for some reason my compiler doesn't have these version flags defined
  477. a nice homework assignment for someone one day is to define the rest*/
  478. //these are the values as given on MSDN
  479. #ifdef MS_WINDOWS
  480. #ifndef VER_SUITE_EMBEDDEDNT
  481. #define VER_SUITE_EMBEDDEDNT 0x00000040
  482. #endif
  483. #ifndef VER_SUITE_SINGLEUSERTS
  484. #define VER_SUITE_SINGLEUSERTS 0x00000100
  485. #endif
  486. #endif
  487. #endif