This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Replace references to PL_vtbl_{bm,fm} in the code with PL_vtbl_regexp.
[perl5.git] / lib / pwd.pl
index 7abcc1f..bd8123b 100644 (file)
@@ -1,14 +1,21 @@
+warn "Legacy library @{[(caller(0))[6]]} will be removed from the Perl core distribution in the next major release. Please install it from the CPAN distribution Perl4::CoreLibs. It is being used at @{[(caller)[1]]}, line @{[(caller)[2]]}.\n";
+
 ;# pwd.pl - keeps track of current working directory in PWD environment var
 ;#
-;# $Header: pwd.pl,v 3.0.1.2 91/01/11 18:09:24 lwall Locked $
+#
+# This library is no longer being maintained, and is included for backward
+# compatibility with Perl 4 programs which may require it.
+# This legacy library is deprecated and will be removed in a future
+# release of perl.
+#
+# In particular, this should not be used as an example of modern Perl
+# programming techniques.
+#
+# Suggested alternative: Cwd
+
+;# $RCSfile: pwd.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:11 $
 ;#
 ;# $Log:       pwd.pl,v $
-;# Revision 3.0.1.2  91/01/11  18:09:24  lwall
-;# patch42: some .pl files were missing their trailing 1;
-;# 
-;# Revision 3.0.1.1  90/08/09  04:01:24  lwall
-;# patch19: Initial revision
-;# 
 ;#
 ;# Usage:
 ;#     require "pwd.pl";
@@ -22,13 +29,25 @@ sub main'initpwd {
     if ($ENV{'PWD'}) {
        local($dd,$di) = stat('.');
        local($pd,$pi) = stat($ENV{'PWD'});
-       return if $di == $pi && $dd == $pd;
+       if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) {
+           chop($ENV{'PWD'} = `pwd`);
+       }
+    }
+    else {
+       chop($ENV{'PWD'} = `pwd`);
+    }
+    if ($ENV{'PWD'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|) {
+       local($pd,$pi) = stat($2);
+       local($dd,$di) = stat($1);
+       if (defined $pd and defined $dd and $di == $pi and $dd == $pd) {
+           $ENV{'PWD'}="$2$3";
+       }
     }
-    chop($ENV{'PWD'} = `pwd`);
 }
 
 sub main'chdir {
     local($newdir) = shift;
+    $newdir =~ s|/{2,}|/|g;
     if (chdir $newdir) {
        if ($newdir =~ m#^/#) {
            $ENV{'PWD'} = $newdir;