]> git.lizzy.rs Git - rust.git/commitdiff
Fix a bug where .write([]) would always fail.
authorGareth Daniel Smith <garethdanielsmith@gmail.com>
Sat, 3 Nov 2012 18:48:02 +0000 (18:48 +0000)
committerGareth Daniel Smith <garethdanielsmith@gmail.com>
Sat, 3 Nov 2012 18:48:02 +0000 (18:48 +0000)
src/libcore/io.rs

index 77074a473e260dbf8ee17fbf3045e74b9df42ccf..c0e17230010f33ea2986a6ab6d565efb4638f59f 100644 (file)
@@ -377,9 +377,8 @@ fn get_type() -> WriterType { File }
 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 @@ fn file_reader_not_exist() {
         }
     }
 
+    #[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("?/?"), ~[]) {