summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-01-21 22:08:15 +0000
committerLennart Poettering <lennart@poettering.net>2005-01-21 22:08:15 +0000
commit4ba1a4b0b4488e5058af67b789187735b529075e (patch)
treed1d0f8ee6c36659b552fc371cad67678ae90b7c8 /util.c
parentb25580915c7223c276348c39d5e7ed496a58a26e (diff)
add infrastrtcur for creating and sending DNS packets
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@10 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'util.c')
-rw-r--r--util.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/util.c b/util.c
index 62574ba..faf1ac0 100644
--- a/util.c
+++ b/util.c
@@ -1,5 +1,7 @@
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
#include "util.h"
@@ -50,3 +52,50 @@ glong flx_timeval_diff(const GTimeVal *a, const GTimeVal *b) {
return (a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
}
+
+
+gint flx_set_cloexec(gint fd) {
+ gint n;
+
+ g_assert(fd >= 0);
+
+ if ((n = fcntl(fd, F_GETFD)) < 0)
+ return -1;
+
+ if (n & FD_CLOEXEC)
+ return 0;
+
+ return fcntl(fd, F_SETFD, n|FD_CLOEXEC);
+}
+
+gint flx_set_nonblock(gint fd) {
+ gint n;
+
+ g_assert(fd >= 0);
+
+ if ((n = fcntl(fd, F_GETFL)) < 0)
+ return -1;
+
+ if (n & O_NONBLOCK)
+ return 0;
+
+ return fcntl(fd, F_SETFL, n|O_NONBLOCK);
+}
+
+gint flx_wait_for_write(gint fd) {
+ fd_set fds;
+ gint r;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ if ((r = select(fd+1, NULL, &fds, NULL, NULL)) < 0) {
+ g_message("select() failed: %s", strerror(errno));
+
+ return -1;
+ }
+
+ g_assert(r > 0);
+
+ return 0;
+}