diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/virtfs/virtfsdirrwops.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/fs/virtfs/virtfsdirrwops.cpp b/src/fs/virtfs/virtfsdirrwops.cpp index a43a8af8a..6b8be6e30 100644 --- a/src/fs/virtfs/virtfsdirrwops.cpp +++ b/src/fs/virtfs/virtfsdirrwops.cpp @@ -151,17 +151,30 @@ namespace VirtFsDir return 0; VirtFile *const handle = static_cast<VirtFile *const>( rw->hidden.unknown.data1); - const int64_t rc = VirtFs::read(handle, ptr, - CAST_U32(size), - CAST_U32(maxnum)); + FILEHTYPE fd = handle->mFd; + +#ifdef USE_FILE_FOPEN + const int64_t rc = fread(ptr, size, maxnum, fd); +#else // USE_FILE_FOPEN + int max = size * maxnum; + int cnt = ::read(fd, ptr, max); + if (cnt <= 0) + return cnt; + const int64_t rc = cnt / size; +#endif // USE_FILE_FOPEN + if (rc != static_cast<int64_t>(maxnum)) { - if (!VirtFs::eof(handle)) /* not EOF? Must be an error. */ +#ifndef USE_FILE_FOPEN + const int64_t pos = lseek(fd, 0, SEEK_CUR); + struct stat statbuf; + if (fstat(fd, &statbuf) == -1) { - logger->assertLog("VirtFs::rwops_seek: read error."); + reportAlways("VirtFsDir::fileLength error."); + return CAST_S32(rc); } +#endif // USE_FILE_FOPEN } - return CAST_S32(rc); } |