Skip to content

Commit f2ada86

Browse files
committed
unistd::getgroups: respond to comments
1 parent f4a665f commit f2ada86

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/unistd.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,9 +954,11 @@ pub fn getgroups() -> Result<Vec<Gid>> {
954954
// First get the number of groups so we can size our Vec
955955
use std::ptr;
956956
let ret = unsafe { libc::getgroups(0, ptr::null_mut()) };
957-
let mut size = try!(Errno::result(ret));
957+
let mut size = Errno::result(ret)?;
958958

959-
// Now actually get the groups
959+
// Now actually get the groups. We try multiple times in case the number of
960+
// groups has changed since the first call to getgroups() and the buffer is
961+
// now too small
960962
let mut groups = Vec::<Gid>::with_capacity(size as usize);
961963
loop {
962964
// We can coerce a pointer to some `Gid`s as a pointer to some `gid_t`s

0 commit comments

Comments
 (0)