summaryrefslogtreecommitdiff
path: root/lib/pwd.pl
diff options
context:
space:
mode:
authorLarry Wall <lwall@jpl-devvax.jpl.nasa.gov>1990-08-08 17:07:07 +0000
committerLarry Wall <lwall@jpl-devvax.jpl.nasa.gov>1990-08-08 17:07:07 +0000
commit00bf170e31343ccc4fac7a63f6a3acf5e76c3616 (patch)
tree64f2ca6ce7de08a6bae7fb4d11de65e8d49396be /lib/pwd.pl
parent33b78306b8a6f9a33cf09697c8c3167d2111ea12 (diff)
downloadperl-00bf170e31343ccc4fac7a63f6a3acf5e76c3616.tar.gz
perl 3.0 patch #25 patch #19, continued
See patch #19.
Diffstat (limited to 'lib/pwd.pl')
-rw-r--r--lib/pwd.pl48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/pwd.pl b/lib/pwd.pl
new file mode 100644
index 0000000000..c141e9888e
--- /dev/null
+++ b/lib/pwd.pl
@@ -0,0 +1,48 @@
+;# pwd.pl - keeps track of current working directory in PWD environment var
+;#
+;# $Header: pwd.pl,v 3.0.1.1 90/08/09 04:01:24 lwall Locked $
+;#
+;# $Log: pwd.pl,v $
+;# Revision 3.0.1.1 90/08/09 04:01:24 lwall
+;# patch19: Initial revision
+;#
+;#
+;# Usage:
+;# require "pwd.pl";
+;# &initpwd;
+;# ...
+;# &chdir($newdir);
+
+package pwd;
+
+sub main'initpwd {
+ if ($ENV{'PWD'}) {
+ local($dd,$di) = stat('.');
+ local($pd,$pi) = stat($ENV{'PWD'});
+ return if $di == $pi && $dd == $pd;
+ }
+ chop($ENV{'PWD'} = `pwd`);
+}
+
+sub main'chdir {
+ local($newdir) = shift;
+ if (chdir $newdir) {
+ if ($newdir =~ m#^/#) {
+ $ENV{'PWD'} = $newdir;
+ }
+ else {
+ local(@curdir) = split(m#/#,$ENV{'PWD'});
+ @curdir = '' unless @curdir;
+ foreach $component (split(m#/#, $newdir)) {
+ next if $component eq '.';
+ pop(@curdir),next if $component eq '..';
+ push(@curdir,$component);
+ }
+ $ENV{'PWD'} = join('/',@curdir) || '/';
+ }
+ }
+ else {
+ 0;
+ }
+}
+