aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/timespec-util.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/timespec-util.h b/src/timespec-util.h
index d37568d..d3c53bd 100644
--- a/src/timespec-util.h
+++ b/src/timespec-util.h
@@ -290,4 +290,22 @@ timespec_add(struct timespec *r,
}
}
+/**
+ * Saturating timespec subtraction
+ *
+ * \param r[out] result: max(a - b, 0)
+ * \param a[in] operand
+ * \param b[in] operand
+ */
+static inline void
+timespec_sub_saturate(struct timespec *r,
+ const struct timespec *a, const struct timespec *b)
+{
+ timespec_sub(r, a, b);
+ if (r->tv_sec < 0) {
+ r->tv_sec = 0;
+ r->tv_nsec = 0;
+ }
+}
+
#endif /* TIMESPEC_UTIL_H */