]> granicus.if.org Git - strace/commitdiff
util: add ts_min and ts_max
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sun, 2 Sep 2018 18:03:27 +0000 (20:03 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 6 Aug 2019 13:38:20 +0000 (13:38 +0000)
* defs.h (ts_min, ts_max): New declarations.
* util.c (ts_min, ts_max): New functions.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
defs.h
util.c

diff --git a/defs.h b/defs.h
index 56bd993f8dbc026ddf59ee39de760743aeb74af1..cd71d9988a32bb4b9bc538b732609d15276747e1 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -969,6 +969,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 const struct timespec *ts_min(const struct timespec *, const struct timespec *);
+extern const struct timespec *ts_max(const struct timespec *, const struct timespec *);
 extern int parse_ts(const char *s, struct timespec *t);
 
 # ifdef ENABLE_STACKTRACE
diff --git a/util.c b/util.c
index 1d2c621ffdde21fc841723d4ff7731ee3f7e2de8..ec86cdb98fdca4e72c0cdb57ead81b2a95f42c88 100644 (file)
--- a/util.c
+++ b/util.c
@@ -92,6 +92,18 @@ ts_mul(struct timespec *tv, const struct timespec *a, int n)
        tv->tv_nsec = nsec % 1000000000;
 }
 
+const struct timespec *
+ts_min(const struct timespec *a, const struct timespec *b)
+{
+       return ts_cmp(a, b) < 0 ? a : b;
+}
+
+const struct timespec *
+ts_max(const struct timespec *a, const struct timespec *b)
+{
+       return ts_cmp(a, b) > 0 ? a : b;
+}
+
 int
 parse_ts(const char *s, struct timespec *t)
 {