summaryrefslogtreecommitdiff
path: root/src/fs/virtfs/virtfsdirrwops.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-03-30 02:54:22 +0300
committerAndrei Karas <akaras@inbox.ru>2017-03-30 02:54:22 +0300
commit399311ae5dc729ff0c0aea08510ed7b2662ca3e2 (patch)
tree915a9541cec1d5dd829cfc916e199ff002e76a63 /src/fs/virtfs/virtfsdirrwops.cpp
parentcdfa9d0a4253c37750cc385147a18624496b6f37 (diff)
downloadmv-399311ae5dc729ff0c0aea08510ed7b2662ca3e2.tar.gz
mv-399311ae5dc729ff0c0aea08510ed7b2662ca3e2.tar.bz2
mv-399311ae5dc729ff0c0aea08510ed7b2662ca3e2.tar.xz
mv-399311ae5dc729ff0c0aea08510ed7b2662ca3e2.zip
Improve VirtfsDir::rwops_write.
Diffstat (limited to 'src/fs/virtfs/virtfsdirrwops.cpp')
-rw-r--r--src/fs/virtfs/virtfsdirrwops.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/fs/virtfs/virtfsdirrwops.cpp b/src/fs/virtfs/virtfsdirrwops.cpp
index 6b8be6e30..bd8e2f594 100644
--- a/src/fs/virtfs/virtfsdirrwops.cpp
+++ b/src/fs/virtfs/virtfsdirrwops.cpp
@@ -181,20 +181,36 @@ namespace VirtFsDir
RWOPSSIZE rwops_write(SDL_RWops *const rw,
const void *const ptr,
const RWOPSSIZE size,
- const RWOPSSIZE num)
+ const RWOPSSIZE maxnum)
{
if (!rw)
return 0;
VirtFile *const handle = static_cast<VirtFile *const>(
rw->hidden.unknown.data1);
- const int64_t rc = VirtFs::write(handle, ptr,
- CAST_U32(size),
- CAST_U32(num));
- if (rc != static_cast<int64_t>(num))
+ FILEHTYPE fd = handle->mFd;
+
+#ifdef USE_FILE_FOPEN
+ const int64_t rc = fwrite(ptr, size, maxnum, fd);
+#else // USE_FILE_FOPEN
+ int max = size * maxnum;
+ int cnt = ::write(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))
{
- logger->assertLog("VirtFs::rwops_seek: write error.");
+#ifndef USE_FILE_FOPEN
+ const int64_t pos = lseek(fd, 0, SEEK_CUR);
+ struct stat statbuf;
+ if (fstat(fd, &statbuf) == -1)
+ {
+ reportAlways("VirtFsDir::fileLength error.");
+ return CAST_S32(rc);
+ }
+#endif // USE_FILE_FOPEN
}
-
return CAST_S32(rc);
}