Skip to content

Commit 9c6b2e0

Browse files
committed
---
yaml --- r: 145827 b: refs/heads/try2 c: 5bb5f76 h: refs/heads/master i: 145825: ac5f301 145823: 9bc546d v: v3
1 parent f9d9536 commit 9c6b2e0

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9db32a2f1d2cfafc519941475f5e660a9ae076f0
8+
refs/heads/try2: 5bb5f7678530c32caa11a1bc31e27187ff74bc19
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)