X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCwd.pm;h=b6f0a2ad2e83f1954317a509855ab2b77e9093e1;hb=71fbae4b4b3f337a0c2643cc859be9d389fd2e98;hp=c00dbc5f690b3866aca5ff0da29f0c3870b40b4c;hpb=9596c75cf25afc08d6274085fe826f0f50fd6c98;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/Cwd.pm b/lib/Cwd.pm index c00dbc5..b6f0a2a 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.10'; +$VERSION = '3.15'; @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; } @@ -353,12 +365,11 @@ unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) { # # Usage: $cwd = getcwd(); -sub getcwd +sub _perl_getcwd { abs_path('.'); } - # By John Bazik # # Usage: $cwd = &fastcwd; @@ -702,6 +713,7 @@ if (exists $METHOD_MAP{$^O}) { # In case the XS version doesn't load. *abs_path = \&_perl_abs_path unless defined &abs_path; +*getcwd = \&_perl_getcwd unless defined &getcwd; # added function alias for those of us more # used to the libc function. --tchrist 27-Jan-00