auto merge of #6311 : indutny/rust/fix/handle-io-fread-errors, r=z0w0

When, occasionally, trying to read directory instead of file, `fread()`
returns `EISDIR` error. And, considering, absence of error handling,
`read_whole_stream()` just loops indefinitely.
This commit is contained in:
bors 2013-05-08 03:54:38 -07:00
commit 83838aa429

View File

@ -868,9 +868,19 @@ fn read(&self, bytes: &mut [u8], len: uint) -> uint {
assert!(buf_len >= len);
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
len as size_t, *self);
len as size_t, *self) as uint;
if count < len {
match libc::ferror(*self) {
0 => (),
_ => {
error!("error reading buffer");
error!("%s", os::last_os_error());
fail!();
}
}
}
count as uint
count
}
}
}