Remove unused function: dns_randfn_() in dns.c.
[tor.git] / src / lib / wallclock / timeval.h
blob4967e939bf8656e607dda05f43273aa8aefd49ec
1 /* Copyright (c) 2003-2004, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
6 /**
7 * \file timeval.h
9 * \brief Declarations for timeval-related macros that some platforms
10 * are missing.
11 **/
13 #ifndef TOR_TIMEVAL_H
14 #define TOR_TIMEVAL_H
16 #include "orconfig.h"
17 #include "lib/cc/torint.h"
19 #ifdef HAVE_SYS_TIME_H
20 #include <sys/time.h>
21 #endif
23 #ifndef timeradd
24 /** Replacement for timeradd on platforms that do not have it: sets tvout to
25 * the sum of tv1 and tv2. */
26 #define timeradd(tv1,tv2,tvout) \
27 do { \
28 (tvout)->tv_sec = (tv1)->tv_sec + (tv2)->tv_sec; \
29 (tvout)->tv_usec = (tv1)->tv_usec + (tv2)->tv_usec; \
30 if ((tvout)->tv_usec >= 1000000) { \
31 (tvout)->tv_usec -= 1000000; \
32 (tvout)->tv_sec++; \
33 } \
34 } while (0)
35 #endif /* !defined(timeradd) */
37 #ifndef timersub
38 /** Replacement for timersub on platforms that do not have it: sets tvout to
39 * tv1 minus tv2. */
40 #define timersub(tv1,tv2,tvout) \
41 do { \
42 (tvout)->tv_sec = (tv1)->tv_sec - (tv2)->tv_sec; \
43 (tvout)->tv_usec = (tv1)->tv_usec - (tv2)->tv_usec; \
44 if ((tvout)->tv_usec < 0) { \
45 (tvout)->tv_usec += 1000000; \
46 (tvout)->tv_sec--; \
47 } \
48 } while (0)
49 #endif /* !defined(timersub) */
51 #ifndef timercmp
52 /** Replacement for timercmp on platforms that do not have it: returns true
53 * iff the relational operator "op" makes the expression tv1 op tv2 true.
55 * Note that while this definition should work for all boolean operators, some
56 * platforms' native timercmp definitions do not support >=, <=, or ==. So
57 * don't use those.
59 #define timercmp(tv1,tv2,op) \
60 (((tv1)->tv_sec == (tv2)->tv_sec) ? \
61 ((tv1)->tv_usec op (tv2)->tv_usec) : \
62 ((tv1)->tv_sec op (tv2)->tv_sec))
63 #endif /* !defined(timercmp) */
65 #endif