Commit 04ecca54 authored by Alexandre Julliard's avatar Alexandre Julliard

Use wine_server_release_fd() instead of close() everywhere we use

wine_server_handle_to_fd(). A few minor winsock cleanups.
parent ef799c46
......@@ -1075,15 +1075,25 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
{
#ifdef FIONREAD
int avail=0,fd;
int avail=0, fd, ret, flags;
fd = FILE_GetUnixHandle(hPipe, GENERIC_READ);
if (fd == -1) return FALSE;
ret = wine_server_handle_to_fd( hPipe, GENERIC_READ, &fd, NULL, &flags );
if (ret)
{
SetLastError( RtlNtStatusToDosError(ret) );
return FALSE;
}
if (flags & FD_FLAG_RECV_SHUTDOWN)
{
wine_server_release_fd( hPipe, fd );
SetLastError ( ERROR_PIPE_NOT_CONNECTED );
return FALSE;
}
if (ioctl(fd,FIONREAD, &avail ) != 0)
{
TRACE("FIONREAD failed reason: %s\n",strerror(errno));
close(fd);
wine_server_release_fd( hPipe, fd );
return FALSE;
}
if (!avail) /* check for closed pipe */
......@@ -1101,12 +1111,12 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
TRACE("POLLHUP | POLLERR\n");
/* fall through */
case -1:
close(fd);
wine_server_release_fd( hPipe, fd );
SetLastError(ERROR_BROKEN_PIPE);
return FALSE;
}
}
close(fd);
wine_server_release_fd( hPipe, fd );
TRACE(" 0x%08x bytes available\n", avail );
if (!lpvBuffer && lpcbAvail)
{
......
......@@ -129,8 +129,7 @@ static void INT13_ReadFloppyParams( CONTEXT86 *context )
return;
}
r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
close(floppy_fd);
wine_server_release_fd( h, floppy_fd );
CloseHandle(h);
if(r<0)
......
......@@ -202,40 +202,6 @@ void FILE_SetDosError(void)
}
/***********************************************************************
* FILE_GetUnixHandleType
*
* Retrieve the Unix handle corresponding to a file handle.
* Returns -1 on failure.
*/
static int FILE_GetUnixHandleType( HANDLE handle, DWORD access, enum fd_type *type, int *flags_ptr )
{
int ret, flags, fd = -1;
ret = wine_server_handle_to_fd( handle, access, &fd, type, &flags );
if (flags_ptr) *flags_ptr = flags;
if (ret) SetLastError( RtlNtStatusToDosError(ret) );
else if (((access & GENERIC_READ) && (flags & FD_FLAG_RECV_SHUTDOWN)) ||
((access & GENERIC_WRITE) && (flags & FD_FLAG_SEND_SHUTDOWN)))
{
close (fd);
SetLastError ( ERROR_PIPE_NOT_CONNECTED );
return -1;
}
return fd;
}
/***********************************************************************
* FILE_GetUnixHandle
*
* Retrieve the Unix handle corresponding to a file handle.
* Returns -1 on failure.
*/
int FILE_GetUnixHandle( HANDLE handle, DWORD access )
{
return FILE_GetUnixHandleType( handle, access, NULL, NULL );
}
/******************************************************************
* OpenConsoleW (KERNEL32.@)
*
......
......@@ -70,7 +70,6 @@ extern mode_t FILE_umask;
extern int FILE_strcasecmp( const char *str1, const char *str2 );
extern int FILE_strncasecmp( const char *str1, const char *str2, int len );
extern void FILE_SetDosError(void);
extern int FILE_GetUnixHandle( HANDLE handle, DWORD access );
extern BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info, BOOL *is_symlink );
extern HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 );
extern HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment