This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change stat() and -X filetests so that they treat *FILE{IO}
authorSteve Peters <steve@fisharerojo.org>
Fri, 28 Jul 2006 00:42:04 +0000 (00:42 +0000)
committerSteve Peters <steve@fisharerojo.org>
Fri, 28 Jul 2006 00:42:04 +0000 (00:42 +0000)
filehandles like *FILE filehandles.  This resolves RT #8244.

p4raw-id: //depot/perl@28628

doio.c
pp_sys.c

diff --git a/doio.c b/doio.c
index 585eb54..399cadf 100644 (file)
--- a/doio.c
+++ b/doio.c
@@ -1276,6 +1276,7 @@ Perl_my_stat(pTHX)
         if (gv == PL_defgv)
             return PL_laststatval;
        io = GvIO(gv);
+        do_fstat_have_io:
         PL_laststype = OP_STAT;
         PL_statgv = gv;
         sv_setpvn(PL_statname, "", 0);
@@ -1316,6 +1317,10 @@ Perl_my_stat(pTHX)
            gv = (GV*)SvRV(sv);
            goto do_fstat;
        }
+        else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) {
+            io = (IO*)SvRV(sv);
+            goto do_fstat_have_io;
+        }
 
        s = SvPV_const(sv, len);
        PL_statgv = NULL;
index 4246e3c..4465988 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2781,6 +2781,7 @@ PP(pp_stat)
     dVAR;
     dSP;
     GV *gv;
+    IO *io;
     I32 gimme;
     I32 max = 13;
 
@@ -2802,7 +2803,8 @@ PP(pp_stat)
            PL_statgv = gv;
            sv_setpvn(PL_statname, "", 0);
             if(gv) {
-                IO* const io = GvIO(gv);
+                io = GvIO(gv);
+                do_fstat_have_io:
                 if (io) {
                     if (IoIFP(io)) {
                         PL_laststatval = 
@@ -2832,13 +2834,18 @@ PP(pp_stat)
        if (SvTYPE(sv) == SVt_PVGV) {
            gv = (GV*)sv;
            goto do_fstat;
-       }
-       else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) {
-           gv = (GV*)SvRV(sv);
-           if (PL_op->op_type == OP_LSTAT)
-               goto do_fstat_warning_check;
-           goto do_fstat;
-       }
+       } else if(SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) {
+            gv = (GV*)SvRV(sv);
+            if (PL_op->op_type == OP_LSTAT)
+                goto do_fstat_warning_check;
+            goto do_fstat;
+        } else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVIO) { 
+            io = (IO*)SvRV(sv);
+            if (PL_op->op_type == OP_LSTAT)
+                goto do_fstat_warning_check;
+            goto do_fstat_have_io; 
+        }
+        
        sv_setpv(PL_statname, SvPV_nolen_const(sv));
        PL_statgv = NULL;
        PL_laststype = PL_op->op_type;