@@ -3476,18 +3476,17 @@ impl Group {
3476
3476
let mut ret = Vec :: new( ) ;
3477
3477
3478
3478
for i in 0 .. {
3479
- let u = unsafe { mem. offset( i) } ;
3480
- if unsafe { ( * u ) . is_null( ) } {
3479
+ let u = unsafe { mem. offset( i) . read_unaligned ( ) } ;
3480
+ if u . is_null( ) {
3481
3481
break ;
3482
3482
} else {
3483
- let s = unsafe { CStr :: from_ptr( * u) . to_string_lossy( ) . into_owned( ) } ;
3483
+ let s = unsafe { CStr :: from_ptr( u) . to_string_lossy( ) . into_owned( ) } ;
3484
3484
ret. push( s) ;
3485
3485
}
3486
3486
}
3487
3487
3488
3488
ret
3489
3489
}
3490
-
3491
3490
/// # Safety
3492
3491
///
3493
3492
/// If `f` writes to its `*mut *mut libc::group` parameter, then it must
@@ -3569,13 +3568,29 @@ impl Group {
3569
3568
///
3570
3569
/// # Examples
3571
3570
///
3571
+ // Disable this test on all OS except BSD as wheel group may not exist.
3572
+ #[ cfg_attr( not( any( apple_targets, bsd) ) , doc = " ```no_run" ) ]
3573
+ #[ cfg_attr( any( apple_targets, bsd) , doc = " ```" ) ]
3574
+ /// use nix::unistd::Group;
3575
+ /// // Returns an Result<Option<Group>>, thus the double unwrap.
3576
+ /// let group = Group::from_name("wheel").unwrap().unwrap();
3577
+ /// assert!(group.name == "wheel");
3578
+ /// let group_id = group.gid;
3579
+ /// let group = Group::from_gid(group_id).unwrap().unwrap();
3580
+ /// assert_eq!(group.gid, group_id);
3581
+ /// assert_eq!(group.name, "wheel");
3582
+ /// ```
3572
3583
// Disable this test on all OS except Linux as root group may not exist.
3573
3584
#[ cfg_attr( not( target_os = "linux" ) , doc = " ```no_run" ) ]
3574
3585
#[ cfg_attr( target_os = "linux" , doc = " ```" ) ]
3575
3586
/// use nix::unistd::Group;
3576
3587
/// // Returns an Result<Option<Group>>, thus the double unwrap.
3577
- /// let res = Group::from_name("root").unwrap().unwrap();
3578
- /// assert!(res.name == "root");
3588
+ /// let group = Group::from_name("root").unwrap().unwrap();
3589
+ /// assert!(group.name == "root");
3590
+ /// let group_id = group.gid;
3591
+ /// let group = Group::from_gid(group_id).unwrap().unwrap();
3592
+ /// assert_eq!(group.gid, group_id);
3593
+ /// assert_eq!(group.name, "root");
3579
3594
/// ```
3580
3595
pub fn from_name( name: & str ) -> Result <Option <Self >> {
3581
3596
let name = match CString :: new( name) {
0 commit comments