@@ -13,7 +13,7 @@ pub use self::linux::*;
13
13
14
14
mod ffi {
15
15
use libc:: { c_char, c_int, size_t} ;
16
- pub use libc:: { fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid, setuid, setgid} ;
16
+ pub use libc:: { fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid, setuid, setgid, chown } ;
17
17
18
18
#[ allow( improper_ctypes) ]
19
19
extern {
@@ -28,7 +28,7 @@ mod ffi {
28
28
29
29
// Execute PATH with arguments ARGV and environment from `environ'.
30
30
// doc: http://man7.org/linux/man-pages/man3/execv.3.html
31
- pub fn execv ( path : * const c_char , argv : * const * const c_char ) -> c_int ;
31
+ pub fn execv ( path : * const c_char , argv : * const * const c_char ) -> c_int ;
32
32
33
33
// execute program
34
34
// doc: http://man7.org/linux/man-pages/man2/execve.2.html
@@ -157,6 +157,16 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
157
157
Errno :: result ( res) . map ( drop)
158
158
}
159
159
160
+ #[ inline]
161
+ pub fn chown < P : ?Sized + NixPath > ( path : & P , owner : Option < uid_t > , group : Option < gid_t > ) -> Result < ( ) > {
162
+ let res = try!( path. with_nix_path ( |cstr| {
163
+ // We use `0 - 1` to get `-1 : {u,g}id_t` which is specified as the no-op value for chown(3).
164
+ unsafe { ffi:: chown ( cstr. as_ptr ( ) , owner. unwrap_or ( 0 - 1 ) , group. unwrap_or ( 0 - 1 ) ) }
165
+ } ) ) ;
166
+
167
+ Errno :: result ( res) . map ( drop)
168
+ }
169
+
160
170
fn to_exec_array ( args : & [ CString ] ) -> Vec < * const c_char > {
161
171
use std:: ptr;
162
172
use libc:: c_char;
0 commit comments