Skip to content

Fix a bug where .write([]) would always fail. #3912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,8 @@ impl<T: Writer, C> {base: T, cleanup: C}: Writer {
impl *libc::FILE: Writer {
fn write(v: &[const u8]) {
do vec::as_const_buf(v) |vbuf, len| {
let nout = libc::fwrite(vbuf as *c_void, len as size_t,
1u as size_t, self);
if nout < 1 as size_t {
let nout = libc::fwrite(vbuf as *c_void, 1, len as size_t, self);
if nout != len as size_t {
error!("error writing buffer");
log(error, os::last_os_error());
fail;
Expand Down Expand Up @@ -959,6 +958,13 @@ mod tests {
}
}

#[test]
fn test_write_empty() {
let file = io::file_writer(&Path("tmp/lib-io-test-write-empty.tmp"),
[io::Create]).get();
file.write([]);
}

#[test]
fn file_writer_bad_name() {
match io::file_writer(&Path("?/?"), ~[]) {
Expand Down