implemented SetFilePointerEx() and fixed SetFilePointer() to check if the calculated file position is negative

svn path=/trunk/; revision=8710
This commit is contained in:
Thomas Bluemel 2004-03-14 13:11:55 +00:00
parent 3b338cc571
commit 2c9bca4a1a
2 changed files with 86 additions and 28 deletions

View file

@ -1,4 +1,4 @@
/* $Id: file.c,v 1.49 2004/01/23 21:16:03 ekohl Exp $
/* $Id: file.c,v 1.50 2004/03/14 13:11:55 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -203,6 +203,8 @@ SetFilePointer(HANDLE hFile,
DPRINT("SetFilePointer(hFile %x, lDistanceToMove %d, dwMoveMethod %d)\n",
hFile,lDistanceToMove,dwMoveMethod);
/* FIXME - should fail if hFile is a console handle */
Distance.u.LowPart = lDistanceToMove;
if (lpDistanceToMoveHigh)
{
@ -216,18 +218,18 @@ SetFilePointer(HANDLE hFile,
{
Distance.u.HighPart = -1;
}
if (dwMoveMethod == FILE_CURRENT)
{
switch(dwMoveMethod)
{
case FILE_CURRENT:
NtQueryInformationFile(hFile,
&IoStatusBlock,
&FilePosition,
sizeof(FILE_POSITION_INFORMATION),
FilePositionInformation);
FilePosition.CurrentByteOffset.QuadPart += Distance.QuadPart;
}
else if (dwMoveMethod == FILE_END)
{
break;
case FILE_END:
NtQueryInformationFile(hFile,
&IoStatusBlock,
&FileStandart,
@ -235,11 +237,17 @@ SetFilePointer(HANDLE hFile,
FileStandardInformation);
FilePosition.CurrentByteOffset.QuadPart =
FileStandart.EndOfFile.QuadPart + Distance.QuadPart;
}
else if ( dwMoveMethod == FILE_BEGIN )
{
break;
case FILE_BEGIN:
FilePosition.CurrentByteOffset.QuadPart = Distance.QuadPart;
}
break;
}
if(FilePosition.CurrentByteOffset.QuadPart < 0)
{
SetLastError(ERROR_NEGATIVE_SEEK);
return -1;
}
errCode = NtSetInformationFile(hFile,
&IoStatusBlock,
@ -260,6 +268,72 @@ SetFilePointer(HANDLE hFile,
}
/*
* @implemented
*/
BOOL
STDCALL
SetFilePointerEx(HANDLE hFile,
LARGE_INTEGER liDistanceToMove,
PLARGE_INTEGER lpNewFilePointer,
DWORD dwMoveMethod)
{
FILE_POSITION_INFORMATION FilePosition;
FILE_STANDARD_INFORMATION FileStandart;
NTSTATUS errCode;
IO_STATUS_BLOCK IoStatusBlock;
/* FIXME - should fail if hFile is a console handle */
switch(dwMoveMethod)
{
case FILE_CURRENT:
NtQueryInformationFile(hFile,
&IoStatusBlock,
&FilePosition,
sizeof(FILE_POSITION_INFORMATION),
FilePositionInformation);
FilePosition.CurrentByteOffset.QuadPart += liDistanceToMove.QuadPart;
break;
case FILE_END:
NtQueryInformationFile(hFile,
&IoStatusBlock,
&FileStandart,
sizeof(FILE_STANDARD_INFORMATION),
FileStandardInformation);
FilePosition.CurrentByteOffset.QuadPart =
FileStandart.EndOfFile.QuadPart + liDistanceToMove.QuadPart;
break;
case FILE_BEGIN:
FilePosition.CurrentByteOffset.QuadPart = liDistanceToMove.QuadPart;
break;
}
if(FilePosition.CurrentByteOffset.QuadPart < 0)
{
SetLastError(ERROR_NEGATIVE_SEEK);
return FALSE;
}
errCode = NtSetInformationFile(hFile,
&IoStatusBlock,
&FilePosition,
sizeof(FILE_POSITION_INFORMATION),
FilePositionInformation);
if (!NT_SUCCESS(errCode))
{
SetLastErrorByStatus(errCode);
return FALSE;
}
if (lpNewFilePointer)
{
*lpNewFilePointer = FilePosition.CurrentByteOffset;
}
return TRUE;
}
/*
* @implemented
*/

View file

@ -1,4 +1,4 @@
/* $Id: stubs.c,v 1.64 2004/03/14 11:11:17 weiden Exp $
/* $Id: stubs.c,v 1.65 2004/03/14 13:11:55 weiden Exp $
*
* KERNEL32.DLL stubs (unimplemented functions)
* Remove from this file, if you implement them.
@ -1421,22 +1421,6 @@ SetCriticalSectionSpinCount(
return 0;
}
/*
* @unimplemented
*/
BOOL
STDCALL
SetFilePointerEx(
HANDLE hFile,
LARGE_INTEGER liDistanceToMove,
PLARGE_INTEGER lpNewFilePointer,
DWORD dwMoveMethod
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return 0;
}
/*
* @unimplemented
*/