summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-01 23:11:55 -0500
committerpommicket <pommicket@gmail.com>2023-01-01 23:11:55 -0500
commit850ab378946e8d6f0818b4ccf8eee413f68dcb95 (patch)
tree579230cbcf4f6f4a4a00504178ea6ca1b7d5ab8f /util.c
parent3ee947ced94ce24463838e0c587cb076ac81ec98 (diff)
start os.h merging
Diffstat (limited to 'util.c')
-rw-r--r--util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/util.c b/util.c
index 39d1e39..f8bdab5 100644
--- a/util.c
+++ b/util.c
@@ -1228,3 +1228,25 @@ u32 color_interpolate(float x, u32 color1, u32 color2) {
c_out = color_hsva_to_rgba(c_out);
return rgba_v4_to_u32(c_out);
}
+
+
+int timespec_cmp(struct timespec a, struct timespec b) {
+ if (a.tv_sec > b.tv_sec) return 1;
+ if (a.tv_sec < b.tv_sec) return -1;
+ if (a.tv_nsec > b.tv_nsec) return 1;
+ if (a.tv_nsec < b.tv_nsec) return -1;
+ return 0;
+}
+
+bool timespec_eq(struct timespec a, struct timespec b) {
+ return timespec_cmp(a, b) == 0;
+}
+
+struct timespec timespec_max(struct timespec a, struct timespec b) {
+ return timespec_cmp(a, b) < 0 ? b : a;
+}
+
+double timespec_to_seconds(struct timespec ts) {
+ return (double)ts.tv_sec
+ + (double)ts.tv_nsec * 1e-9;
+}