diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-01-29 08:18:03 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-01-29 08:18:03 +0000 |
commit | 9ba3d42046af4721998adfe3c6bd6bc9220234f4 (patch) | |
tree | 5265a1ccc13db7b0201b6f9245f6f07846525ce3 /io.c | |
parent | a72e3e187d8e49040532a4563ae832f869657501 (diff) |
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@57 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 39 |
1 files changed, 11 insertions, 28 deletions
@@ -1144,18 +1144,21 @@ io_reopen(io, nfile) mode = io_mode_string(fptr); fd = fileno(fptr->f); - if (fileno(fptr->f) < 3) /* need to keep stdio */ + if (fileno(fptr->f) < 3) { + /* need to keep stdio */ + dup2(fileno(orig->f), fd); + } + else { fclose(fptr->f); - dup2(fileno(orig->f), fd); - fptr->f = rb_fdopen(fd, mode); + fptr->f = rb_fdopen(fd, mode); + } if (fptr->f2) { fd = fileno(fptr->f2); - if (fileno(fptr->f2) < 3) - fclose(fptr->f2); + fclose(fptr->f2); if (orig->f2) { dup2(fileno(orig->f2), fd); - fptr->f = rb_fdopen(fd, "w"); + fptr->f2 = rb_fdopen(fd, "w"); } else { fptr->f2 = 0; @@ -1397,32 +1400,12 @@ io_errset(val, id) { OpenFile *fptr; int fd; + FILE *f; if (TYPE(val) != T_FILE) { TypeError("$stderr must be IO Object"); } - GetOpenFile(val, fptr); - io_writable(fptr); - rb_stderr = val; - - fd = fileno(fptr->f2?fptr->f2:fptr->f); - if (fd != 2) { - FILE *f; - - fflush(stderr); - dup2(fd, 2); - f = rb_fdopen(2, io_mode_string(fptr)); - if (fptr->f2) { - if (fileno(fptr->f2) < 3) /* need to keep stdio */ - fclose(fptr->f2); - fptr->f2 = f; - } - else { - if (fileno(fptr->f) < 3) - fclose(fptr->f); - fptr->f = f; - } - } + io_reopen(rb_stderr, val); } static VALUE |