From 29a83846d7159b6ef7eace31148b7c4db122c74d Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 4 Mar 2019 11:07:52 -0500 Subject: [PATCH] TT#50652 use a better timeval_cmp function Change-Id: I727d1e7c28c2fe887fa0889060ae5f93883f52bd --- lib/auxlib.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/auxlib.h b/lib/auxlib.h index 6c9ad5b03..d433539d6 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -235,14 +235,18 @@ INLINE void timeval_add(struct timeval *result, const struct timeval *a, const s INLINE void timeval_add_usec(struct timeval *tv, long usec) { timeval_from_us(tv, timeval_us(tv) + usec); } -INLINE int timeval_cmp(const struct timeval *a, const struct timeval *b) { - long long diff; - diff = timeval_diff(a, b); - if (diff < 0) +INLINE int long_cmp(long long a, long long b) { + if (a == b) + return 0; + if (a < b) return -1; - if (diff > 0) - return 1; - return 0; + return 1; +} +INLINE int timeval_cmp(const struct timeval *a, const struct timeval *b) { + int r = long_cmp(a->tv_sec, b->tv_sec); + if (r != 0) + return r; + return long_cmp(a->tv_usec, b->tv_usec); } // as a GCompareFunc int timeval_cmp_ptr(const void *a, const void *b);