summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfsdirrwops.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-30 02:44:06 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-30 02:44:06 +0300
commitcdfa9d0a4253c37750cc385147a18624496b6f37 (patch)
tree93d0ded84ec63d4966cdc656cc0a788a486aff5f /src/fs/virtfs/virtfsdirrwops.cpp
parent7fcdef87fb6a0de213a62461d24acb29f7671855 (diff)
downloadmv-cdfa9d0a4253c37750cc385147a18624496b6f37.tar.gz
mv-cdfa9d0a4253c37750cc385147a18624496b6f37.tar.bz2
mv-cdfa9d0a4253c37750cc385147a18624496b6f37.tar.xz
mv-cdfa9d0a4253c37750cc385147a18624496b6f37.zip
Improve VirtfsDir::rwops_read.
Diffstat (limited to 'src/fs/virtfs/virtfsdirrwops.cpp')
-rw-r--r--src/fs/virtfs/virtfsdirrwops.cpp25
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);
}