#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;
}
}
+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;
+}