io: handle fread() errors

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:
Fedor Indutny 2013-05-08 01:01:04 +04:00
parent 452817b854
commit db1a274bf5
1 changed files with 12 additions and 2 deletions

View File

@ -868,9 +868,19 @@ impl Reader for *libc::FILE {
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
}
}
}