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;
=item -X EXPR
+=item -X DIRHANDLE
+
=item -X
A file test, where X is one of the letters listed below. This unary
-operator takes one argument, either a filename or a filehandle, and
-tests the associated file to see if something is true about it. If the
+operator takes one argument, either a filename, a filehandle, or a dirhandle,
+and tests the associated file to see if something is true about it. If the
argument is omitted, tests C<$_>, except for C<-t>, which tests STDIN.
Unless otherwise documented, it returns C<1> for true and C<''> for false, or
the undefined value if the file doesn't exist. Despite the funny
=item stat EXPR
+=item stat DIRHANDLE
+
=item stat
Returns a 13-element list giving the status info for a file, either
-the file opened via FILEHANDLE, or named by EXPR. If EXPR is omitted,
-it stats C<$_>. Returns a null list if the stat fails. Typically used
-as follows:
+the file opened via FILEHANDLE or DIRHANDLE, or named by EXPR. If EXPR is
+omitted, it stats C<$_>. Returns a null list if the stat fails. Typically
+used as follows:
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
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);
use Config;
use File::Spec;
-plan tests => 86;
+plan tests => 88;
my $Perl = which_perl();
unlink $tmpfile;
}
+SKIP: {
+ skip "No dirfd()", 2 unless $Config{d_dirfd};
+ opendir my $dir, "." or die 'Unable to opendir ".": $!';
+ ok(stat($dir), "stat() on dirhandle works");
+ ok(-d -r _ , "chained -x's on dirhandle");
+}
+
END {
1 while unlink $tmpfile;
}