Merge pull request #3912 from Dretch/iofix

Fix a bug where .write([]) would always fail.
This commit is contained in:
Tim Chevalier 2012-11-03 13:44:31 -07:00
commit c1fb590854

View file

@ -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;
@ -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("?/?"), ~[]) {