diff --git a/cli/priority.rs b/cli/priority.rs index 128243ff0857d2..f003f4c4ff23a4 100644 --- a/cli/priority.rs +++ b/cli/priority.rs @@ -23,6 +23,13 @@ use winapi::um::winbase::{ }; #[cfg(windows)] use winapi::um::winnt::PROCESS_QUERY_LIMITED_INFORMATION; +#[cfg(target_os = "macos")] +#[allow(non_camel_case_types)] +type priority_t = i32; +#[cfg(target_os = "linux")] +#[allow(non_camel_case_types)] +type priority_t = u32; + pub const PRIORITY_LOW: i32 = 19; pub const PRIORITY_BELOW_NORMAL: i32 = 10; @@ -35,7 +42,7 @@ pub const PRIORITY_HIGHEST: i32 = -20; pub fn get_priority(pid: u32) -> Result { unsafe { set_errno(Errno(0)); - match (libc::getpriority(PRIO_PROCESS as u32, pid as id_t), errno()) { + match (libc::getpriority(PRIO_PROCESS as priority_t, pid as id_t), errno()) { (-1, Errno(0)) => Ok(PRIORITY_HIGH), (-1, _) => Err(OpError::from(std::io::Error::last_os_error())), (priority, _) => Ok(priority), @@ -46,7 +53,7 @@ pub fn get_priority(pid: u32) -> Result { #[cfg(unix)] pub fn set_priority(pid: u32,priority: i32) -> Result<(), OpError> { unsafe { - match libc::setpriority(PRIO_PROCESS as u32, pid as id_t, priority) { + match libc::setpriority(PRIO_PROCESS as priority_t, pid as id_t, priority) { -1 => Err(OpError::from(std::io::Error::last_os_error())), _ => Ok(()), }