summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
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};