summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorSteve Peters <steve@fisharerojo.org>2006-07-03 18:09:01 +0000
committerSteve Peters <steve@fisharerojo.org>2006-07-03 18:09:01 +0000
commit5228a96c60a47c008c307f4fa3bf942383d38423 (patch)
tree70ae56d50266f791be5436a6f593a84a7cf33c94 /pp_sys.c
parent88e01c9dba7e9c1403ea12dc83a20252782bb76f (diff)
downloadperl-5228a96c60a47c008c307f4fa3bf942383d38423.tar.gz
Allow stat() and -X file tests work on dirhandles.
p4raw-id: //depot/perl@28473
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 0c3d6de738..25deca1f9e 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2790,9 +2790,26 @@ PP(pp_stat)
PL_laststype = OP_STAT;
PL_statgv = gv;
sv_setpvn(PL_statname, "", 0);
- PL_laststatval = (GvIO(gv) && IoIFP(GvIOp(gv))
- ? PerlLIO_fstat(PerlIO_fileno(IoIFP(GvIOn(gv))), &PL_statcache) : -1);
- }
+ if(gv) {
+ IO* const io = GvIO(gv);
+ if (io) {
+ if (IoIFP(io)) {
+ PL_laststatval =
+ PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);
+ } else if (IoDIRP(io)) {
+#ifdef HAS_DIRFD
+ PL_laststatval =
+ PerlLIO_fstat(dirfd(IoDIRP(io)), &PL_statcache);
+#else
+ DIE(aTHX_ PL_no_func, "dirfd");
+#endif
+ } else {
+ PL_laststatval = -1;
+ }
+ }
+ }
+ }
+
if (PL_laststatval < 0) {
if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
report_evil_fh(gv, GvIO(gv), PL_op->op_type);