Skip to content

Commit 4614cba

Browse files
committed
unistd: Add setgroups
1 parent 4e9dd25 commit 4614cba

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/unistd.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,26 @@ pub fn setgid(gid: Gid) -> Result<()> {
941941
Errno::result(res).map(drop)
942942
}
943943

944+
#[inline]
945+
pub fn setgroups(groups: &[Gid]) -> Result<()> {
946+
cfg_if! {
947+
if #[cfg(any(target_os = "macos",
948+
target_os = "ios",
949+
target_os = "freebsd",
950+
target_os = "dragonfly",
951+
target_os = "openbsd",
952+
target_os = "netbsd"))] {
953+
type setgroups_ngroups_t = c_int;
954+
} else {
955+
type setgroups_ngroups_t = size_t;
956+
}
957+
}
958+
let gids: Vec<gid_t> = groups.iter().cloned().map(Into::into).collect();
959+
let res = unsafe { libc::setgroups(groups.len() as setgroups_ngroups_t, gids.as_ptr()) };
960+
961+
Errno::result(res).map(drop)
962+
}
963+
944964
#[inline]
945965
pub fn pause() -> Result<()> {
946966
let res = unsafe { libc::pause() };
@@ -1248,7 +1268,7 @@ pub enum SysconfVar {
12481268
OPEN_MAX = libc::_SC_OPEN_MAX,
12491269
#[cfg(any(target_os="dragonfly", target_os="freebsd", target_os = "ios",
12501270
target_os="linux", target_os = "macos", target_os="openbsd"))]
1251-
/// The implementation supports the Advisory Information option.
1271+
/// The implementation supports the Advisory Information option.
12521272
_POSIX_ADVISORY_INFO = libc::_SC_ADVISORY_INFO,
12531273
#[cfg(any(target_os="dragonfly", target_os="freebsd", target_os = "ios",
12541274
target_os="linux", target_os = "macos", target_os="netbsd",
@@ -1267,7 +1287,7 @@ pub enum SysconfVar {
12671287
target_os="openbsd"))]
12681288
/// The implementation supports the Process CPU-Time Clocks option.
12691289
_POSIX_CPUTIME = libc::_SC_CPUTIME,
1270-
/// The implementation supports the File Synchronization option.
1290+
/// The implementation supports the File Synchronization option.
12711291
_POSIX_FSYNC = libc::_SC_FSYNC,
12721292
#[cfg(any(target_os="dragonfly", target_os="freebsd", target_os = "ios",
12731293
target_os="linux", target_os = "macos", target_os="openbsd"))]
@@ -1382,7 +1402,7 @@ pub enum SysconfVar {
13821402
target_os="linux", target_os = "macos", target_os="openbsd"))]
13831403
/// The implementation supports timeouts.
13841404
_POSIX_TIMEOUTS = libc::_SC_TIMEOUTS,
1385-
/// The implementation supports timers.
1405+
/// The implementation supports timers.
13861406
_POSIX_TIMERS = libc::_SC_TIMERS,
13871407
#[cfg(any(target_os="dragonfly", target_os="freebsd", target_os = "ios",
13881408
target_os="linux", target_os = "macos", target_os="openbsd"))]

0 commit comments

Comments
 (0)