X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=util.c;fp=util.c;h=62574ba524d83920bf9b8f448ef3f90deeae3987;hb=0781d5363fb6fd723a2316fc7558aef6439b2f71;hp=334a7990e4cbd1bc417f47fa7b9db5a5f4f808b6;hpb=d6e2dbabccb08970da991e6d2b0fda7a56d83e6f;p=catta diff --git a/util.c b/util.c index 334a799..62574ba 100644 --- a/util.c +++ b/util.c @@ -24,3 +24,29 @@ gchar *flx_normalize_name(const gchar *s) { return g_strdup_printf("%s.", s); } +gint flx_timeval_compare(const GTimeVal *a, const GTimeVal *b) { + g_assert(a); + g_assert(b); + + if (a->tv_sec < b->tv_sec) + return -1; + + if (a->tv_sec > b->tv_sec) + return 1; + + if (a->tv_usec < b->tv_usec) + return -1; + + if (a->tv_usec > b->tv_usec) + return 1; + + return 0; +} + +glong flx_timeval_diff(const GTimeVal *a, const GTimeVal *b) { + g_assert(a); + g_assert(b); + g_assert(flx_timeval_compare(a, b) >= 0); + + return (a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec; +}