summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authorNikolay Amiantov <ab@fmap.me>2016-02-19 17:37:53 +0300
committerNikolay Amiantov <ab@fmap.me>2016-02-19 23:33:58 +0300
commitb07f3752b6f72b57c05b000987b14302eefb195a (patch)
tree2cc8361c31b1b8ddfe861ca204134d831c75e480 /src/unistd.rs
parent7fa7206e9ffe4a74762e4a8c1cdc1b8a480d07bb (diff)
downloadnix-b07f3752b6f72b57c05b000987b14302eefb195a.zip
unistd: add setuid, setgid syscalls
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index a4e66618..1e3bdfb8 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};
+ pub use libc::{fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid, setuid, setgid};
#[allow(improper_ctypes)]
extern {
@@ -369,6 +369,20 @@ pub fn getegid() -> gid_t {
unsafe { ffi::getegid() }
}
+#[inline]
+pub fn setuid(uid: uid_t) -> Result<()> {
+ let res = unsafe { ffi::setuid(uid) };
+
+ Errno::result(res).map(drop)
+}
+
+#[inline]
+pub fn setgid(gid: gid_t) -> Result<()> {
+ let res = unsafe { ffi::setgid(gid) };
+
+ Errno::result(res).map(drop)
+}
+
#[cfg(any(target_os = "linux", target_os = "android"))]
mod linux {
use sys::syscall::{syscall, SYSPIVOTROOT};