@@ -859,42 +859,36 @@ fn new_sched_rng() -> XorShiftRng {
859
859
use libc;
860
860
use sys;
861
861
use c_str:: ToCStr ;
862
- use ptr:: RawPtr ;
863
862
use vec:: MutableVector ;
864
863
use iter:: Iterator ;
865
864
use rand:: SeedableRng ;
866
865
867
866
// XXX: this could use io::native::file, when it works.
868
- let file = do "/dev/urandom" . with_c_str |name| {
869
- do "r" . with_c_str |mode| {
870
- unsafe { libc:: fopen ( name, mode) }
871
- }
867
+ let fd = do "/dev/urandom" . with_c_str |name| {
868
+ unsafe { libc:: open ( name, libc:: O_RDONLY , 0 ) }
872
869
} ;
873
- if file . is_null ( ) {
870
+ if fd == - 1 {
874
871
rtabort ! ( "could not open /dev/urandom for reading." )
875
872
}
876
873
877
874
let mut seeds = [ 0u32 , .. 4 ] ;
875
+ let size = sys:: size_of_val ( & seeds) ;
878
876
loop {
879
- let nbytes = do seeds. as_mut_buf |buf, len | {
877
+ let nbytes = do seeds. as_mut_buf |buf, _ | {
880
878
unsafe {
881
- libc:: fread ( buf as * mut libc:: c_void ,
882
- sys:: size_of :: < u32 > ( ) as libc:: size_t ,
883
- len as libc:: size_t ,
884
- file)
879
+ libc:: read ( fd,
880
+ buf as * mut libc:: c_void ,
881
+ size as libc:: size_t )
885
882
}
886
883
} ;
887
- rtassert ! ( nbytes == seeds . len ( ) as libc :: size_t ) ;
884
+ rtassert ! ( nbytes as uint == size ) ;
888
885
889
886
if !seeds. iter ( ) . all ( |x| * x == 0 ) {
890
887
break ;
891
888
}
892
889
}
893
890
894
- // XXX: do we need to guarantee that this is closed with a finally
895
- // block (is that even possible without a scheduler?), or do we
896
- // know that the only way that we can fail here is `abort`ing?
897
- unsafe { libc:: fclose ( file) ; }
891
+ unsafe { libc:: close ( fd) ; }
898
892
899
893
SeedableRng :: from_seed ( seeds)
900
894
}
0 commit comments