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;
+ if (flx_timeval_compare(a, b) < 0)
+ return flx_timeval_diff(b, a);
+
+ return ((glong) a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
}
return tv;
}
+
+gint flx_age(const GTimeVal *a) {
+ GTimeVal now;
+
+ g_assert(a);
+
+ g_get_current_time(&now);
+
+ return flx_timeval_diff(&now, a);
+}
+
+gboolean flx_domain_equal(const gchar *a, const gchar *b) {
+ g_assert(a);
+ g_assert(b);
+
+ for (;;) {
+ if (*a == 0 && *b == 0)
+ return TRUE;
+
+ if (*a == 0 && *b == '.' && *(b+1) == 0)
+ return TRUE;
+
+ if (*a == '.' && *(a+1) == 0 && *b == 0)
+ return TRUE;
+
+ if (*a != *b)
+ return FALSE;
+
+ a++;
+ b++;
+ }
+}
+
+guint flx_domain_hash(const gchar *p) {
+ char t[256];
+ strncpy(t, p, sizeof(t)-1);
+ t[sizeof(t)-1] = 0;
+
+ return g_int_hash(t);
+}
+