Use the right prototype and a glob is fine (from Rafael).
[p5sagit/p5-mst-13.2.git] / perlio.c
index 25c1380..2dc18b2 100644 (file)
--- 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
@@ -2768,6 +2798,10 @@ PerlIOStdio_invalidate_fileno(pTHX_ FILE *f)
 #  elif defined(WIN32)
 #    if defined(__BORLANDC__)
     f->fd = PerlLIO_dup(fileno(f));
+#    elif defined(UNDER_CE)
+    /* WIN_CE does not have access to FILE internals, it hardly has FILE
+       structure at all
+     */
 #    else
     f->_file = -1;
 #    endif
@@ -2795,7 +2829,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
         int fd = fileno(stdio);
        int socksfd = 0;
        int invalidate = 0;
-       IV result;
+       IV result = 0;
        int saveerr = 0;
        int dupfd = 0;
 #ifdef SOCKS5_VERSION_NAME
@@ -2830,6 +2864,7 @@ PerlIOStdio_close(pTHX_ PerlIO *f)
               Use Sarathy's trick from maint-5.6 to invalidate the 
               fileno slot of the FILE * 
            */ 
+           result = PerlIO_flush(f);
            saveerr = errno;
            if (!(invalidate = PerlIOStdio_invalidate_fileno(aTHX_ stdio))) {
                dupfd = PerlLIO_dup(fd);
@@ -3338,7 +3373,7 @@ PerlIOBuf_open(pTHX_ PerlIO_funcs *self, PerlIO_list_t *layers,
 #ifdef PERLIO_USING_CRLF
 #  ifdef PERLIO_IS_BINMODE_FD
                if (PERLIO_IS_BINMODE_FD(fd))
-                   PerlIO_binmode(f,  '<'/*not used*/, O_BINARY, Nullch);
+                   PerlIO_binmode(aTHX_ f,  '<'/*not used*/, O_BINARY, Nullch);
                else
 #  endif
                /*