diff --git a/defs.h b/defs.h index 3ed15ced..437755c0 100644 --- a/defs.h +++ b/defs.h @@ -955,6 +955,8 @@ extern void ts_add(struct timespec *, const struct timespec *, const struct time extern void ts_sub(struct timespec *, const struct timespec *, const struct timespec *); extern void ts_mul(struct timespec *, const struct timespec *, int); extern void ts_div(struct timespec *, const struct timespec *, int); +extern void ts_min(struct timespec *, const struct timespec *, const struct timespec *); +extern void ts_max(struct timespec *, const struct timespec *, const struct timespec *); #ifdef ENABLE_STACKTRACE extern void unwind_init(void); diff --git a/util.c b/util.c index 5250ae78..59e7583c 100644 --- a/util.c +++ b/util.c @@ -109,6 +109,30 @@ ts_mul(struct timespec *tv, const struct timespec *a, int n) tv->tv_nsec = nsec % 1000000000; } +void +ts_min(struct timespec *tv, const struct timespec *a, const struct timespec *b) +{ + if (ts_cmp(a, b) < 0) { + tv->tv_sec = a->tv_sec; + tv->tv_nsec = a->tv_nsec; + } else { + tv->tv_sec = b->tv_sec; + tv->tv_nsec = b->tv_nsec; + } +} + +void +ts_max(struct timespec *tv, const struct timespec *a, const struct timespec *b) +{ + if (ts_cmp(a, b) > 0) { + tv->tv_sec = a->tv_sec; + tv->tv_nsec = a->tv_nsec; + } else { + tv->tv_sec = b->tv_sec; + tv->tv_nsec = b->tv_nsec; + } +} + #if !defined HAVE_STPCPY char * stpcpy(char *dst, const char *src)