windows: fix pread/pwrite
authorVincent Fu <vincent.fu@samsung.com>
Thu, 8 May 2025 17:02:57 +0000 (10:02 -0700)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 8 May 2025 18:03:21 +0000 (14:03 -0400)
The pread and pwrite functions for Windows posix emulation never actually seek
to the requested offset. Fix this so that the psync ioengine works correctly on
Windows.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
os/windows/posix.c

index e3abf383e929333056c1f15a2cdbad3234f44d68..3e48c3ffeae4b98610c4a6fa25525d4c90586896 100644 (file)
@@ -830,18 +830,24 @@ ssize_t pwrite(int fildes, const void *buf, size_t nbyte,
                off_t offset)
 {
        int64_t pos = _telli64(fildes);
-       ssize_t len = _write(fildes, buf, nbyte);
+       ssize_t len;
 
+       _lseeki64(fildes, offset, SEEK_SET);
+       len = _write(fildes, buf, nbyte);
        _lseeki64(fildes, pos, SEEK_SET);
+
        return len;
 }
 
 ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset)
 {
        int64_t pos = _telli64(fildes);
-       ssize_t len = read(fildes, buf, nbyte);
+       ssize_t len;
 
+       _lseeki64(fildes, offset, SEEK_SET);
+       len = read(fildes, buf, nbyte);
        _lseeki64(fildes, pos, SEEK_SET);
+
        return len;
 }