From 2cb4361c06669803d4ec057cc96c306b254be230 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 1 Nov 2006 16:12:57 +0100 Subject: [PATCH] kernel32: Reimplemented SetFilePointerEx on top of ntdll functions. --- dlls/kernel32/file.c | 65 +++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/dlls/kernel32/file.c b/dlls/kernel32/file.c index 8f8890d2136..d0b28d063b6 100644 --- a/dlls/kernel32/file.c +++ b/dlls/kernel32/file.c @@ -47,7 +47,6 @@ #include "wine/unicode.h" #include "wine/debug.h" #include "thread.h" -#include "wine/server.h" WINE_DEFAULT_DEBUG_CHANNEL(file); @@ -940,44 +939,48 @@ DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, DWORD BOOL WINAPI SetFilePointerEx( HANDLE hFile, LARGE_INTEGER distance, LARGE_INTEGER *newpos, DWORD method ) { - static const int whence[3] = { SEEK_SET, SEEK_CUR, SEEK_END }; - BOOL ret = FALSE; - NTSTATUS status; - int fd; - - TRACE("handle %p offset %s newpos %p origin %d\n", - hFile, wine_dbgstr_longlong(distance.QuadPart), newpos, method ); + LONGLONG pos; + IO_STATUS_BLOCK io; + FILE_POSITION_INFORMATION info; - if (method > FILE_END) + switch(method) { + case FILE_BEGIN: + pos = distance.QuadPart; + break; + case FILE_CURRENT: + if (NtQueryInformationFile( hFile, &io, &info, sizeof(info), FilePositionInformation )) + goto error; + pos = info.CurrentByteOffset.QuadPart + distance.QuadPart; + break; + case FILE_END: + { + FILE_END_OF_FILE_INFORMATION eof; + if (NtQueryInformationFile( hFile, &io, &eof, sizeof(eof), FileEndOfFileInformation )) + goto error; + pos = eof.EndOfFile.QuadPart + distance.QuadPart; + } + break; + default: SetLastError( ERROR_INVALID_PARAMETER ); - return ret; + return FALSE; } - if (!(status = wine_server_handle_to_fd( hFile, 0, &fd, NULL ))) + if (pos < 0) { - off_t pos, res; - - pos = distance.QuadPart; - 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 = TRUE; - if( newpos ) - newpos->QuadPart = res; - } - wine_server_release_fd( hFile, fd ); + SetLastError( ERROR_NEGATIVE_SEEK ); + return FALSE; } - else SetLastError( RtlNtStatusToDosError(status) ); - return ret; + info.CurrentByteOffset.QuadPart = pos; + if (NtSetInformationFile( hFile, &io, &info, sizeof(info), FilePositionInformation )) + goto error; + if (newpos) newpos->QuadPart = pos; + return TRUE; + +error: + SetLastError( RtlNtStatusToDosError(io.u.Status) ); + return FALSE; } /*********************************************************************** -- 2.11.4.GIT