From bac8214e90488fd562d29f6fea18ae75ecd9029e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 27 Nov 2024 20:55:51 -0500 Subject: xtime: New timespec utility functions --- src/xtime.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/xtime.h') diff --git a/src/xtime.h b/src/xtime.h index 2927a2e..b76fef2 100644 --- a/src/xtime.h +++ b/src/xtime.h @@ -46,6 +46,42 @@ int xtimegm(struct tm *tm, time_t *timep); */ int xgetdate(const char *str, struct timespec *result); +/** + * Add to a timespec. + */ +void timespec_add(struct timespec *lhs, const struct timespec *rhs); + +/** + * Subtract from a timespec. + */ +void timespec_sub(struct timespec *lhs, const struct timespec *rhs); + +/** + * Compare two timespecs. + * + * @return + * An integer with the sign of (*lhs - *rhs). + */ +int timespec_cmp(const struct timespec *lhs, const struct timespec *rhs); + +/** + * Update a minimum timespec. + */ +void timespec_min(struct timespec *dest, const struct timespec *src); + +/** + * Update a maximum timespec. + */ +void timespec_max(struct timespec *dest, const struct timespec *src); + +/** + * Convert a timespec to floating point. + * + * @return + * The value in nanoseconds. + */ +double timespec_ns(const struct timespec *ts); + /** * A timer. */ -- cgit v1.2.3