Merge pull request #4076 from akallabeth/SetFilePointer_fix
Set file pointer fix
This commit is contained in:
commit
80ed23779f
@ -385,16 +385,13 @@ BOOL drive_file_free(DRIVE_FILE* file)
|
||||
|
||||
BOOL drive_file_seek(DRIVE_FILE* file, UINT64 Offset)
|
||||
{
|
||||
LONG lDistHigh;
|
||||
DWORD dwPtrLow;
|
||||
LARGE_INTEGER loffset;
|
||||
|
||||
if (!file)
|
||||
return FALSE;
|
||||
|
||||
lDistHigh = Offset >> 32;
|
||||
DEBUG_WSTR("Seek %s", file->fullpath);
|
||||
dwPtrLow = SetFilePointer(file->file_handle, Offset & 0xFFFFFFFF, &lDistHigh, FILE_BEGIN);
|
||||
return dwPtrLow != INVALID_SET_FILE_POINTER;
|
||||
loffset.QuadPart = Offset;
|
||||
return SetFilePointerEx(file->file_handle, loffset, NULL, FILE_BEGIN);
|
||||
}
|
||||
|
||||
BOOL drive_file_read(DRIVE_FILE* file, BYTE* buffer, UINT32* Length)
|
||||
@ -623,8 +620,7 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN
|
||||
|
||||
liSize.QuadPart = size & 0xFFFFFFFF;
|
||||
|
||||
if (SetFilePointer(file->file_handle, liSize.LowPart, &liSize.HighPart,
|
||||
FILE_BEGIN) == INVALID_SET_FILE_POINTER)
|
||||
if (!SetFilePointerEx(file->file_handle, liSize, NULL, FILE_BEGIN))
|
||||
{
|
||||
WLog_ERR(TAG, "Unable to truncate %s to %d (%"PRId32")", file->fullpath, size, GetLastError());
|
||||
return FALSE;
|
||||
|
@ -122,12 +122,19 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove,
|
||||
PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
|
||||
{
|
||||
WINPR_FILE* pFile = (WINPR_FILE*) hFile;
|
||||
long offset = lDistanceToMove;
|
||||
INT64 offset;
|
||||
int whence;
|
||||
|
||||
if (!hFile)
|
||||
return INVALID_SET_FILE_POINTER;
|
||||
|
||||
if (lpDistanceToMoveHigh)
|
||||
{
|
||||
offset = (*lpDistanceToMoveHigh << 32) | (UINT32)lDistanceToMove;
|
||||
}
|
||||
else
|
||||
offset = lDistanceToMove;
|
||||
|
||||
switch(dwMoveMethod)
|
||||
{
|
||||
case FILE_BEGIN:
|
||||
@ -153,6 +160,42 @@ static DWORD FileSetFilePointer(HANDLE hFile, LONG lDistanceToMove,
|
||||
return ftell(pFile->fp);
|
||||
}
|
||||
|
||||
static BOOL FileSetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
|
||||
{
|
||||
WINPR_FILE* pFile = (WINPR_FILE*) hFile;
|
||||
int whence;
|
||||
|
||||
if (!hFile)
|
||||
return FALSE;
|
||||
|
||||
switch(dwMoveMethod)
|
||||
{
|
||||
case FILE_BEGIN:
|
||||
whence = SEEK_SET;
|
||||
break;
|
||||
case FILE_END:
|
||||
whence = SEEK_END;
|
||||
break;
|
||||
case FILE_CURRENT:
|
||||
whence = SEEK_CUR;
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (fseek(pFile->fp, liDistanceToMove.QuadPart, whence))
|
||||
{
|
||||
WLog_ERR(TAG, "fseek(%s) failed with %s [0x%08X]", pFile->lpFileName,
|
||||
strerror(errno), errno);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (lpNewFilePointer)
|
||||
lpNewFilePointer->QuadPart = ftell(pFile->fp);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
|
||||
{
|
||||
@ -550,7 +593,7 @@ static HANDLE_OPS fileOps = {
|
||||
NULL, /* FlushFileBuffers */
|
||||
FileSetEndOfFile,
|
||||
FileSetFilePointer,
|
||||
NULL, /* SetFilePointerEx */
|
||||
FileSetFilePointerEx,
|
||||
NULL, /* FileLockFile */
|
||||
FileLockFileEx,
|
||||
FileUnlockFile,
|
||||
|
Loading…
Reference in New Issue
Block a user