From: Sven M. Hallberg Date: Fri, 29 Aug 2014 18:31:44 +0000 (+0200) Subject: work around lack of fcntl on Windows X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=278b079946ce138ecda5f270d937476c9d3946ba;p=catta work around lack of fcntl on Windows --- diff --git a/configure.ac b/configure.ac index 401a9ae..696903e 100644 --- a/configure.ac +++ b/configure.ac @@ -282,7 +282,7 @@ AC_CHECK_HEADERS([arpa/inet.h fcntl.h netinet/in.h sys/ioctl.h sys/socket.h sys/ # Checks for library functions. AC_FUNC_SELECT_ARGTYPES -AC_CHECK_FUNCS([gethostname select socket uname strcasecmp gettimeofday strncasecmp strlcpy]) +AC_CHECK_FUNCS([gethostname select socket uname strcasecmp gettimeofday strncasecmp strlcpy fcntl]) AC_FUNC_CHOWN AC_FUNC_STAT diff --git a/src/fdutil.c b/src/fdutil.c index c483ce8..ca5f65b 100644 --- a/src/fdutil.c +++ b/src/fdutil.c @@ -23,9 +23,14 @@ #include #include -#include #include +#ifdef HAVE_FCNTL +#include +#else +#include +#endif + #include "fdutil.h" int catta_set_cloexec(int fd) { @@ -33,6 +38,7 @@ int catta_set_cloexec(int fd) { assert(fd >= 0); +#if defined(HAVE_FCNTL) if ((n = fcntl(fd, F_GETFD)) < 0) return -1; @@ -40,6 +46,15 @@ int catta_set_cloexec(int fd) { return 0; return fcntl(fd, F_SETFD, n|FD_CLOEXEC); +#elif defined(_WIN32) + (void)n; + if(!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) + return -1; + return 0; +#else + (void)n; + return -1; +#endif } int catta_set_nonblock(int fd) { @@ -47,6 +62,7 @@ int catta_set_nonblock(int fd) { assert(fd >= 0); +#ifdef HAVE_FCNTL if ((n = fcntl(fd, F_GETFL)) < 0) return -1; @@ -54,6 +70,10 @@ int catta_set_nonblock(int fd) { return 0; return fcntl(fd, F_SETFL, n|O_NONBLOCK); +#else + n = 1; + return ioctl(fd, FIONBIO, &n); +#endif } int catta_wait_for_write(int fd) {