From 278b079946ce138ecda5f270d937476c9d3946ba Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Fri, 29 Aug 2014 20:31:44 +0200 Subject: [PATCH] work around lack of fcntl on Windows --- configure.ac | 2 +- src/fdutil.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) 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) { -- 2.39.2