summaryrefslogtreecommitdiff
path: root/doio.c
diff options
context:
space:
mode:
authorAbhijit Menon-Sen <ams@wiw.org>2002-02-16 02:43:59 +0000
committerAbhijit Menon-Sen <ams@wiw.org>2002-02-16 02:43:59 +0000
commite212fc47535368d2c67d798e231108ada401dee1 (patch)
tree172ada9591f44b9b1ef95880068e247c12adf4bd /doio.c
parent050dfae09d60a26290397d38efa5f4e336bef7e0 (diff)
downloadperl-e212fc47535368d2c67d798e231108ada401dee1.tar.gz
Absorb #14701 by Sarathy from maint-5.6.
p4raw-id: //depot/perl@14714
Diffstat (limited to 'doio.c')
-rw-r--r--doio.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/doio.c b/doio.c
index 0520992cc7..395553d1e8 100644
--- a/doio.c
+++ b/doio.c
@@ -600,9 +600,16 @@ Perl_do_openn(pTHX_ GV *gv, register char *name, I32 len, int as_raw,
UNLOCK_FDPID_MUTEX;
(void)SvUPGRADE(sv, SVt_IV);
SvIVX(sv) = pid;
- if (!was_fdopen) {
- PerlIO_close(fp);
+ if (was_fdopen) {
+ /* need to close fp without closing underlying fd */
+ int ofd = PerlIO_fileno(fp);
+ int dupfd = PerlLIO_dup(ofd);
+ PerlIO_close(fp);
+ PerlLIO_dup2(dupfd,ofd);
+ PerlLIO_close(dupfd);
}
+ else
+ PerlIO_close(fp);
}
fp = saveifp;
PerlIO_clearerr(fp);