mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
os: implement waitstatus_to_exitcode
This commit is contained in:
@@ -1668,6 +1668,31 @@ pub(super) mod _os {
|
||||
Ok((loadavg[0], loadavg[1], loadavg[2]))
|
||||
}
|
||||
|
||||
#[cfg(any(unix, windows))]
|
||||
#[pyfunction]
|
||||
fn waitstatus_to_exitcode(status: i32, vm: &VirtualMachine) -> PyResult<i32> {
|
||||
let status = u32::try_from(status)
|
||||
.map_err(|_| vm.new_value_error(format!("invalid WEXITSTATUS: {}", status)))?;
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(not(windows))] {
|
||||
let status = status as libc::c_int;
|
||||
if libc::WIFEXITED(status) {
|
||||
return Ok(libc::WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
if libc::WIFSIGNALED(status) {
|
||||
return Ok(-libc::WTERMSIG(status));
|
||||
}
|
||||
|
||||
Err(vm.new_value_error(format!("Invalid wait status: {}", status)))
|
||||
} else {
|
||||
i32::try_from(status.rotate_right(8))
|
||||
.map_err(|_| vm.new_value_error(format!("invalid wait status: {}", status)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pyattr]
|
||||
#[pyclass(module = "os", name = "terminal_size")]
|
||||
#[derive(PyStructSequence)]
|
||||
|
||||
Reference in New Issue
Block a user