summaryrefslogtreecommitdiffstats
path: root/polyp/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'polyp/util.c')
-rw-r--r--polyp/util.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/polyp/util.c b/polyp/util.c
index 2878c546..6c8febb6 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -36,6 +36,7 @@
#include <pwd.h>
#include <signal.h>
#include <pthread.h>
+#include <sys/time.h>
#include "util.h"
#include "xmalloc.h"
@@ -192,3 +193,23 @@ char *pa_get_host_name(char *s, size_t l) {
s[l-1] = 0;
return s;
}
+
+uint32_t pa_age(struct timeval *tv) {
+ struct timeval now;
+ uint32_t r;
+ assert(tv);
+
+ if (tv->tv_sec == 0)
+ return 0;
+
+ gettimeofday(&now, NULL);
+
+ r = (now.tv_sec-tv->tv_sec) * 1000000;
+
+ if (now.tv_usec >= tv->tv_usec)
+ r += now.tv_usec - tv->tv_usec;
+ else
+ r -= tv->tv_usec - now.tv_usec;
+
+ return r;
+}