utils: move ARRAY_SIZE from uloop to utils.h
[project/libubox.git] / uloop.c
diff --git a/uloop.c b/uloop.c
index 6bc974d..88e9c81 100644 (file)
--- a/uloop.c
+++ b/uloop.c
@@ -32,6 +32,7 @@
 #include <stdbool.h>
 
 #include "uloop.h"
+#include "utils.h"
 
 #ifdef USE_KQUEUE
 #include <sys/event.h>
 #endif
 #include <sys/wait.h>
 
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-#endif
 #define ULOOP_MAX_EVENTS 10
 
 static struct list_head timeouts = LIST_HEAD_INIT(timeouts);
@@ -304,10 +301,9 @@ out:
 
 static int tv_diff(struct timeval *t1, struct timeval *t2)
 {
-       if (t1->tv_sec != t2->tv_sec)
-               return (t1->tv_sec - t2->tv_sec) * 1000;
-       else
-               return (t1->tv_usec - t2->tv_usec) / 1000;
+       return
+               (t1->tv_sec - t2->tv_sec) * 1000 +
+               (t1->tv_usec - t2->tv_usec) / 1000;
 }
 
 int uloop_timeout_add(struct uloop_timeout *timeout)