diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -6665,10 +6665,14 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file) } } else { - if (close(fptr->fd) < 0) - rb_sys_fail_path(fptr->pathv); - fptr->fd = -1; - fptr->fd = rb_sysopen(fptr->pathv, oflags, 0666); + int tmpfd = rb_sysopen(fptr->pathv, oflags, 0666); + int err = 0; + if (rb_cloexec_dup2(tmpfd, fptr->fd) < 0) + err = errno; + (void)close(tmpfd); + if (err) { + rb_syserr_fail_path(err, fptr->pathv); + } } return file; |