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

Function ReadMpqFileLocalFile

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

Source from the content-addressed store, hash-verified

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