]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/uktimeconv: Add time spec validation inlines
authorAndrei Tatar <andrei@unikraft.io>
Mon, 24 Feb 2025 14:30:07 +0000 (15:30 +0100)
committerUnikraft Bot <monkey@unikraft.io>
Tue, 25 Feb 2025 07:59:37 +0000 (07:59 +0000)
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 <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1566

lib/uktimeconv/include/uk/timeutil.h

index 2f5cf34891ea7a1c4d56b6a51b6c0cd187210c11..bfe9e94a55054473277e0b1d6e5560e0e4e49074 100644 (file)
        .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)