From: Andrei Tatar Date: Mon, 24 Feb 2025 14:30:07 +0000 (+0100) Subject: lib/uktimeconv: Add time spec validation inlines X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=72721647cc9c2e29b8abf6877e65dc96944a7427;p=unikraft%2Funikraft.git lib/uktimeconv: Add time spec validation inlines This change adds inlines to check whether a timespec is in canonical form, and if so whether it represents positive time. Signed-off-by: Andrei Tatar Approved-by: Sergiu Moga Reviewed-by: Sergiu Moga GitHub-Closes: #1566 --- diff --git a/lib/uktimeconv/include/uk/timeutil.h b/lib/uktimeconv/include/uk/timeutil.h index 2f5cf3489..bfe9e94a5 100644 --- a/lib/uktimeconv/include/uk/timeutil.h +++ b/lib/uktimeconv/include/uk/timeutil.h @@ -39,6 +39,24 @@ .tv_usec = ukarch_time_nsec_to_usec((ts)->tv_nsec) \ }) +/** + * Return non-zero if `t` is canonical (nanoseconds in [0, 999999999] range). + */ +static inline +int uk_time_spec_canonical(const struct timespec *t) +{ + return t->tv_nsec >= 0 && t->tv_nsec < 1000000000; +} + +/** + * Return non-zero if canonical `t` represents zero or positive time. + */ +static inline +int uk_time_spec_positive(const struct timespec *t) +{ + return t->tv_sec >= 0; +} + static inline __snsec uk_time_spec_nsecdiff(const struct timespec *t1, const struct timespec *t2)