diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-09 08:48:41 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-09 08:48:41 +0000 |
commit | 507f89d33fb2c3fb7180dfda1a27364819f67f32 (patch) | |
tree | e9efbe9380442937004f36aeace64e602f9424c2 /io.c | |
parent | 3854be4322afc4c90dafef6f7907354b7bbd83d7 (diff) | |
download | ruby-507f89d33fb2c3fb7180dfda1a27364819f67f32.tar.gz |
* io.c (fptr_finalize): close IO object if fd is already closed.
(rb_p): call rb_io_write just once.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -2673,6 +2673,7 @@ rb_io_set_close_on_exec(VALUE io, VALUE arg) static void fptr_finalize(rb_io_t *fptr, int noraise) { + int ebadf = 0; if (fptr->wbuf_len) { io_fflush(fptr); } @@ -2690,13 +2691,22 @@ fptr_finalize(rb_io_t *fptr, int noraise) } else if (0 <= fptr->fd) { if (close(fptr->fd) < 0 && !noraise) { - /* fptr->fd is still not closed */ - rb_sys_fail(fptr->path); + if (errno != EBADF) { + /* fptr->fd is still not closed */ + rb_sys_fail(fptr->path); + } + else { + /* fptr->fd is already closed. */ + ebadf = 1; + } } } fptr->fd = -1; fptr->stdio_file = 0; fptr->mode &= ~(FMODE_READABLE|FMODE_WRITABLE); + if (ebadf) { + rb_sys_fail(fptr->path); + } } static void @@ -4750,8 +4760,9 @@ rb_f_puts(int argc, VALUE *argv, VALUE recv) void rb_p(VALUE obj) /* for debug print within C code */ { - rb_io_write(rb_stdout, rb_obj_as_string(rb_inspect(obj))); - rb_io_write(rb_stdout, rb_default_rs); + VALUE str = rb_obj_as_string(rb_inspect(obj)); + rb_str_buf_append(str, rb_default_rs); + rb_io_write(rb_stdout, str); } /* |