8 gchar *flx_get_host_name(void) {
10 gethostname(t, sizeof(t));
11 return g_strndup(t, sizeof(t));
14 gchar *flx_normalize_name(const gchar *s) {
26 return g_strdup_printf("%s.", s);
29 gint flx_timeval_compare(const GTimeVal *a, const GTimeVal *b) {
33 if (a->tv_sec < b->tv_sec)
36 if (a->tv_sec > b->tv_sec)
39 if (a->tv_usec < b->tv_usec)
42 if (a->tv_usec > b->tv_usec)
48 glong flx_timeval_diff(const GTimeVal *a, const GTimeVal *b) {
52 if (flx_timeval_compare(a, b) < 0)
53 return flx_timeval_diff(b, a);
55 return ((glong) a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
59 gint flx_set_cloexec(gint fd) {
64 if ((n = fcntl(fd, F_GETFD)) < 0)
70 return fcntl(fd, F_SETFD, n|FD_CLOEXEC);
73 gint flx_set_nonblock(gint fd) {
78 if ((n = fcntl(fd, F_GETFL)) < 0)
84 return fcntl(fd, F_SETFL, n|O_NONBLOCK);
87 gint flx_wait_for_write(gint fd) {
94 if ((r = select(fd+1, NULL, &fds, NULL, NULL)) < 0) {
95 g_message("select() failed: %s", strerror(errno));
105 GTimeVal *flx_elapse_time(GTimeVal *tv, guint msec, guint jitter) {
108 g_get_current_time(tv);
111 g_time_val_add(tv, msec*1000);
114 g_time_val_add(tv, g_random_int_range(0, jitter) * 1000);
119 gint flx_age(const GTimeVal *a) {
124 g_get_current_time(&now);
126 return flx_timeval_diff(&now, a);
129 gboolean flx_domain_equal(const gchar *a, const gchar *b) {
134 if (*a == 0 && *b == 0)
137 if (*a == 0 && *b == '.' && *(b+1) == 0)
140 if (*a == '.' && *(a+1) == 0 && *b == 0)
151 guint flx_domain_hash(const gchar *p) {
153 strncpy(t, p, sizeof(t)-1);
156 return g_int_hash(t);