diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-30 02:44:06 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-30 02:44:06 +0300 |
commit | cdfa9d0a4253c37750cc385147a18624496b6f37 (patch) | |
tree | 93d0ded84ec63d4966cdc656cc0a788a486aff5f /src/fs/virtfs/virtfsdirrwops.cpp | |
parent | 7fcdef87fb6a0de213a62461d24acb29f7671855 (diff) | |
download | manaverse-cdfa9d0a4253c37750cc385147a18624496b6f37.tar.gz manaverse-cdfa9d0a4253c37750cc385147a18624496b6f37.tar.bz2 manaverse-cdfa9d0a4253c37750cc385147a18624496b6f37.tar.xz manaverse-cdfa9d0a4253c37750cc385147a18624496b6f37.zip |
Improve VirtfsDir::rwops_read.
Diffstat (limited to 'src/fs/virtfs/virtfsdirrwops.cpp')
-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); } |