| 636 | #endif |
| 637 | |
| 638 | static 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 |
no test coverage detected