structure of the previous file test (or stat operator) is used, saving
a system call. (This doesn't work with C<-t>, and you need to remember
that lstat() and C<-l> will leave values in the stat structure for the
-symbolic link, not the real file.) Example:
+symbolic link, not the real file.) (Also, if the stat buffer was filled by
+a C<lstat> call, C<-T> and C<-B> will reset it with the results of C<stat _>).
+Example:
print "Can do.\n" if -r $a || -w _ || -x _;
really_filename:
PL_statgv = Nullgv;
PL_laststatval = -1;
+ PL_laststype = OP_STAT;
sv_setpv(PL_statname, SvPV(sv, n_a));
if (!(fp = PerlIO_open(SvPVX(PL_statname), "r"))) {
if (ckWARN(WARN_NEWLINE) && strchr(SvPV(sv, n_a), '\n'))
flock STDIN, 8;
flock $a, 8;
- The stat preceding lstat() wasn't an lstat %s [pp_stat]
- lstat(STDIN);
-
warn(warn_nl, "stat"); [pp_stat]
-T on closed filehandle %s
EXPECT
Unsuccessful stat on filename containing newline at - line 3.
########
-# pp_sys.c [pp_stat]
-use Config;
-BEGIN {
- if ($^O eq 'd_lstat') {
- print <<EOM ;
-SKIPPED
-# lstat not present
-EOM
- exit ;
- }
-}
-use warnings 'io' ;
-lstat(STDIN) ;
-no warnings 'io' ;
-lstat(STDIN) ;
-EXPECT
-The stat preceding lstat() wasn't an lstat at - line 13.
-########
# pp_sys.c [pp_fttext]
use warnings qw(unopened closed) ;
close STDIN ;
use Config;
use File::Spec;
-plan tests => 69;
+plan tests => 74;
my $Perl = which_perl();
# bug id 20011101.069
my @r = \stat(".");
is(scalar @r, 13, 'stat returns full 13 elements');
+
+SKIP: {
+ skip "No lstat", 2 unless $Config{d_lstat};
+
+ stat $0;
+ eval { lstat _ };
+ ok( $@ =~ /^The stat preceding lstat\(\) wasn't an lstat/,
+ 'lstat _ croaks after stat' );
+ eval { -l _ };
+ ok( $@ =~ /^The stat preceding -l _ wasn't an lstat/,
+ '-l _ croaks after stat' );
+
+ eval { lstat STDIN };
+ ok( $@ =~ /^The stat preceding lstat\(\) wasn't an lstat/,
+ 'lstat FILEHANDLE croaks' );
+
+ # bug id 20020124.004
+ # If we have d_lstat, we should have symlink()
+ my $linkname = 'dolzero';
+ symlink $0, $linkname or die "# Can't symlink $0: $!";
+ lstat $linkname;
+ -T _;
+ eval { lstat _ };
+ ok( $@ =~ /^The stat preceding lstat\(\) wasn't an lstat/,
+ 'lstat croaks after -T _' );
+ eval { -l _ };
+ ok( $@ =~ /^The stat preceding -l _ wasn't an lstat/,
+ '-l _ croaks after -T _' );
+ unlink $linkname or print "# unlink $linkname failed: $!\n";
+}