302 |
if (ulPos + WordCount * WordSize >= CurrentChunkSize) WordCount = (CurrentChunkSize - ulPos) / WordSize; |
if (ulPos + WordCount * WordSize >= CurrentChunkSize) WordCount = (CurrentChunkSize - ulPos) / WordSize; |
303 |
#if POSIX |
#if POSIX |
304 |
if (lseek(pFile->hFileRead, ulStartPos + ulPos, SEEK_SET) < 0) return 0; |
if (lseek(pFile->hFileRead, ulStartPos + ulPos, SEEK_SET) < 0) return 0; |
305 |
unsigned long readWords = read(pFile->hFileRead, pData, WordCount * WordSize); |
ssize_t readWords = read(pFile->hFileRead, pData, WordCount * WordSize); |
306 |
if (readWords < 1) return 0; |
if (readWords < 1) { |
307 |
|
#if DEBUG |
308 |
|
std::cerr << "POSIX read() failed: " << strerror(errno) << std::endl << std::flush; |
309 |
|
#endif // DEBUG |
310 |
|
return 0; |
311 |
|
} |
312 |
readWords /= WordSize; |
readWords /= WordSize; |
313 |
#elif defined(WIN32) |
#elif defined(WIN32) |
314 |
if (SetFilePointer(pFile->hFileRead, ulStartPos + ulPos, NULL/*32 bit*/, FILE_BEGIN) == INVALID_SET_FILE_POINTER) return 0; |
if (SetFilePointer(pFile->hFileRead, ulStartPos + ulPos, NULL/*32 bit*/, FILE_BEGIN) == INVALID_SET_FILE_POINTER) return 0; |
318 |
readWords /= WordSize; |
readWords /= WordSize; |
319 |
#else // standard C functions |
#else // standard C functions |
320 |
if (fseek(pFile->hFileRead, ulStartPos + ulPos, SEEK_SET)) return 0; |
if (fseek(pFile->hFileRead, ulStartPos + ulPos, SEEK_SET)) return 0; |
321 |
unsigned long readWords = fread(pData, WordSize, WordCount, pFile->hFileRead); |
size_t readWords = fread(pData, WordSize, WordCount, pFile->hFileRead); |
322 |
#endif // POSIX |
#endif // POSIX |
323 |
if (!pFile->bEndianNative && WordSize != 1) { |
if (!pFile->bEndianNative && WordSize != 1) { |
324 |
switch (WordSize) { |
switch (WordSize) { |