diff options
| author | Roy Marples <roy@marples.name> | 2008-06-07 00:11:17 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-06-07 00:11:17 +0000 |
| commit | 751e2f818d970ca55fc094647df3ab9345ad3166 (patch) | |
| tree | 6d8125094743259114b8494d36b7e197d637ed27 /common.c | |
| parent | fedb3da0be34b47246d663e6ff55a7e0937515c0 (diff) | |
| download | dhcpcd-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.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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; |
