super fading
[dana/dcompmgr.git] / time.c
diff --git a/time.c b/time.c
index 38b60b2..889fdd7 100644 (file)
--- a/time.c
+++ b/time.c
@@ -1,9 +1,8 @@
 #include "time.h"
 
-void
-time_add(struct timeval *tv, long microseconds)
+static inline void
+time_fix(struct timeval *tv)
 {
-    tv->tv_usec += microseconds;
     while (tv->tv_usec >= 1000000) {
         tv->tv_usec -= 1000000;
         ++tv->tv_sec;
@@ -14,10 +13,28 @@ time_add(struct timeval *tv, long microseconds)
     }
 }
 
+void
+time_add(struct timeval *tv, long microseconds)
+{
+    tv->tv_usec += microseconds;
+    time_fix(tv);
+}
+
 long
-time_compare(struct timeval *a, struct timeval *b)
+time_compare(const struct timeval *a, const struct timeval *b)
 {
     long r;
     if ((r = a->tv_sec - b->tv_sec)) return r;
     return a->tv_usec - b->tv_usec;
 }
+
+void
+time_difference(const struct timeval *a, const struct timeval *b,
+                struct timeval *r)
+{
+    struct timeval v;
+    v.tv_sec = a->tv_sec - b->tv_sec;
+    v.tv_usec = a->tv_usec - b->tv_usec;
+    time_fix(&v);
+    *r = v;
+}