@@ -3228,16 +3228,23 @@ mod setres {
32283228 /// * returns: Ok or libc error code.
32293229 ///
32303230 /// Err is returned if the user doesn't have permission to set this UID.
3231+ ///
3232+ /// If one of the arguments equals None, the corresponding value is not changed.
32313233 #[ inline]
3232- pub fn setresuid( ruid: Uid , euid: Uid , suid: Uid ) -> Result <( ) > {
3234+ pub fn setresuid( ruid: Option <Uid >, euid: Option <Uid >, suid: Option <Uid >) -> Result <( ) > {
3235+ let ruid = ruid. map( Into :: into) . unwrap_or( ( 0 as libc:: uid_t) . wrapping_sub( 1 ) ) ;
3236+ let euid = euid. map( Into :: into) . unwrap_or( ( 0 as libc:: uid_t) . wrapping_sub( 1 ) ) ;
3237+ let suid = suid. map( Into :: into) . unwrap_or( ( 0 as libc:: uid_t) . wrapping_sub( 1 ) ) ;
32333238 let res =
3234- unsafe { libc:: setresuid( ruid. into ( ) , euid. into ( ) , suid. into ( ) ) } ;
3239+ unsafe { libc:: setresuid( ruid, euid, suid) } ;
32353240
32363241 Errno :: result( res) . map( drop)
32373242 }
32383243
32393244 /// Sets the real, effective, and saved gid.
3240- /// ([see setresuid(2)](https://man7.org/linux/man-pages/man2/setresuid.2.html))
3245+ ///
3246+ /// If one of the arguments equals None, the corresponding value is not changed.
3247+ /// ([see setresgid(2)](https://man7.org/linux/man-pages/man2/setresgid.2.html))
32413248 ///
32423249 /// * `rgid`: real group id
32433250 /// * `egid`: effective group id
@@ -3246,9 +3253,12 @@ mod setres {
32463253 ///
32473254 /// Err is returned if the user doesn't have permission to set this GID.
32483255 #[ inline]
3249- pub fn setresgid( rgid: Gid , egid: Gid , sgid: Gid ) -> Result <( ) > {
3256+ pub fn setresgid( rgid: Option <Gid >, egid: Option <Gid >, sgid: Option <Gid >) -> Result <( ) > {
3257+ let rgid = rgid. map( Into :: into) . unwrap_or( ( 0 as libc:: gid_t) . wrapping_sub( 1 ) ) ;
3258+ let egid = egid. map( Into :: into) . unwrap_or( ( 0 as libc:: gid_t) . wrapping_sub( 1 ) ) ;
3259+ let sgid = sgid. map( Into :: into) . unwrap_or( ( 0 as libc:: gid_t) . wrapping_sub( 1 ) ) ;
32503260 let res =
3251- unsafe { libc:: setresgid( rgid. into ( ) , egid. into ( ) , sgid. into ( ) ) } ;
3261+ unsafe { libc:: setresgid( rgid, egid, sgid) } ;
32523262
32533263 Errno :: result( res) . map( drop)
32543264 }
0 commit comments