Skip to content

Commit 88d7db5

Browse files
committed
---
yaml --- r: 83801 b: refs/heads/try c: 5bb5f76 h: refs/heads/master i: 83799: e7410a1 v: v3
1 parent 783e59f commit 88d7db5

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: 9db32a2f1d2cfafc519941475f5e660a9ae076f0
5+
refs/heads/try: 5bb5f7678530c32caa11a1bc31e27187ff74bc19
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/rt/sched.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -859,42 +859,36 @@ fn new_sched_rng() -> XorShiftRng {
859859
use libc;
860860
use sys;
861861
use c_str::ToCStr;
862-
use ptr::RawPtr;
863862
use vec::MutableVector;
864863
use iter::Iterator;
865864
use rand::SeedableRng;
866865

867866
// 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) }
872869
};
873-
if file.is_null() {
870+
if fd == -1 {
874871
rtabort!("could not open /dev/urandom for reading.")
875872
}
876873

877874
let mut seeds = [0u32, .. 4];
875+
let size = sys::size_of_val(&seeds);
878876
loop {
879-
let nbytes = do seeds.as_mut_buf |buf, len| {
877+
let nbytes = do seeds.as_mut_buf |buf, _| {
880878
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)
885882
}
886883
};
887-
rtassert!(nbytes == seeds.len() as libc::size_t);
884+
rtassert!(nbytes as uint == size);
888885

889886
if !seeds.iter().all(|x| *x == 0) {
890887
break;
891888
}
892889
}
893890

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);}
898892

899893
SeedableRng::from_seed(seeds)
900894
}

0 commit comments

Comments
 (0)