#ifndef TOR_TIMEVAL_H
#define TOR_TIMEVAL_H
#include "orconfig.h"
#include "lib/cc/torint.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef TOR_COVERAGE
#undef timeradd
#undef timersub
#define timeradd(tv1,tv2,tvout) \
do { \
(tvout)->tv_sec = (tv1)->tv_sec + (tv2)->tv_sec; \
(tvout)->tv_usec = (tv1)->tv_usec + (tv2)->tv_usec; \
(tvout)->tv_sec += (tvout)->tv_usec / 1000000; \
(tvout)->tv_usec %= 1000000; \
} while (0)
#define timersub(tv1,tv2,tvout) \
do { \
(tvout)->tv_sec = (tv1)->tv_sec - (tv2)->tv_sec - 1; \
(tvout)->tv_usec = (tv1)->tv_usec - (tv2)->tv_usec + 1000000; \
(tvout)->tv_sec += (tvout)->tv_usec / 1000000; \
(tvout)->tv_usec %= 1000000; \
} while (0)
#endif
#ifndef timeradd
#define timeradd(tv1,tv2,tvout) \
do { \
(tvout)->tv_sec = (tv1)->tv_sec + (tv2)->tv_sec; \
(tvout)->tv_usec = (tv1)->tv_usec + (tv2)->tv_usec; \
if ((tvout)->tv_usec >= 1000000) { \
(tvout)->tv_usec -= 1000000; \
(tvout)->tv_sec++; \
} \
} while (0)
#endif
#ifndef timersub
#define timersub(tv1,tv2,tvout) \
do { \
(tvout)->tv_sec = (tv1)->tv_sec - (tv2)->tv_sec; \
(tvout)->tv_usec = (tv1)->tv_usec - (tv2)->tv_usec; \
if ((tvout)->tv_usec < 0) { \
(tvout)->tv_usec += 1000000; \
(tvout)->tv_sec--; \
} \
} while (0)
#endif
#ifndef COCCI
#ifndef timercmp
#define timercmp(tv1,tv2,op) \
(((tv1)->tv_sec == (tv2)->tv_sec) ? \
((tv1)->tv_usec op (tv2)->tv_usec) : \
((tv1)->tv_sec op (tv2)->tv_sec))
#endif
#endif
#endif