From 91d03c26c95a0982d4de41b039e1cdf8c55d90bc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 30 Mar 2017 04:06:58 +0300 Subject: Improve VirtFsZip::rwops_seek. --- src/fs/virtfs/virtfsziprwops.cpp | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/fs/virtfs/virtfsziprwops.cpp b/src/fs/virtfs/virtfsziprwops.cpp index 094d0c4b0..71e9ad397 100644 --- a/src/fs/virtfs/virtfsziprwops.cpp +++ b/src/fs/virtfs/virtfsziprwops.cpp @@ -39,6 +39,10 @@ namespace VirtFsZip return -1; VirtFile *const handle = static_cast( rw->hidden.unknown.data1); +// const uint8_t *mBuf = handle->mBuf; + size_t mPos = handle->mPos; + size_t mSize = handle->mSize; + RWOPSINT pos = 0; if (whence == SEEK_SET) @@ -47,7 +51,7 @@ namespace VirtFsZip } else if (whence == SEEK_CUR) { - const int64_t current = VirtFs::tell(handle); + const int64_t current = mPos; if (current == -1) { logger->assertLog( @@ -70,23 +74,7 @@ namespace VirtFsZip } else if (whence == SEEK_END) { - const int64_t len = VirtFs::fileLength(handle); - if (len == -1) - { - logger->assertLog( - "VirtFs::rwops_seek:Can't find end of file."); - return -1; - } - - pos = static_cast(len); - if (static_cast(pos) != len) - { - logger->assertLog("VirtFs::rwops_seek: " - "Can't fit end-of-file position in an int!"); - return -1; - } - - pos += offset; + pos = mSize + offset; } else { @@ -102,7 +90,9 @@ namespace VirtFsZip return -1; } - if (!VirtFs::seek(handle, static_cast(pos))) + handle->mPos = pos; + + if (pos > static_cast(mSize)) { logger->assertLog("VirtFs::rwops_seek: seek error."); return -1; -- cgit v1.2.3-70-g09d2