diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-10-16 18:28:48 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-10-16 18:28:48 +0000 |
commit | b77c74bc90789599ae69b0d39a1984d2768fa05e (patch) | |
tree | 0e76082a7ab4f361dffb03ec2916c3afdde4886b /perlio.c | |
parent | 70ace5dac0395f9f5ca5478d23db8cd1e0dbd6e7 (diff) | |
download | perl-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.c | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -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 = { |