Skip to content

Commit b07f375

Browse files
committed
unistd: add setuid, setgid syscalls
1 parent 7fa7206 commit b07f375

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/unistd.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use self::linux::*;
1313

1414
mod ffi {
1515
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};
16+
pub use libc::{fork, close, read, write, pipe, ftruncate, unlink, setpgid, getegid, geteuid, getgid, getpid, getppid, getuid, setuid, setgid};
1717

1818
#[allow(improper_ctypes)]
1919
extern {
@@ -369,6 +369,20 @@ pub fn getegid() -> gid_t {
369369
unsafe { ffi::getegid() }
370370
}
371371

372+
#[inline]
373+
pub fn setuid(uid: uid_t) -> Result<()> {
374+
let res = unsafe { ffi::setuid(uid) };
375+
376+
Errno::result(res).map(drop)
377+
}
378+
379+
#[inline]
380+
pub fn setgid(gid: gid_t) -> Result<()> {
381+
let res = unsafe { ffi::setgid(gid) };
382+
383+
Errno::result(res).map(drop)
384+
}
385+
372386
#[cfg(any(target_os = "linux", target_os = "android"))]
373387
mod linux {
374388
use sys::syscall::{syscall, SYSPIVOTROOT};

0 commit comments

Comments
 (0)