As documented in perldiag, lstat($gv) warns and does an fstat.
lstat($ioref) wasn’t doing what was documented, but after warning
would do the same as stat(_).
havefp = FALSE;
if (gv != PL_defgv) {
+ do_fstat_have_io:
PL_laststype = OP_STAT;
- PL_statgv = gv;
+ PL_statgv = gv ? gv : (GV *)io;
sv_setpvs(PL_statname, "");
if(gv) {
io = GvIO(gv);
- do_fstat_have_io:
- if (io) {
+ }
+ if (io) {
if (IoIFP(io)) {
PL_laststatval =
PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);
} else {
PL_laststatval = -1;
}
- }
}
}
io = MUTABLE_IO(SvRV(sv));
if (PL_op->op_type == OP_LSTAT)
goto do_fstat_warning_check;
- PL_laststype = OP_STAT;
- PL_statgv = (GV *)io;
- sv_setpvs(PL_statname, "");
goto do_fstat_have_io;
}
}
-plan tests => 111;
+plan tests => 112;
my $Perl = which_perl();
}
like $@, qr/^The stat preceding lstat\(\) wasn't an lstat at /,
'stat $ioref resets stat type';
+
+{
+ my @statbuf = stat STDOUT;
+ stat "test.pl";
+ my @lstatbuf = lstat *STDOUT{IO};
+ is "@lstatbuf", "@statbuf", 'lstat $ioref reverts to regular fstat';
+}
SKIP: {
skip "No lstat", 2 unless $Config{d_lstat};