discomfitor pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=0af6fcbc2a781c40b8dfca026852dc80bd1f7a90

commit 0af6fcbc2a781c40b8dfca026852dc80bd1f7a90
Author: Vincent Torri <[email protected]>
Date:   Sun Sep 28 15:26:51 2014 +0200

    Evil: fix fcntl() when used with F_SETFL
    
    @fix
---
 src/lib/evil/evil_fcntl.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/lib/evil/evil_fcntl.c b/src/lib/evil/evil_fcntl.c
index 76b6a60..169d192 100644
--- a/src/lib/evil/evil_fcntl.c
+++ b/src/lib/evil/evil_fcntl.c
@@ -23,29 +23,37 @@
 int fcntl(int fd, int cmd, ...)
 {
    va_list va;
-   HANDLE  h;
    int     res = -1;
 
    va_start (va, cmd);
 
-   h = (HANDLE)_get_osfhandle(fd);
-   if (h == INVALID_HANDLE_VALUE)
-     return -1;
-
    if (cmd == F_GETFD)
      {
+        HANDLE  h;
         DWORD flag;
 
+        h = (HANDLE)_get_osfhandle(fd);
+        if (h == INVALID_HANDLE_VALUE)
+          return -1;
+
        if (!GetHandleInformation(h, &flag))
-         return -1;
+          {
+             /* FIXME: should we close h ? MSDN seems to say that */
+             return -1;
+          }
 
        res = 0;
      }
 
    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)
           {
@@ -73,7 +81,7 @@ int fcntl(int fd, int cmd, ...)
              ret = getsockopt((SOCKET)fd, SOL_SOCKET, SO_TYPE, (char *)&type, 
&len);
              if (!ret && (type == SOCK_STREAM))
                {
-                  if (!ioctlsocket((SOCKET)fd, FIONBIO, &arg) == SOCKET_ERROR)
+                  if (ioctlsocket((SOCKET)fd, FIONBIO, &arg) != SOCKET_ERROR)
                     res = 0;
                }
           }

-- 


Reply via email to