@@ -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,15 @@ 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
+ unsafe { ffi:: chown ( cstr. as_ptr ( ) , owner. unwrap_or ( 0 - 1 ) , group. unwrap_or ( 0 - 1 ) ) }
164
+ } ) ) ;
165
+
166
+ Errno :: result ( res) . map ( drop)
167
+ }
168
+
160
169
fn to_exec_array ( args : & [ CString ] ) -> Vec < * const c_char > {
161
170
use std:: ptr;
162
171
use libc:: c_char;
0 commit comments