From 0da96d48e07f6a6b79a4078d07bc066d1f87c8fd Mon Sep 17 00:00:00 2001
From: Vincent Torri <vincent.torri@gmail.com>
Date: Sat, 1 Apr 2017 17:34:32 +0200
Subject: [PATCH 2/2] Evil: fix fcntl() with sockets

On Windows, _get_osfhandle() does not work on sockets. Just cast the socket
to a HANDLE when using SetHandleInformation()
---
 src/lib/evil/evil_fcntl.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/src/lib/evil/evil_fcntl.c b/src/lib/evil/evil_fcntl.c
index 188e476fa9..65cdf37f1a 100644
--- a/src/lib/evil/evil_fcntl.c
+++ b/src/lib/evil/evil_fcntl.c
@@ -26,14 +26,9 @@ int fcntl(int fd, int cmd, ...)
 
    if (cmd == F_GETFD)
      {
-        HANDLE  h;
         DWORD flag;
 
-        h = (HANDLE)_get_osfhandle(fd);
-        if (h == INVALID_HANDLE_VALUE)
-          return -1;
-
-	if (!GetHandleInformation(h, &flag))
+	if (!GetHandleInformation((HANDLE)fd, &flag))
           {
              /* FIXME: should we close h ? MSDN seems to say that */
              return -1;
@@ -44,17 +39,12 @@ int fcntl(int fd, int cmd, ...)
 
    if (cmd == F_SETFD)
      {
-        HANDLE  h;
         long flag;
 
-        h = (HANDLE)_get_osfhandle(fd);
-        if (h == INVALID_HANDLE_VALUE)
-          return -1;
-
         flag = va_arg(va, long);
         if (flag == FD_CLOEXEC)
           {
-             if (SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0))
+             if (SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0))
                res = 0;
           }
      }
-- 
2.11.0

