summaryrefslogtreecommitdiffstats
path: root/common.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2008-06-07 00:11:17 +0000
committerRoy Marples <roy@marples.name>2008-06-07 00:11:17 +0000
commit751e2f818d970ca55fc094647df3ab9345ad3166 (patch)
tree6d8125094743259114b8494d36b7e197d637ed27 /common.c
parentfedb3da0be34b47246d663e6ff55a7e0937515c0 (diff)
downloaddhcpcd-751e2f818d970ca55fc094647df3ab9345ad3166.tar.xz
Add a function to test if a fd has data to be read.
Diffstat (limited to 'common.c')
-rw-r--r--common.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/common.c b/common.c
index 32df8844..7eeb1d9d 100644
--- a/common.c
+++ b/common.c
@@ -33,6 +33,7 @@
#ifdef BSD
# include <paths.h>
#endif
+#include <poll.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -151,6 +152,25 @@ close_fds(void)
}
int
+fd_hasdata(int fd)
+{
+ struct pollfd fds;
+ int retval;
+
+ if (fd == -1)
+ return -1;
+ fds.fd = fd;
+ fds.events = POLLIN;
+ fds.revents = 0;
+ retval = poll(&fds, 1, 0);
+ if (retval == -1)
+ return -1;
+ if (retval > 0 && fds.revents & POLLIN)
+ return retval;
+ return 0;
+}
+
+int
close_on_exec(int fd)
{
int flags;