summaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-06 12:31:53 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-10-06 12:31:53 +0000
commit1f539dba0667949e42ec9603af3d7e7fb784781f (patch)
treeb0c51b67f8c95f0f532b29913823a2106d098ec6 /io.c
parent1600abf840481b5ce0696dbbb97e694435d9e3a5 (diff)
downloadruby-1f539dba0667949e42ec9603af3d7e7fb784781f.tar.gz
ruby-1f539dba0667949e42ec9603af3d7e7fb784781f.tar.xz
ruby-1f539dba0667949e42ec9603af3d7e7fb784781f.zip
* io.c (io_reopen): avoid close if possible.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25244 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/io.c b/io.c
index d8af0bdc2..e3f913af2 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);