diff --git a/utils.h b/utils.h index 9f794528f..08f24172d 100644 --- a/utils.h +++ b/utils.h @@ -178,6 +178,12 @@ #define TIMEVAL_MSEC_ADD(a, b, msecs) { (a).tv_sec = (b).tv_sec + ((msecs) / 1000); (a).tv_usec = (b).tv_usec + ((msecs) % 1000) * 1000; (a).tv_sec += (a).tv_usec / 1000000; (a).tv_usec %= 1000000; } #define TIMEVAL_ADD(a, b, usecs) { (a).tv_sec = (b).tv_sec + ((usecs) / 1000000); (a).tv_usec = (b).tv_usec + ((usecs) % 1000000); (a).tv_sec += (a).tv_usec / 1000000; (a).tv_usec %= 1000000; } +/* Find our if one timeval is before or after another, avoiding the integer + overflow that can result when doing a TIMEVAL_SUBTRACT on two widely spaced + timevals. */ +#define TIMEVAL_BEFORE(a, b) (((a).tv_sec < (b).tv_sec) || ((a).tv_sec == (b).tv_sec && (a).tv_usec < (b).tv_usec)) +#define TIMEVAL_AFTER(a, b) (((a).tv_sec > (b).tv_sec) || ((a).tv_sec == (b).tv_sec && (a).tv_usec > (b).tv_usec)) + /* Return num if it is between min and max. Otherwise return min or max (whichever is closest to num), */ template T box(T bmin, T bmax, T bnum) {