MCPcopy Index your code
hub / github.com/RustPython/RustPython / lseek

Function lseek

crates/vm/src/stdlib/os.rs:1602–1634  ·  view source on GitHub ↗
(
        fd: crt_fd::Borrowed<'_>,
        position: crt_fd::Offset,
        how: i32,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

1600
1601 #[pyfunction]
1602 pub fn lseek(
1603 fd: crt_fd::Borrowed<'_>,
1604 position: crt_fd::Offset,
1605 how: i32,
1606 vm: &VirtualMachine,
1607 ) -> PyResult<crt_fd::Offset> {
1608 #[cfg(not(windows))]
1609 let res = unsafe { suppress_iph!(libc::lseek(fd.as_raw(), position, how)) };
1610 #[cfg(windows)]
1611 let res = unsafe {
1612 use std::os::windows::io::AsRawHandle;
1613 use windows_sys::Win32::Storage::FileSystem;
1614 let handle = crt_fd::as_handle(fd).map_err(|e| e.into_pyexception(vm))?;
1615 let mut distance_to_move: [i32; 2] = core::mem::transmute(position);
1616 let ret = FileSystem::SetFilePointer(
1617 handle.as_raw_handle(),
1618 distance_to_move[0],
1619 &mut distance_to_move[1],
1620 how as _,
1621 );
1622 if ret == FileSystem::INVALID_SET_FILE_POINTER {
1623 -1
1624 } else {
1625 distance_to_move[0] = ret as _;
1626 core::mem::transmute::<[i32; 2], i64>(distance_to_move)
1627 }
1628 };
1629 if res < 0 {
1630 Err(vm.new_last_os_error())
1631 } else {
1632 Ok(res)
1633 }
1634 }
1635
1636 #[derive(FromArgs)]
1637 struct LinkArgs {

Callers 5

initMethod · 0.85
seekableMethod · 0.85
seekMethod · 0.85
tellMethod · 0.85
truncateMethod · 0.85

Calls 4

as_handleFunction · 0.85
new_last_os_errorMethod · 0.80
ErrClass · 0.50
into_pyexceptionMethod · 0.45

Tested by

no test coverage detected