Warn under -w if lstat(FH) is attempted.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 21 Apr 2000 10:43:46 +0000 (04:43 -0600)
committerJarkko Hietaniemi <jhi@iki.fi>
Fri, 4 Aug 2000 19:02:08 +0000 (19:02 +0000)
Subject: [ID 20000421.003] perlfunc says you can lstat a file handle but you cannot
Message-Id: <200004211643.e3LGhkX24720@xerxes.courtesan.com>

p4raw-id: //depot/perl@6524

pod/perldiag.pod
pod/perlfunc.pod
pp_sys.c
t/pragma/warn/pp_sys

index 930b9de..cf6cd19 100644 (file)
@@ -1767,6 +1767,12 @@ effective uids or gids failed.
 to check the return value of your socket() call?  See
 L<perlfunc/listen>.
 
+=item lstat() on filehandle %s
+
+(W io) You tried to do a lstat on a filehandle.  What did you mean
+by that?  lstat() makes sense only on filenames.  (Perl did a fstat()
+instead on the filehandle.)
+
 =item Lvalue subs returning %s not implemented yet
 
 (F) Due to limitations in the current implementation, array and hash
index 09cd437..f6a7327 100644 (file)
@@ -2424,8 +2424,6 @@ divided by the natural log of N.  For example:
 
 See also L</exp> for the inverse operation.
 
-=item lstat FILEHANDLE
-
 =item lstat EXPR
 
 =item lstat
index 9a264c8..b4cbb55 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2497,6 +2497,9 @@ PP(pp_stat)
 
     if (PL_op->op_flags & OPf_REF) {
        tmpgv = cGVOP_gv;
+       if (PL_op->op_type == OP_LSTAT && ckWARN(WARN_IO))
+           Perl_warner(aTHX_ WARN_IO,
+                       "lstat() on filehandle %s", GvENAME(tmpgv));
       do_fstat:
        if (tmpgv != PL_defgv) {
            PL_laststype = OP_STAT;
index 1666b6a..eb17d68 100644 (file)
@@ -72,6 +72,9 @@
     close STDIN;
     flock STDIN, 8;
 
+  lstat() on filehandle %s                     [pp_stat]
+    lstat(STDIN);
+
   warn(warn_nl, "stat");                       [pp_stat]
 
   -T on unopened filehandle %s
@@ -325,6 +328,24 @@ 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
+lstat() on filehandle STDIN at - line 13.
+########
 # pp_sys.c [pp_fttext]
 use warnings 'unopened' ;
 close STDIN ;