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, ...@@ -1075,15 +1075,25 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage ) LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
{ {
#ifdef FIONREAD #ifdef FIONREAD
int avail=0,fd; int avail=0, fd, ret, flags;
fd = FILE_GetUnixHandle(hPipe, GENERIC_READ); ret = wine_server_handle_to_fd( hPipe, GENERIC_READ, &fd, NULL, &flags );
if (fd == -1) return FALSE; 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) if (ioctl(fd,FIONREAD, &avail ) != 0)
{ {
TRACE("FIONREAD failed reason: %s\n",strerror(errno)); TRACE("FIONREAD failed reason: %s\n",strerror(errno));
close(fd); wine_server_release_fd( hPipe, fd );
return FALSE; return FALSE;
} }
if (!avail) /* check for closed pipe */ if (!avail) /* check for closed pipe */
...@@ -1101,12 +1111,12 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer, ...@@ -1101,12 +1111,12 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
TRACE("POLLHUP | POLLERR\n"); TRACE("POLLHUP | POLLERR\n");
/* fall through */ /* fall through */
case -1: case -1:
close(fd); wine_server_release_fd( hPipe, fd );
SetLastError(ERROR_BROKEN_PIPE); SetLastError(ERROR_BROKEN_PIPE);
return FALSE; return FALSE;
} }
} }
close(fd); wine_server_release_fd( hPipe, fd );
TRACE(" 0x%08x bytes available\n", avail ); TRACE(" 0x%08x bytes available\n", avail );
if (!lpvBuffer && lpcbAvail) if (!lpvBuffer && lpcbAvail)
{ {
......
...@@ -129,8 +129,7 @@ static void INT13_ReadFloppyParams( CONTEXT86 *context ) ...@@ -129,8 +129,7 @@ static void INT13_ReadFloppyParams( CONTEXT86 *context )
return; return;
} }
r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm); r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm);
wine_server_release_fd( h, floppy_fd );
close(floppy_fd);
CloseHandle(h); CloseHandle(h);
if(r<0) if(r<0)
......
...@@ -202,40 +202,6 @@ void FILE_SetDosError(void) ...@@ -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.@) * OpenConsoleW (KERNEL32.@)
* *
......
...@@ -70,7 +70,6 @@ extern mode_t FILE_umask; ...@@ -70,7 +70,6 @@ extern mode_t FILE_umask;
extern int FILE_strcasecmp( const char *str1, const char *str2 ); extern int FILE_strcasecmp( const char *str1, const char *str2 );
extern int FILE_strncasecmp( const char *str1, const char *str2, int len ); extern int FILE_strncasecmp( const char *str1, const char *str2, int len );
extern void FILE_SetDosError(void); 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 BOOL FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info, BOOL *is_symlink );
extern HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 ); extern HFILE16 FILE_Dup2( HFILE16 hFile1, HFILE16 hFile2 );
extern HANDLE FILE_CreateFile( LPCSTR filename, DWORD access, DWORD sharing, 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