@@ -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,6 +3568,18 @@ impl Group {
3569
3568
///
3570
3569
/// # Examples
3571
3570
///
3571
+ // Disable this test on all OS except Apple as everyone group may not exist.
3572
+ #[ cfg_attr( not( apple_targets) , doc = " ```no_run" ) ]
3573
+ #[ cfg_attr( apple_targets, doc = " ```" ) ]
3574
+ /// use nix::unistd::Group;
3575
+ /// // Returns an Result<Option<Group>>, thus the double unwrap.
3576
+ /// let group = Group::from_name("everyone").unwrap().unwrap();
3577
+ /// assert!(group.name == "everyone");
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, "everyone");
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 = " ```" ) ]
0 commit comments