X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Ftime_support.c;h=05eaf0a9d08e4cfae9a1dddf28c12d906813a2fb;hb=d46b28983dc27369e90f4dc8a0e54b5057583b38;hp=8337e73ba7518f20a90437032c9eb3acbeacdab1;hpb=d0e763ac7ef6aa17b17bd00ccdfbccfb4eacda69;p=openocd.git diff --git a/src/helper/time_support.c b/src/helper/time_support.c index 8337e73ba7..05eaf0a9d0 100644 --- a/src/helper/time_support.c +++ b/src/helper/time_support.c @@ -62,6 +62,21 @@ int timeval_add_time(struct timeval *result, long sec, long usec) return 0; } +/* compare two timevals and return -1/0/+1 accordingly */ +int timeval_compare(const struct timeval *x, const struct timeval *y) +{ + if (x->tv_sec < y->tv_sec) + return -1; + else if (x->tv_sec > y->tv_sec) + return 1; + else if (x->tv_usec < y->tv_usec) + return -1; + else if (x->tv_usec > y->tv_usec) + return 1; + else + return 0; +} + int duration_start(struct duration *duration) { return gettimeofday(&duration->start, NULL);