Evil: fix fcntl() when used with F_SETFL

@fix
This commit is contained in:
Vincent Torri 2014-09-28 15:26:51 +02:00 committed by zmike
parent 60bc2cc1ce
commit 0af6fcbc2a
1 changed files with 15 additions and 7 deletions

View File

@ -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;
}
}