@@ -13,7 +13,7 @@ pub use self::linux::*;
1313
1414mod ffi {
1515 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 } ;
1717
1818 #[ allow( improper_ctypes) ]
1919 extern {
@@ -28,7 +28,7 @@ mod ffi {
2828
2929 // Execute PATH with arguments ARGV and environment from `environ'.
3030 // 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 ;
3232
3333 // execute program
3434 // doc: http://man7.org/linux/man-pages/man2/execve.2.html
@@ -157,6 +157,16 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
157157 Errno :: result ( res) . map ( drop)
158158}
159159
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+
160170fn to_exec_array ( args : & [ CString ] ) -> Vec < * const c_char > {
161171 use std:: ptr;
162172 use libc:: c_char;
0 commit comments