* io.c (io_reopen): avoid dup2() equal handles not to close itself and
to get rid of a msvcrt bug. [ruby-dev:20919] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2dfe646bae
commit
f01fe1351e
@ -1,3 +1,8 @@
|
|||||||
|
Sun Jul 27 03:10:43 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* io.c (io_reopen): avoid dup2() equal handles not to close itself and
|
||||||
|
to get rid of a msvcrt bug. [ruby-dev:20919]
|
||||||
|
|
||||||
Sun Jul 27 00:37:16 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
Sun Jul 27 00:37:16 2003 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* lib/tmpdir.rb: use GetWindowsDirectory, not GetSystemDirectory.
|
* lib/tmpdir.rb: use GetWindowsDirectory, not GetSystemDirectory.
|
||||||
|
53
io.c
53
io.c
@ -2351,7 +2351,7 @@ io_reopen(io, nfile)
|
|||||||
{
|
{
|
||||||
OpenFile *fptr, *orig;
|
OpenFile *fptr, *orig;
|
||||||
char *mode;
|
char *mode;
|
||||||
int fd;
|
int fd, fd2;
|
||||||
off_t pos = 0;
|
off_t pos = 0;
|
||||||
|
|
||||||
nfile = rb_io_get_io(nfile);
|
nfile = rb_io_get_io(nfile);
|
||||||
@ -2386,36 +2386,41 @@ io_reopen(io, nfile)
|
|||||||
|
|
||||||
mode = rb_io_mode_string(fptr);
|
mode = rb_io_mode_string(fptr);
|
||||||
fd = fileno(fptr->f);
|
fd = fileno(fptr->f);
|
||||||
if (fptr->f == stdin || fptr->f == stdout || fptr->f == stderr) {
|
fd2 = fileno(orig->f);
|
||||||
clearerr(fptr->f);
|
if (fd != fd2) {
|
||||||
/* need to keep stdio objects */
|
if (fptr->f == stdin || fptr->f == stdout || fptr->f == stderr) {
|
||||||
if (dup2(fileno(orig->f), fd) < 0)
|
clearerr(fptr->f);
|
||||||
rb_sys_fail(orig->path);
|
/* need to keep stdio objects */
|
||||||
}
|
if (dup2(fd2, fd) < 0)
|
||||||
else {
|
rb_sys_fail(orig->path);
|
||||||
fclose(fptr->f);
|
}
|
||||||
if (dup2(fileno(orig->f), fd) < 0)
|
else {
|
||||||
rb_sys_fail(orig->path);
|
fclose(fptr->f);
|
||||||
fptr->f = rb_fdopen(fd, mode);
|
if (dup2(fd2, fd) < 0)
|
||||||
}
|
rb_sys_fail(orig->path);
|
||||||
rb_thread_fd_close(fd);
|
fptr->f = rb_fdopen(fd, mode);
|
||||||
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
|
}
|
||||||
io_seek(fptr, pos, SEEK_SET);
|
rb_thread_fd_close(fd);
|
||||||
io_seek(orig, pos, SEEK_SET);
|
if ((orig->mode & FMODE_READABLE) && pos >= 0) {
|
||||||
|
io_seek(fptr, pos, SEEK_SET);
|
||||||
|
io_seek(orig, pos, SEEK_SET);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fptr->f2 && fd != fileno(fptr->f2)) {
|
if (fptr->f2 && fd != fileno(fptr->f2)) {
|
||||||
fd = fileno(fptr->f2);
|
fd = fileno(fptr->f2);
|
||||||
fclose(fptr->f2);
|
if (!orig->f2) {
|
||||||
rb_thread_fd_close(fd);
|
fclose(fptr->f2);
|
||||||
if (orig->f2) {
|
rb_thread_fd_close(fd);
|
||||||
if (dup2(fileno(orig->f2), fd) < 0)
|
fptr->f2 = 0;
|
||||||
|
}
|
||||||
|
else if (fd != (fd2 = fileno(orig->f2))) {
|
||||||
|
fclose(fptr->f2);
|
||||||
|
rb_thread_fd_close(fd);
|
||||||
|
if (dup2(fd2, fd) < 0)
|
||||||
rb_sys_fail(orig->path);
|
rb_sys_fail(orig->path);
|
||||||
fptr->f2 = rb_fdopen(fd, "w");
|
fptr->f2 = rb_fdopen(fd, "w");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
fptr->f2 = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fptr->mode & FMODE_BINMODE) {
|
if (fptr->mode & FMODE_BINMODE) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user