From 410db2ada4dce2989ba600c2857714c51378a651 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 14 Jun 2004 19:40:44 +0000 Subject: [PATCH] Rewrote SetFilePointer to use SetFilePointerEx. --- dlls/kernel/file.c | 46 ++++++++++------------------------------------ include/winbase.h | 1 + 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/dlls/kernel/file.c b/dlls/kernel/file.c index ab71dc0a19..75659b257c 100644 --- a/dlls/kernel/file.c +++ b/dlls/kernel/file.c @@ -815,48 +815,22 @@ BOOL WINAPI SetEndOfFile( HANDLE hFile ) /*********************************************************************** * SetFilePointer (KERNEL32.@) */ -DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, - DWORD method ) +DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, DWORD method ) { - static const int whence[3] = { SEEK_SET, SEEK_CUR, SEEK_END }; - DWORD ret = INVALID_SET_FILE_POINTER; - NTSTATUS status; - int fd; + LARGE_INTEGER dist, newpos; - TRACE("handle %p offset %ld high %ld origin %ld\n", - hFile, distance, highword?*highword:0, method ); - - if (method > FILE_END) + if (highword) { - SetLastError( ERROR_INVALID_PARAMETER ); - return ret; + dist.u.LowPart = distance; + dist.u.HighPart = *highword; } + else dist.QuadPart = distance; - if (!(status = wine_server_handle_to_fd( hFile, 0, &fd, NULL, NULL ))) - { - off_t pos, res; + if (!SetFilePointerEx( hFile, dist, &newpos, method )) return INVALID_SET_FILE_POINTER; - if (highword) pos = ((off_t)*highword << 32) | (ULONG)distance; - else pos = (off_t)distance; - if ((res = lseek( fd, pos, whence[method] )) == (off_t)-1) - { - /* also check EPERM due to SuSE7 2.2.16 lseek() EPERM kernel bug */ - if (((errno == EINVAL) || (errno == EPERM)) && (method != FILE_BEGIN) && (pos < 0)) - SetLastError( ERROR_NEGATIVE_SEEK ); - else - FILE_SetDosError(); - } - else - { - ret = (DWORD)res; - if (highword) *highword = (res >> 32); - if (ret == INVALID_SET_FILE_POINTER) SetLastError( 0 ); - } - wine_server_release_fd( hFile, fd ); - } - else SetLastError( RtlNtStatusToDosError(status) ); - - return ret; + if (highword) *highword = newpos.u.HighPart; + if (newpos.u.LowPart == INVALID_SET_FILE_POINTER) SetLastError( 0 ); + return newpos.u.LowPart; } diff --git a/include/winbase.h b/include/winbase.h index 5b4738d953..09c47f55ce 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -1621,6 +1621,7 @@ BOOL WINAPI SetEvent(HANDLE); VOID WINAPI SetFileApisToANSI(void); VOID WINAPI SetFileApisToOEM(void); DWORD WINAPI SetFilePointer(HANDLE,LONG,LPLONG,DWORD); +BOOL WINAPI SetFilePointerEx(HANDLE,LARGE_INTEGER,LARGE_INTEGER*,DWORD); BOOL WINAPI SetFileSecurityA(LPCSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR); BOOL WINAPI SetFileSecurityW(LPCWSTR,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR); #define SetFileSecurity WINELIB_NAME_AW(SetFileSecurity)