From cdfa9d0a4253c37750cc385147a18624496b6f37 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 30 Mar 2017 02:44:06 +0300 Subject: Improve VirtfsDir::rwops_read. --- src/fs/virtfs/virtfsdirrwops.cpp | 25 +++++++++++++++++++------ 1 file 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( 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(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); } -- cgit v1.2.3-70-g09d2