Skip to content

Commit

Permalink
io: handle fread() errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
indutny committed May 7, 2013
1 parent 452817b commit db1a274
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/libcore/io.rs
Expand Up @@ -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
}
}
}
Expand Down

5 comments on commit db1a274

@bors
Copy link
Contributor

@bors bors commented on db1a274 May 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from z0w0
at indutny@db1a274

@bors
Copy link
Contributor

@bors bors commented on db1a274 May 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging indutny/rust/fix/handle-io-fread-errors = db1a274 into auto

@bors
Copy link
Contributor

@bors bors commented on db1a274 May 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indutny/rust/fix/handle-io-fread-errors = db1a274 merged ok, testing candidate = 83838aa

@bors
Copy link
Contributor

@bors bors commented on db1a274 May 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on db1a274 May 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 83838aa

Please sign in to comment.