MCPcopy Create free account
hub / github.com/diasurgical/devilution / SFileSetFilePointer

Function SFileSetFilePointer

3rdParty/StormLib/src/SFileReadFile.cpp:809–907  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

807}
808
809DWORD STORMAPI SFileSetFilePointer(HANDLE hFile, LONG lFilePos, LONG * plFilePosHigh, DWORD dwMoveMethod)
810{
811 TMPQFile * hf = (TMPQFile *)hFile;
812 ULONGLONG OldPosition;
813 ULONGLONG NewPosition;
814 ULONGLONG FileSize;
815 ULONGLONG DeltaPos;
816
817 // If the hFile is not a valid file handle, return an error.
818 if(!IsValidFileHandle(hFile))
819 {
820 SetLastError(ERROR_INVALID_HANDLE);
821 return SFILE_INVALID_POS;
822 }
823
824 // Retrieve the file size for handling the limits
825 if(hf->pStream != NULL)
826 {
827 FileStream_GetSize(hf->pStream, &FileSize);
828 }
829 else
830 {
831 FileSize = SFileGetFileSize(hFile, NULL);
832 }
833
834 // Handle the NULL and non-NULL values of plFilePosHigh
835 // Non-NULL: The DeltaPos is combined from lFilePos and *lpFilePosHigh
836 // NULL: The DeltaPos is sign-extended value of lFilePos
837 DeltaPos = (plFilePosHigh != NULL) ? MAKE_OFFSET64(plFilePosHigh[0], lFilePos) : (ULONGLONG)(LONGLONG)lFilePos;
838
839 // Get the relative point where to move from
840 switch(dwMoveMethod)
841 {
842 case FILE_BEGIN:
843
844 // Move relative to the file begin.
845 OldPosition = 0;
846 break;
847
848 case FILE_CURRENT:
849
850 // Retrieve the current file position
851 if(hf->pStream != NULL)
852 {
853 FileStream_GetPos(hf->pStream, &OldPosition);
854 }
855 else
856 {
857 OldPosition = hf->dwFilePos;
858 }
859 break;
860
861 case FILE_END:
862
863 // Move relative to the end of the file
864 OldPosition = FileSize;
865 break;
866

Callers 3

SBmpLoadImageFunction · 0.85
WReadFileFunction · 0.85
CreatePseudoFileNameFunction · 0.85

Calls 6

IsValidFileHandleFunction · 0.85
SetLastErrorFunction · 0.85
FileStream_GetSizeFunction · 0.85
SFileGetFileSizeFunction · 0.85
FileStream_GetPosFunction · 0.85
FileStream_ReadFunction · 0.85

Tested by

no test coverage detected