@@ -8,7 +8,6 @@ pub use libc::rlim_t;
88cfg_if ! {
99 if #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ] {
1010 use libc:: { __rlimit_resource_t, rlimit, RLIM_INFINITY } ;
11- use crate :: Error ;
1211 } else{
1312 use libc:: { c_int, rlimit, RLIM_INFINITY } ;
1413 }
@@ -117,6 +116,7 @@ libc_enum! {
117116/// [getrlimit(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html#tag_16_215)
118117///
119118/// [`Resource`]: enum.Resource.html
119+
120120pub fn getrlimit ( resource : Resource ) -> Result < ( Option < rlim_t > , Option < rlim_t > ) > {
121121 let mut old_rlim = rlimit {
122122 rlim_cur : 0 ,
@@ -168,6 +168,9 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
168168/// [setrlimit(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html#tag_16_215)
169169///
170170/// [`Resource`]: enum.Resource.html
171+ ///
172+ /// Note: `setrlimit` provides a safe wrapper to libc's `setrlimit`. For the
173+ /// platform that are not compatible, try using `prlimit` to set rlimit.
171174pub fn setrlimit (
172175 resource : Resource ,
173176 soft_limit : Option < rlim_t > ,
@@ -179,17 +182,6 @@ pub fn setrlimit(
179182 } ;
180183 cfg_if ! {
181184 if #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ] {
182- // the below implementation is mimicing the similar implementation in golang
183- // https://go-review.googlesource.com/c/sys/+/230478/2/unix/syscall_linux_arm64.go#176
184- // seems for some of the architectures, we prefer to use prlimit instead of {g,s}etrlimit
185- let res = unsafe { libc:: prlimit( 0 , resource as __rlimit_resource_t, & new_rlim as * const _, std:: ptr:: null_mut( ) ) } ;
186- if res == -1 {
187- match Errno :: last( ) {
188- Errno :: ENOSYS =>{ }
189- e => { return Err ( Error :: Sys ( e) ) ; }
190- }
191- }
192-
193185 let res = unsafe { libc:: setrlimit( resource as __rlimit_resource_t, & new_rlim as * const _) } ;
194186 } else{
195187 let res = unsafe { libc:: setrlimit( resource as c_int, & new_rlim as * const _) } ;
0 commit comments