summaryrefslogtreecommitdiff
path: root/perlio.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-04-14 17:35:51 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-04-14 17:35:51 +0000
commit39f7a87036eb8d13c207511143dc7f2e620b3891 (patch)
tree6ff5e9911b13a8b869ce1243c9e8df24657f3f95 /perlio.c
parent119586db753fab6875f9973c20a57e0d66dbfbcf (diff)
downloadperl-39f7a87036eb8d13c207511143dc7f2e620b3891.tar.gz
Introduce PerlIO::get_layers() to allow people to peek
at the PerlIO layer stack. p4raw-id: //depot/perl@19203
Diffstat (limited to 'perlio.c')
-rw-r--r--perlio.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/perlio.c b/perlio.c
index 6b37c63b35..2dc18b2624 100644
--- a/perlio.c
+++ b/perlio.c
@@ -640,6 +640,36 @@ PerlIO_pop(pTHX_ PerlIO *f)
}
}
+/* Return as an array the stack of layers on a filehandle. Note that
+ * the stack is returned top-first in the array, and there are three
+ * times as many array elements as there are layers in the stack: the
+ * first element of a layer triplet is the name, the second one is the
+ * arguments, and the third one is the flags. */
+
+AV *
+PerlIO_get_layers(pTHX_ PerlIO *f)
+{
+ AV *av = newAV();
+
+ if (PerlIOValid(f)) {
+ dSP;
+ PerlIOl *l = PerlIOBase(f);
+
+ while (l) {
+ SV *name = l->tab && l->tab->name ?
+ newSVpv(l->tab->name, 0) : &PL_sv_undef;
+ SV *arg = l->tab && l->tab->Getarg ?
+ (*l->tab->Getarg)(aTHX_ &l, 0, 0) : &PL_sv_undef;
+ av_push(av, name);
+ av_push(av, arg);
+ av_push(av, newSViv((IV)l->flags));
+ l = l->next;
+ }
+ }
+
+ return av;
+}
+
/*--------------------------------------------------------------------------------------*/
/*
* XS Interface for perl code