add a next_repaint time to each screen
[dana/dcompmgr.git] / time.c
diff --git a/time.c b/time.c
new file mode 100644 (file)
index 0000000..38b60b2
--- /dev/null
+++ b/time.c
@@ -0,0 +1,23 @@
+#include "time.h"
+
+void
+time_add(struct timeval *tv, long microseconds)
+{
+    tv->tv_usec += microseconds;
+    while (tv->tv_usec >= 1000000) {
+        tv->tv_usec -= 1000000;
+        ++tv->tv_sec;
+    }
+    while (tv->tv_usec < 0) {
+        tv->tv_usec += 1000000;
+        --tv->tv_sec;
+    }
+}
+
+long
+time_compare(struct timeval *a, struct timeval *b)
+{
+    long r;
+    if ((r = a->tv_sec - b->tv_sec)) return r;
+    return a->tv_usec - b->tv_usec;
+}