@@ -8,7 +8,6 @@ pub use libc::rlim_t;
8
8
cfg_if ! {
9
9
if #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ] {
10
10
use libc:: { __rlimit_resource_t, rlimit, RLIM_INFINITY } ;
11
- use crate :: Error ;
12
11
} else{
13
12
use libc:: { c_int, rlimit, RLIM_INFINITY } ;
14
13
}
@@ -117,6 +116,7 @@ libc_enum! {
117
116
/// [getrlimit(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html#tag_16_215)
118
117
///
119
118
/// [`Resource`]: enum.Resource.html
119
+
120
120
pub fn getrlimit ( resource : Resource ) -> Result < ( Option < rlim_t > , Option < rlim_t > ) > {
121
121
let mut old_rlim = rlimit {
122
122
rlim_cur : 0 ,
@@ -168,6 +168,9 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
168
168
/// [setrlimit(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/getrlimit.html#tag_16_215)
169
169
///
170
170
/// [`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.
171
174
pub fn setrlimit (
172
175
resource : Resource ,
173
176
soft_limit : Option < rlim_t > ,
@@ -179,17 +182,6 @@ pub fn setrlimit(
179
182
} ;
180
183
cfg_if ! {
181
184
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
-
193
185
let res = unsafe { libc:: setrlimit( resource as __rlimit_resource_t, & new_rlim as * const _) } ;
194
186
} else{
195
187
let res = unsafe { libc:: setrlimit( resource as c_int, & new_rlim as * const _) } ;
0 commit comments