@@ -15,7 +15,6 @@ use lazy_static::lazy_static;
1515use  std:: { 
1616    fs:: File , 
1717    io:: Read , 
18-     os:: unix:: io:: { FromRawFd ,  IntoRawFd ,  RawFd } , 
1918} ; 
2019
2120#[ cfg( target_os = "redox" ) ]  
@@ -33,9 +32,9 @@ const FILE_PATH: &str = "/dev/random";
3332
3433pub  fn  getrandom_inner ( dest :  & mut  [ u8 ] )  -> Result < ( ) ,  Error >  { 
3534    lazy_static !  { 
36-         static  ref RNG_FD :  Result <RawFd ,  Error > = init_file( ) ; 
35+         static  ref FILE :  Result <File ,  Error > = init_file( ) ; 
3736    } 
38-     let  mut  f = unsafe   {   File :: from_raw_fd ( ( * RNG_FD ) ? )   } ; 
37+     let  mut  f = FILE . as_ref ( ) ? ; 
3938
4039    if  cfg ! ( target_os = "emscripten" )  { 
4140        // `Crypto.getRandomValues` documents `dest` should be at most 65536 bytes. 
@@ -48,12 +47,12 @@ pub fn getrandom_inner(dest: &mut [u8]) -> Result<(), Error> {
4847    Ok ( ( ) ) 
4948} 
5049
51- fn  init_file ( )  -> Result < RawFd ,  Error >  { 
50+ fn  init_file ( )  -> Result < File ,  Error >  { 
5251    if  FILE_PATH  == "/dev/urandom"  { 
5352        // read one byte from "/dev/random" to ensure that OS RNG has initialized 
5453        File :: open ( "/dev/random" ) ?. read_exact ( & mut  [ 0u8 ;  1 ] ) ?; 
5554    } 
56-     Ok ( File :: open ( FILE_PATH ) ?. into_raw_fd ( ) ) 
55+     Ok ( File :: open ( FILE_PATH ) ?) 
5756} 
5857
5958#[ inline( always) ]  
0 commit comments