aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--io.c13
2 files changed, 9 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 33124ba8ac..c1de680ef8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Oct 6 21:30:58 2009 Tanaka Akira <akr@fsij.org>
+
+ * io.c (io_reopen): avoid close if possible.
+
Tue Oct 6 18:56:09 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (rb_struct_select): Struct#select should return
diff --git a/io.c b/io.c
index d8af0bdc2b..e3f913af23 100644
--- a/io.c
+++ b/io.c
@@ -5684,20 +5684,17 @@ io_reopen(VALUE io, VALUE nfile)
fd = fptr->fd;
fd2 = orig->fd;
if (fd != fd2) {
- if (IS_PREP_STDIO(fptr)) {
- /* need to keep stdio objects */
+ if (IS_PREP_STDIO(fptr) || fd <= 2 || !fptr->stdio_file) {
+ /* need to keep FILE objects of stdin, stdout and stderr */
if (dup2(fd2, fd) < 0)
rb_sys_fail_path(orig->pathv);
}
else {
- if (fptr->stdio_file)
- fclose(fptr->stdio_file);
- else
- close(fptr->fd);
+ fclose(fptr->stdio_file);
fptr->stdio_file = 0;
fptr->fd = -1;
- if (dup2(fd2, fd) < 0)
- rb_sys_fail_path(orig->pathv);
+ if (dup2(fd2, fd) < 0)
+ rb_sys_fail_path(orig->pathv);
fptr->fd = fd;
}
rb_thread_fd_close(fd);