use crate::errno::Error;
use crate::errno::Result;
use crate::util::zeroed;
#[cfg(not(target_os = "linux"))]
#[allow(non_camel_case_types)]
type r_int = i32;
#[cfg(target_os = "linux")]
#[allow(non_camel_case_types)]
type r_int = u32;
#[cfg(target_pointer_width = "32")]
#[allow(non_camel_case_types)]
type rlim = u32;
#[cfg(target_pointer_width = "64")]
#[allow(non_camel_case_types)]
type rlim = u64;
pub fn getrlimit(resource: r_int) -> Result<(rlim, rlim)> {
let mut rlimit: libc::rlimit = zeroed();
unsafe {
if libc::getrlimit(resource, &mut rlimit) == 0 {
Ok((rlimit.rlim_cur, rlimit.rlim_max))
} else {
Err(Error::errno())
}
}
}
pub fn setrlimit(resource: r_int, soft: rlim, hard: rlim) -> Result<()> {
let rlimit = libc::rlimit { rlim_cur: soft, rlim_max: hard };
unsafe {
if libc::setrlimit(resource, &rlimit) == 0 {
Ok(())
} else {
return Err(Error::errno());
}
}
}