MCPcopy Create free account
hub / github.com/Kenix3/libultraship / ReadMpqFileLocalFile

Function ReadMpqFileLocalFile

extern/StormLib/src/SFileReadFile.cpp:643–673  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

641}
642
643static DWORD ReadMpqFileLocalFile(TMPQFile * hf, void * pvBuffer, DWORD dwFilePos, DWORD dwToRead, LPDWORD pdwBytesRead)
644{
645 ULONGLONG FilePosition1 = dwFilePos;
646 ULONGLONG FilePosition2;
647 DWORD dwBytesRead = 0;
648 DWORD dwErrCode = ERROR_SUCCESS;
649
650 assert(hf->pStream != NULL);
651
652 // Because stream I/O functions are designed to read
653 // "all or nothing", we compare file position before and after,
654 // and if they differ, we assume that number of bytes read
655 // is the difference between them
656
657 if(!FileStream_Read(hf->pStream, &FilePosition1, pvBuffer, dwToRead))
658 {
659 // If not all bytes have been read, then return the number of bytes read
660 if((dwErrCode = GetLastError()) == ERROR_HANDLE_EOF)
661 {
662 FileStream_GetPos(hf->pStream, &FilePosition2);
663 dwBytesRead = (DWORD)(FilePosition2 - FilePosition1);
664 }
665 }
666 else
667 {
668 dwBytesRead = dwToRead;
669 }
670
671 *pdwBytesRead = dwBytesRead;
672 return dwErrCode;
673}
674
675//-----------------------------------------------------------------------------
676// SFileReadFile

Callers 1

SFileReadFileFunction · 0.85

Calls 3

FileStream_ReadFunction · 0.85
GetLastErrorFunction · 0.85
FileStream_GetPosFunction · 0.85

Tested by

no test coverage detected