diff options
-rw-r--r-- | pod/perlfunc.pod | 4 | ||||
-rw-r--r-- | pp_sys.c | 1 | ||||
-rw-r--r-- | t/lib/warnings/pp_sys | 21 | ||||
-rwxr-xr-x | t/op/stat.t | 32 |
4 files changed, 35 insertions, 23 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 8efe7cc182..ea196c27c0 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -350,7 +350,9 @@ the special filehandle consisting of a solitary underline, then the stat 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 _; @@ -3311,6 +3311,7 @@ PP(pp_fttext) 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')) diff --git a/t/lib/warnings/pp_sys b/t/lib/warnings/pp_sys index e30637b0d4..4b9c8b1a96 100644 --- a/t/lib/warnings/pp_sys +++ b/t/lib/warnings/pp_sys @@ -83,9 +83,6 @@ 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 @@ -347,24 +344,6 @@ stat "abc\ndef"; 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 ; diff --git a/t/op/stat.t b/t/op/stat.t index c3bbe8362d..2f387198f0 100755 --- a/t/op/stat.t +++ b/t/op/stat.t @@ -9,7 +9,7 @@ BEGIN { use Config; use File::Spec; -plan tests => 69; +plan tests => 74; my $Perl = which_perl(); @@ -376,3 +376,33 @@ unlink $tmpfile or print "# unlink failed: $!\n"; # 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"; +} |