File tree Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Original file line number Diff line number Diff line change @@ -954,21 +954,14 @@ pub fn getgroups() -> Result<Vec<Gid>> {
954
954
let size = try!( Errno :: result ( ret) ) ;
955
955
956
956
// Now actually get the groups
957
- let mut groups = Vec :: with_capacity ( size as usize ) ;
958
- let ret = unsafe { libc:: getgroups ( size, groups. as_mut_ptr ( ) ) } ;
957
+ let mut groups = Vec :: < Gid > :: with_capacity ( size as usize ) ;
958
+ // We can coerce a pointer to some `Gid`s as a pointer to some `gid_t`s as
959
+ // they have the same representation in memory.
960
+ let ret = unsafe { libc:: getgroups ( size, groups. as_mut_ptr ( ) as * mut gid_t ) } ;
959
961
960
962
Errno :: result ( ret) . map ( |s| {
961
- // We can coerce a pointer to some `gid_t`s as a pointer to some `Gid`s
962
- // as they have the same representation in memory.
963
- // https://doc.rust-lang.org/1.19.0/std/mem/fn.transmute.html#alternatives
964
- let gids = unsafe {
965
- Vec :: from_raw_parts (
966
- groups. as_mut_ptr ( ) as * mut Gid ,
967
- s as usize ,
968
- groups. capacity ( ) )
969
- } ;
970
- mem:: forget ( groups) ;
971
- gids
963
+ unsafe { groups. set_len ( s as usize ) } ;
964
+ groups
972
965
} )
973
966
}
974
967
You can’t perform that action at this time.
0 commit comments