Skip to content

Commit 8a85fee

Browse files
committed
Fix os.lseek on Windows
1 parent bca6852 commit 8a85fee

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ schannel = "0.1"
107107

108108
[target."cfg(windows)".dependencies.winapi]
109109
version = "0.3"
110-
features = ["winsock2", "handleapi", "ws2def", "std", "winbase", "wincrypt"]
110+
features = ["winsock2", "handleapi", "ws2def", "std", "winbase", "wincrypt", "fileapi"]
111111

112112
[target.'cfg(target_arch = "wasm32")'.dependencies]
113113
wasm-bindgen = "0.2"

vm/src/stdlib/os.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,25 @@ fn os_isatty(fd: i32) -> bool {
13441344

13451345
fn os_lseek(fd: i32, position: Offset, how: i32, vm: &VirtualMachine) -> PyResult<Offset> {
13461346
#[cfg(not(windows))]
1347-
use libc::lseek;
1347+
let res = unsafe { suppress_iph!(libc::lseek(fd, position, how)) };
13481348
#[cfg(windows)]
1349-
use libc::lseek64 as lseek;
1350-
let res = unsafe { suppress_iph!(lseek(fd, position, how)) };
1349+
let res = unsafe {
1350+
use winapi::um::{fileapi, winnt};
1351+
let mut li = winnt::LARGE_INTEGER::default();
1352+
*li.QuadPart_mut() = position;
1353+
let ret = fileapi::SetFilePointer(
1354+
fd as RawHandle,
1355+
li.u().LowPart as _,
1356+
&mut li.u_mut().HighPart,
1357+
how as _,
1358+
);
1359+
if ret == fileapi::INVALID_SET_FILE_POINTER {
1360+
-1
1361+
} else {
1362+
li.u_mut().LowPart = ret;
1363+
*li.QuadPart()
1364+
}
1365+
};
13511366
if res < 0 {
13521367
Err(errno_err(vm))
13531368
} else {

0 commit comments

Comments
 (0)