File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -114,8 +114,12 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
114
114
#[ inline]
115
115
pub fn chown < P : ?Sized + NixPath > ( path : & P , owner : Option < uid_t > , group : Option < gid_t > ) -> Result < ( ) > {
116
116
let res = try!( path. with_nix_path ( |cstr| {
117
- // We use `0 - 1` to get `-1 : {u,g}id_t` which is specified as the no-op value for chown(3).
118
- unsafe { libc:: chown ( cstr. as_ptr ( ) , owner. unwrap_or ( 0 - 1 ) , group. unwrap_or ( 0 - 1 ) ) }
117
+ // According to the POSIX specification, -1 is used to indicate that
118
+ // owner and group, respectively, are not to be changed. Since uid_t and
119
+ // gid_t are unsigned types, we use wrapping_sub to get '-1'.
120
+ unsafe { libc:: chown ( cstr. as_ptr ( ) ,
121
+ owner. unwrap_or ( ( 0 as uid_t ) . wrapping_sub ( 1 ) ) ,
122
+ group. unwrap_or ( ( 0 as gid_t ) . wrapping_sub ( 1 ) ) ) }
119
123
} ) ) ;
120
124
121
125
Errno :: result ( res) . map ( drop)
You can’t perform that action at this time.
0 commit comments