Browse Source

util: add ts_min and ts_max

* 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>
Eugene Syromyatnikov 1 year ago
parent
commit
4b2175f526
2 changed files with 14 additions and 0 deletions
  1. 2
    0
      defs.h
  2. 12
    0
      util.c

+ 2
- 0
defs.h View File

@@ -969,6 +969,8 @@ extern void ts_add(struct timespec *, const struct timespec *, const struct time
969 969
 extern void ts_sub(struct timespec *, const struct timespec *, const struct timespec *);
970 970
 extern void ts_mul(struct timespec *, const struct timespec *, int);
971 971
 extern void ts_div(struct timespec *, const struct timespec *, int);
972
+extern const struct timespec *ts_min(const struct timespec *, const struct timespec *);
973
+extern const struct timespec *ts_max(const struct timespec *, const struct timespec *);
972 974
 extern int parse_ts(const char *s, struct timespec *t);
973 975
 
974 976
 # ifdef ENABLE_STACKTRACE

+ 12
- 0
util.c View File

@@ -92,6 +92,18 @@ ts_mul(struct timespec *tv, const struct timespec *a, int n)
92 92
 	tv->tv_nsec = nsec % 1000000000;
93 93
 }
94 94
 
95
+const struct timespec *
96
+ts_min(const struct timespec *a, const struct timespec *b)
97
+{
98
+	return ts_cmp(a, b) < 0 ? a : b;
99
+}
100
+
101
+const struct timespec *
102
+ts_max(const struct timespec *a, const struct timespec *b)
103
+{
104
+	return ts_cmp(a, b) > 0 ? a : b;
105
+}
106
+
95 107
 int
96 108
 parse_ts(const char *s, struct timespec *t)
97 109
 {

Loading…
Cancel
Save