Skip to content

Commit 71d1e44

Browse files
committed
unistd: Add initgroups
1 parent 4614cba commit 71d1e44

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/unistd.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,22 @@ pub fn setgroups(groups: &[Gid]) -> Result<()> {
961961
Errno::result(res).map(drop)
962962
}
963963

964+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "macos", target_os = "ios"))]
965+
#[inline]
966+
pub fn initgroups(user: &CString, group: Gid) -> Result<()> {
967+
cfg_if! {
968+
if #[cfg(any(target_os = "macos", target_os = "ios"))] {
969+
type initgroups_group_t = c_int;
970+
} else {
971+
type initgroups_group_t = gid_t;
972+
}
973+
}
974+
let gid: gid_t = group.into();
975+
let res = unsafe { libc::initgroups(user.as_ptr(), gid as initgroups_group_t) };
976+
977+
Errno::result(res).map(drop)
978+
}
979+
964980
#[inline]
965981
pub fn pause() -> Result<()> {
966982
let res = unsafe { libc::pause() };

0 commit comments

Comments
 (0)