summaryrefslogtreecommitdiff
path: root/perlio.c
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2001-10-16 18:28:48 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2001-10-16 18:28:48 +0000
commitb77c74bc90789599ae69b0d39a1984d2768fa05e (patch)
tree0e76082a7ab4f361dffb03ec2916c3afdde4886b /perlio.c
parent70ace5dac0395f9f5ca5478d23db8cd1e0dbd6e7 (diff)
downloadperl-b77c74bc90789599ae69b0d39a1984d2768fa05e.tar.gz
Implement PerlIOStdio_dup (explains core dumps - dup
was not setting up a FILE * to be fclosed()). p4raw-id: //depot/perlio@12461
Diffstat (limited to 'perlio.c')
-rw-r--r--perlio.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/perlio.c b/perlio.c
index 4f79b71c7d..dd9f394c84 100644
--- a/perlio.c
+++ b/perlio.c
@@ -2016,7 +2016,6 @@ PerlIO *
PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param)
{
PerlIO *nexto = PerlIONext(o);
- PerlIO_debug("PerlIOBase_dup f=%p o=%p param=%p\n",f,o,param);
if (*nexto) {
PerlIO_funcs *tab = PerlIOBase(nexto)->tab;
f = (*tab->Dup)(aTHX_ f, nexto, param);
@@ -2025,6 +2024,7 @@ PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param)
PerlIO_funcs *self = PerlIOBase(o)->tab;
SV *arg = Nullsv;
char buf[8];
+ PerlIO_debug("PerlIOBase_dup %s f=%p o=%p param=%p\n",self->name,f,o,param);
if (self->Getarg) {
arg = (*self->Getarg)(o);
if (arg) {
@@ -2549,7 +2549,27 @@ PerlIOStdio_set_ptrcnt(PerlIO *f, STDCHAR * ptr, SSize_t cnt)
PerlIO *
PerlIOStdio_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param)
{
- return PerlIOBase_dup(aTHX_ f, o, param);
+ /* This assumes no layers underneath - which is what
+ happens, but is not how I remember it. NI-S 2001/10/16
+ */
+ int fd = PerlLIO_dup(PerlIO_fileno(o));
+ if (fd >= 0) {
+ char buf[8];
+ FILE *stdio = PerlSIO_fdopen(fd, PerlIO_modestr(o, buf));
+ if (stdio) {
+ if ((f = PerlIOBase_dup(aTHX_ f, o, param))) {
+ PerlIOSelf(f, PerlIOStdio)->stdio = stdio;
+ }
+ else {
+ PerlSIO_fclose(stdio);
+ }
+ }
+ else {
+ PerlLIO_close(fd);
+ f = NULL;
+ }
+ }
+ return f;
}
PerlIO_funcs PerlIO_stdio = {