summaryrefslogtreecommitdiff
path: root/doio.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 /doio.c
parent88e01c9dba7e9c1403ea12dc83a20252782bb76f (diff)
downloadperl-5228a96c60a47c008c307f4fa3bf942383d38423.tar.gz
Allow stat() and -X file tests work on dirhandles.
p4raw-id: //depot/perl@28473
Diffstat (limited to 'doio.c')
-rw-r--r--doio.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/doio.c b/doio.c
index 41f026fc9c..25756ab5dd 100644
--- a/doio.c
+++ b/doio.c
@@ -1308,22 +1308,31 @@ Perl_my_stat(pTHX)
EXTEND(SP,1);
gv = cGVOP_gv;
do_fstat:
+ if (gv == PL_defgv)
+ return PL_laststatval;
io = GvIO(gv);
- if (io && IoIFP(io)) {
- PL_statgv = gv;
- sv_setpvn(PL_statname,"", 0);
- PL_laststype = OP_STAT;
- return (PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache));
- }
- else {
- if (gv == PL_defgv)
- return PL_laststatval;
- if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
- report_evil_fh(gv, io, PL_op->op_type);
- PL_statgv = NULL;
- sv_setpvn(PL_statname,"", 0);
- return (PL_laststatval = -1);
- }
+ PL_laststype = OP_STAT;
+ PL_statgv = gv;
+ sv_setpvn(PL_statname, "", 0);
+ if(io) {
+ if (IoIFP(io)) {
+ return (PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache));
+ } else if (IoDIRP(io)) {
+#ifdef HAS_DIRFD
+ return (PL_laststatval = PerlLIO_fstat(dirfd(IoDIRP(io)), &PL_statcache));
+#else
+ DIE(aTHX_ PL_no_func, "dirfd");
+#endif
+ } else {
+ if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
+ report_evil_fh(gv, io, PL_op->op_type);
+ return (PL_laststatval = -1);
+ }
+ } else {
+ if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
+ report_evil_fh(gv, io, PL_op->op_type);
+ return (PL_laststatval = -1);
+ }
}
else if (PL_op->op_private & OPpFT_STACKED) {
return PL_laststatval;