Skip to content

Commit

Permalink
unistd: add chown syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
abbradar committed Feb 19, 2016
1 parent b07f375 commit 466cf7e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -157,6 +157,15 @@ 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| {
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;
Expand Down

0 comments on commit 466cf7e

Please sign in to comment.