util: add ts_min and ts_max

* defs.h (ts_min, ts_max): New declarations.
* util.c (ts_min, ts_max): New functions.
This commit is contained in:
Eugene Syromyatnikov 2018-09-02 20:03:27 +02:00
parent f73d6361c1
commit 7c7705fbc9
2 changed files with 26 additions and 0 deletions

2
defs.h
View File

@ -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);

24
util.c
View File

@ -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)