diff options
author | Steve Peters <steve@fisharerojo.org> | 2005-12-10 15:42:39 +0000 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2005-12-10 15:42:39 +0000 |
commit | fa52125f2139574b06ddadadf21b82bb93e6c77e (patch) | |
tree | d27b282b23bdcda8a935ed3c7e189ed8f9f50d26 /lib/Cwd.pm | |
parent | 00b6aa4170b1d4f8cd86fa0a48749312580e6806 (diff) | |
download | perl-fa52125f2139574b06ddadadf21b82bb93e6c77e.tar.gz |
Upgrade to PathTools-3.14_01
p4raw-id: //depot/perl@26318
Diffstat (limited to 'lib/Cwd.pm')
-rw-r--r-- | lib/Cwd.pm | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/Cwd.pm b/lib/Cwd.pm index d5a6db8ec2..462f262dc7 100644 --- a/lib/Cwd.pm +++ b/lib/Cwd.pm @@ -35,7 +35,8 @@ absolute path of the current working directory. Returns the current working directory. -Re-implements the getcwd(3) (or getwd(3)) functions in Perl. +Exposes the POSIX function getcwd(3) or re-implements it if it's not +available. =item cwd @@ -170,7 +171,7 @@ use strict; use Exporter; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); -$VERSION = '3.14'; +$VERSION = '3.14_01'; @ISA = qw/ Exporter /; @EXPORT = qw(cwd getcwd fastcwd fastgetcwd); @@ -302,6 +303,7 @@ foreach my $try ('/bin/pwd', last; } } +my $found_pwd_cmd = defined($pwd_cmd); unless ($pwd_cmd) { # Isn't this wrong? _backtick_pwd() will fail if somenone has # pwd in their path but it is not /bin/pwd or /usr/bin/pwd? @@ -334,9 +336,19 @@ unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) { # The pwd command is not available in some chroot(2)'ed environments my $sep = $Config::Config{path_sep} || ':'; my $os = $^O; # Protect $^O from tainting - if( $os eq 'MacOS' || (defined $ENV{PATH} && - $os ne 'MSWin32' && # no pwd on Windows - grep { -x "$_/pwd" } split($sep, $ENV{PATH})) ) + + + # Try again to find a pwd, this time searching the whole PATH. + if (defined $ENV{PATH} and $os ne 'MSWin32') { # no pwd on Windows + my @candidates = split($sep, $ENV{PATH}); + while (!$found_pwd_cmd and @candidates) { + my $candidate = shift @candidates; + $found_pwd_cmd = 1 if -x "$candidate/pwd"; + } + } + + # MacOS has some special magic to make `pwd` work. + if( $os eq 'MacOS' || $found_pwd_cmd ) { *cwd = \&_backtick_pwd; } @@ -349,16 +361,6 @@ unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) { # isn't redefined later (20001212 rspier) *fastgetcwd = \&cwd; -# By Brandon S. Allbery -# -# Usage: $cwd = getcwd(); - -sub getcwd -{ - abs_path('.'); -} - - # By John Bazik # # Usage: $cwd = &fastcwd; |