diff options
author | Andrei Karas <akaras@inbox.ru> | 2017-03-30 02:25:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2017-03-30 02:25:51 +0300 |
commit | 7fcdef87fb6a0de213a62461d24acb29f7671855 (patch) | |
tree | a447b69140c5a8711f9795bc0f61855cd9108072 /src/fs/virtfs/virtfsdirrwops.cpp | |
parent | 55c45b7035af9e25fb1fde562c9370a70bfe9767 (diff) | |
download | plus-7fcdef87fb6a0de213a62461d24acb29f7671855.tar.gz plus-7fcdef87fb6a0de213a62461d24acb29f7671855.tar.bz2 plus-7fcdef87fb6a0de213a62461d24acb29f7671855.tar.xz plus-7fcdef87fb6a0de213a62461d24acb29f7671855.zip |
Improve VirtFsDir::rwops_seek.
Diffstat (limited to 'src/fs/virtfs/virtfsdirrwops.cpp')
-rw-r--r-- | src/fs/virtfs/virtfsdirrwops.cpp | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/fs/virtfs/virtfsdirrwops.cpp b/src/fs/virtfs/virtfsdirrwops.cpp index 428e416b3..a43a8af8a 100644 --- a/src/fs/virtfs/virtfsdirrwops.cpp +++ b/src/fs/virtfs/virtfsdirrwops.cpp @@ -39,6 +39,7 @@ namespace VirtFsDir return -1; VirtFile *const handle = static_cast<VirtFile *const>( rw->hidden.unknown.data1); + FILEHTYPE fd = handle->mFd; RWOPSINT pos = 0; if (whence == SEEK_SET) @@ -47,7 +48,12 @@ namespace VirtFsDir } else if (whence == SEEK_CUR) { - const int64_t current = VirtFs::tell(handle); +#ifdef USE_FILE_FOPEN + const int64_t current = ftell(fd); +#else // USE_FILE_FOPEN + const int64_t current = lseek(fd, 0, SEEK_CUR); +#endif // USE_FILE_FOPEN + if (current == -1) { logger->assertLog( @@ -70,9 +76,30 @@ namespace VirtFsDir } else if (whence == SEEK_END) { - const int64_t len = VirtFs::fileLength(handle); + int64_t len = 0; +#ifdef USE_FILE_FOPEN + const long curpos = ftell(fd); + fseek(fd, 0, SEEK_END); + len = ftell(fd); +// fseek(fd, curpos, SEEK_SET); +#else // USE_FILE_FOPEN + struct stat statbuf; + if (fstat(fd, &statbuf) == -1) + { + reportAlways("VirtFsDir::fileLength error."); + len = -1; + } + else + { + len = static_cast<int64_t>(statbuf.st_size); + } +#endif // USE_FILE_FOPEN + if (len == -1) { +#ifdef USE_FILE_FOPEN + fseek(fd, curpos, SEEK_SET); +#endif // USE_FILE_FOPEN logger->assertLog( "VirtFs::rwops_seek:Can't find end of file."); return -1; @@ -81,6 +108,9 @@ namespace VirtFsDir pos = static_cast<RWOPSINT>(len); if (static_cast<int64_t>(pos) != len) { +#ifdef USE_FILE_FOPEN + fseek(fd, curpos, SEEK_SET); +#endif // USE_FILE_FOPEN logger->assertLog("VirtFs::rwops_seek: " "Can't fit end-of-file position in an int!"); return -1; @@ -102,7 +132,8 @@ namespace VirtFsDir return -1; } - if (!VirtFs::seek(handle, static_cast<uint64_t>(pos))) + const int64_t res = FILESEEK(fd, pos, SEEK_SET); + if (res == -1) { logger->assertLog("VirtFs::rwops_seek: seek error."); return -1; |