X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fhelper%2Ftime_support.c;h=05eaf0a9d08e4cfae9a1dddf28c12d906813a2fb;hp=8337e73ba7518f20a90437032c9eb3acbeacdab1;hb=e0fc7a54f287aad414b373410e09faa048f3a9dd;hpb=e22c6484eaedd56d71011dd56e76eacab515a0d6;ds=sidebyside 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);