Skip to content

Commit db1a274

Browse files
committed
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.
1 parent 452817b commit db1a274

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/libcore/io.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,19 @@ impl Reader for *libc::FILE {
868868
assert!(buf_len >= len);
869869

870870
let count = libc::fread(buf_p as *mut c_void, 1u as size_t,
871-
len as size_t, *self);
871+
len as size_t, *self) as uint;
872+
if count < len {
873+
match libc::ferror(*self) {
874+
0 => (),
875+
_ => {
876+
error!("error reading buffer");
877+
error!("%s", os::last_os_error());
878+
fail!();
879+
}
880+
}
881+
}
872882

873-
count as uint
883+
count
874884
}
875885
}
876886
}

0 commit comments

Comments
 (0)