Skip to content

Commit 020172b

Browse files
committed
wall: get macos to use correct types
1 parent 8f1f189 commit 020172b

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/uu/wall/src/wall.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -311,26 +311,21 @@ fn is_gr_member(user: &[c_char], gid: gid_t) -> bool {
311311
// on macos, getgrouplist takes c_int as its group argument,
312312
// other unices should use gid_t like linux
313313
#[cfg(target_os = "macos")]
314-
let base_gid = group as libc::c_int;
315-
#[cfg(not(target_os = "macos"))]
316-
let base_gid = group;
314+
let group = group as libc::c_int;
317315

318316
// otherwise check gid is in list of supplementary groups user belongs to
319317
let mut ngroups = 16;
320-
let mut groups: Vec<gid_t> = vec![0; ngroups as usize];
321-
while unsafe {
322-
libc::getgrouplist(
323-
user.as_ptr(),
324-
base_gid,
325-
groups.as_mut_ptr(),
326-
&raw mut ngroups,
327-
)
328-
} == -1
318+
let mut groups = vec![0; ngroups as usize];
319+
while unsafe { libc::getgrouplist(user.as_ptr(), group, groups.as_mut_ptr(), &raw mut ngroups) }
320+
== -1
329321
{
330322
// ret -1 means buffer was too small so we resize
331323
// according to the returned ngroups value
332324
groups.resize(ngroups as usize, 0);
333325
}
326+
327+
#[cfg(target_os = "macos")]
328+
let gid = gid as libc::c_int;
334329
groups.contains(&gid)
335330
}
336331

tests/by-util/test_wall.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ mod tests {
33
use uutests::new_ucmd;
44

55
#[test]
6-
fn test_invalid_arg() { new_ucmd!().arg("--definitely-invalid").fails().code_is(1); }
6+
fn test_invalid_arg() {
7+
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
8+
}
79

810
#[test]
911
fn test_fails_on_invalid_group() {
@@ -46,5 +48,7 @@ mod tests {
4648
}
4749

4850
#[test]
49-
fn test_succeeds_no_stdout() { new_ucmd!().pipe_in("pipe me").succeeds().stdout_is(""); }
51+
fn test_succeeds_no_stdout() {
52+
new_ucmd!().pipe_in("pipe me").succeeds().stdout_is("");
53+
}
5054
}

0 commit comments

Comments
 (0)