Move setgroups() to grp.h

This commit is contained in:
Peter Limkilde Svendsen
2026-04-13 22:56:56 +02:00
parent 539d04009a
commit fbccaff46c
3 changed files with 17 additions and 17 deletions
+16 -6
View File
@@ -18,12 +18,14 @@ use alloc::{
};
use crate::{
error::ResultExt,
fs::File,
header::{errno, fcntl, limits, string::strlen, unistd},
io,
io::{BufReader, Lines, prelude::*},
platform,
platform::types::{c_char, c_int, c_void, gid_t, size_t},
header::{errno, fcntl, limits, string::strlen},
io::{self, BufReader, Lines, prelude::*},
platform::{
self, Pal, Sys,
types::{c_char, c_int, c_void, gid_t, size_t},
},
};
use super::{errno::*, string::strncmp};
@@ -544,5 +546,13 @@ pub unsafe extern "C" fn initgroups(user: *const c_char, gid: gid_t) -> c_int {
if unsafe { getgrouplist(user, gid, groups.as_mut_ptr(), &raw mut count) < 0 } {
return -1;
}
unsafe { unistd::setgroups(count as size_t, groups.as_ptr()) }
unsafe { setgroups(count as size_t, groups.as_ptr()) }
}
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/setgroups.2.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn setgroups(size: size_t, list: *const gid_t) -> c_int {
unsafe { Sys::setgroups(size, list) }
.map(|()| 0)
.or_minus_one_errno()
}
-10
View File
@@ -899,16 +899,6 @@ pub extern "C" fn setgid(gid: gid_t) -> c_int {
.or_minus_one_errno()
}
/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/setgroups.2.html>.
///
/// TODO: specified in `grp.h`?
#[unsafe(no_mangle)]
pub unsafe extern "C" fn setgroups(size: size_t, list: *const gid_t) -> c_int {
unsafe { Sys::setgroups(size, list) }
.map(|()| 0)
.or_minus_one_errno()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/setpgid.html>.
#[unsafe(no_mangle)]
pub extern "C" fn setpgid(pid: pid_t, pgid: pid_t) -> c_int {
+1 -1
View File
@@ -349,7 +349,7 @@ pub trait Pal {
/// Platform implementation of [`sched_yield()`](crate::header::sched::sched_yield) from [`sched.h`](crate::header::sched).
fn sched_yield() -> Result<()>;
/// Platform implementation of [`setgroups()`](crate::header::unistd::setgroups) from [`unistd.h`](crate::header::unistd) (TODO: should be `grp.h`?).
/// Platform implementation of [`setgroups()`](crate::header::grp::setgroups) from [`grp.h`](crate::header::grp).
unsafe fn setgroups(size: size_t, list: *const gid_t) -> Result<()>;
/// Platform implementation of [`setpgid()`](crate::header::unistd::setpgid) from [`unistd.h`](crate::header::unistd).