From a42d2d408a74f677bb58a799f995d69f9fdd8438 Mon Sep 17 00:00:00 2001 From: Gareth Daniel Smith Date: Sat, 3 Nov 2012 18:48:02 +0000 Subject: [PATCH] Fix a bug where .write([]) would always fail. --- src/libcore/io.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 77074a473e260..c0e17230010f3 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -377,9 +377,8 @@ impl {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; @@ -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("?/?"), ~[]) {