From: Rafael Garcia-Suarez Date: Thu, 31 Jan 2002 14:37:52 +0000 (+0100) Subject: forbid -l _ after -T _ X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5c9aa243fcc1509167c9708b74c0f9451983e63b;p=p5sagit%2Fp5-mst-13.2.git forbid -l _ after -T _ Message-ID: <20020131143752.A1452@rafael> p4raw-id: //depot/perl@14506 --- diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 8efe7cc..ea196c2 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 call, C<-T> and C<-B> will reset it with the results of C). +Example: print "Can do.\n" if -r $a || -w _ || -x _; diff --git a/pp_sys.c b/pp_sys.c index 3fb4be9..d540535 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -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 e30637b..4b9c8b1 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 < 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"; +}