util.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright 2003 Roger Dingledine */
  2. /* See LICENSE for licensing information */
  3. /* $Id$ */
  4. #ifndef __UTIL_H
  5. #define __UTIL_H
  6. #include "orconfig.h"
  7. #ifdef HAVE_SYS_TIME_H
  8. #include <sys/time.h>
  9. #endif
  10. #ifdef HAVE_TIME_H
  11. #include <time.h>
  12. #endif
  13. #ifndef HAVE_GETTIMEOFDAY
  14. #ifdef HAVE_FTIME
  15. #define USING_FAKE_TIMEVAL
  16. #include <sys/timeb.h>
  17. #define timeval timeb
  18. #define tv_sec time
  19. #define tv_usec millitm
  20. #endif
  21. #endif
  22. #ifdef _MSC_VER
  23. /* Windows names string functions funnily. */
  24. #define strncasecmp strnicmp
  25. #define strcasecmp stricmp
  26. #define INLINE __inline
  27. #else
  28. #define INLINE inline
  29. #endif
  30. void *tor_malloc(size_t size);
  31. /* Same as gettimeofday, but no need to check exit value. */
  32. void my_gettimeofday(struct timeval *timeval);
  33. /* Returns the number of microseconds between start and end. Requires that
  34. * end >= start, and that the number of microseconds < LONG_MAX. */
  35. long tv_udiff(struct timeval *start, struct timeval *end);
  36. void tv_addms(struct timeval *a, long ms);
  37. void tv_add(struct timeval *a, struct timeval *b);
  38. int tv_cmp(struct timeval *a, struct timeval *b);
  39. void set_socket_nonblocking(int socket);
  40. /* Minimalist interface to run a void function in the background. On
  41. unix calls fork, on win32 calls beginthread. Returns -1 on failure.
  42. func should not return, but rather should call spawn_exit.
  43. */
  44. int spawn_func(int (*func)(void *), void *data);
  45. void spawn_exit();
  46. int tor_socketpair(int family, int type, int protocol, int fd[2]);
  47. #endif