Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarFile_windows.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-09-12 23:06:13 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-09-12 23:06:13 +1000
commite8d59f9c2b51859f214a84a47583e0fae5aab5b8 (patch)
tree18d543bd6a0e87cb54b1e9cb881358a65f4170c3 /source/core/StarFile_windows.cpp
parent7852ad9cf2efdf359132c986f46b0e34acbd28ba (diff)
fix windows pread and pwrite bug
reading without a byte offset specified can affect absolute reads afterward, this is a workaround (thanks windows...)
Diffstat (limited to 'source/core/StarFile_windows.cpp')
-rw-r--r--source/core/StarFile_windows.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/source/core/StarFile_windows.cpp b/source/core/StarFile_windows.cpp
index 0b5c286..d9719b1 100644
--- a/source/core/StarFile_windows.cpp
+++ b/source/core/StarFile_windows.cpp
@@ -377,7 +377,12 @@ size_t File::pread(void* f, char* data, size_t len, StreamOffset position) {
HANDLE file = (HANDLE)f;
DWORD numRead = 0;
OVERLAPPED overlapped = makeOverlapped(position);
+
+ StreamOffset pos = ftell(f);
+ if (pos != 0) fseek(f, 0, IOSeek::Absolute);
int ret = ReadFile(file, data, len, &numRead, &overlapped);
+ if (pos != 0) fseek(f, pos, IOSeek::Absolute);
+
if (ret == 0) {
auto err = GetLastError();
if (err != ERROR_IO_PENDING)
@@ -391,7 +396,12 @@ size_t File::pwrite(void* f, char const* data, size_t len, StreamOffset position
HANDLE file = (HANDLE)f;
DWORD numWritten = 0;
OVERLAPPED overlapped = makeOverlapped(position);
+
+ StreamOffset pos = ftell(f);
+ if (pos != 0) fseek(f, 0, IOSeek::Absolute);
int ret = WriteFile(file, data, len, &numWritten, &overlapped);
+ if (pos != 0) fseek(f, pos, IOSeek::Absolute);
+
if (ret == 0) {
auto err = GetLastError();
if (err != ERROR_IO_PENDING)