| 437 | |
| 438 | #[cfg(any(target_os = "macos", target_os = "ios"))] |
| 439 | fn getgroups_impl() -> nix::Result<Vec<Gid>> { |
| 440 | use core::ptr; |
| 441 | use libc::{c_int, gid_t}; |
| 442 | |
| 443 | let ret = unsafe { libc::getgroups(0, ptr::null_mut()) }; |
| 444 | let mut groups = Vec::<Gid>::with_capacity(Errno::result(ret)? as usize); |
| 445 | let ret = unsafe { |
| 446 | libc::getgroups( |
| 447 | groups.capacity() as c_int, |
| 448 | groups.as_mut_ptr() as *mut gid_t, |
| 449 | ) |
| 450 | }; |
| 451 | |
| 452 | Errno::result(ret).map(|s| { |
| 453 | unsafe { groups.set_len(s as usize) }; |
| 454 | groups |
| 455 | }) |
| 456 | } |
| 457 | |
| 458 | #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "redox")))] |
| 459 | use nix::unistd::getgroups as getgroups_impl; |