summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index 1e3bdfb8..6d793aec 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -13,7 +13,7 @@ pub use self::linux::*;
mod ffi {
use libc::{c_char, c_int, size_t};
- pub use libc::{fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid, setuid, setgid};
+ pub use libc::{fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid, setuid, setgid, chown};
#[allow(improper_ctypes)]
extern {
@@ -28,7 +28,7 @@ mod ffi {
// Execute PATH with arguments ARGV and environment from `environ'.
// doc: http://man7.org/linux/man-pages/man3/execv.3.html
- pub fn execv (path: *const c_char, argv: *const *const c_char) -> c_int;
+ pub fn execv(path: *const c_char, argv: *const *const c_char) -> c_int;
// execute program
// doc: http://man7.org/linux/man-pages/man2/execve.2.html
@@ -157,6 +157,16 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
Errno::result(res).map(drop)
}
+#[inline]
+pub fn chown<P: ?Sized + NixPath>(path: &P, owner: Option<uid_t>, group: Option<gid_t>) -> Result<()> {
+ let res = try!(path.with_nix_path(|cstr| {
+ // We use `0 - 1` to get `-1 : {u,g}id_t` which is specified as the no-op value for chown(3).
+ unsafe { ffi::chown(cstr.as_ptr(), owner.unwrap_or(0 - 1), group.unwrap_or(0 - 1)) }
+ }));
+
+ Errno::result(res).map(drop)
+}
+
fn to_exec_array(args: &[CString]) -> Vec<*const c_char> {
use std::ptr;
use libc::c_char;