summaryrefslogtreecommitdiff
path: root/src/fs/virtfs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/virtfs')
-rw-r--r--src/fs/virtfs/virtfsdirrwops.cpp30
-rw-r--r--src/fs/virtfs/virtfsdirrwops.h2
2 files changed, 24 insertions, 8 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);
}
diff --git a/src/fs/virtfs/virtfsdirrwops.h b/src/fs/virtfs/virtfsdirrwops.h
index d8f5c7d15..6751694d1 100644
--- a/src/fs/virtfs/virtfsdirrwops.h
+++ b/src/fs/virtfs/virtfsdirrwops.h
@@ -39,7 +39,7 @@ namespace VirtFsDir
RWOPSSIZE rwops_write(SDL_RWops *const rw,
const void *const ptr,
const RWOPSSIZE size,
- const RWOPSSIZE num);
+ const RWOPSSIZE maxnum);
int rwops_close(SDL_RWops *const rw);
#ifdef USE_SDL2
RWOPSINT rwops_size(SDL_RWops *const rw);