From f8120f4c08f8b99d781c0a310ce1c0e383b256ae Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 30 Mar 2017 03:06:37 +0300 Subject: Improve VirtFsDir::rwops_size --- src/fs/virtfs/virtfsdirrwops.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/fs/virtfs/virtfsdirrwops.cpp') diff --git a/src/fs/virtfs/virtfsdirrwops.cpp b/src/fs/virtfs/virtfsdirrwops.cpp index 2170dd05f..f5fc3acd1 100644 --- a/src/fs/virtfs/virtfsdirrwops.cpp +++ b/src/fs/virtfs/virtfsdirrwops.cpp @@ -230,7 +230,22 @@ namespace VirtFsDir { VirtFile *const handle = static_cast( rw->hidden.unknown.data1); - return VirtFs::fileLength(handle); + FILEHTYPE fd = handle->mFd; +#ifdef USE_FILE_FOPEN + const long pos = ftell(fd); + fseek(fd, 0, SEEK_END); + const long sz = ftell(fd); + fseek(fd, pos, SEEK_SET); + return sz; +#else // USE_FILE_FOPEN + struct stat statbuf; + if (fstat(fd, &statbuf) == -1) + { + reportAlways("VirtFsDir::fileLength error."); + return -1; + } + return static_cast(statbuf.st_size); +#endif // USE_FILE_FOPEN } #endif // USE_SDL2 -- cgit v1.2.3-70-g09d2