use Carp;
-our $VERSION = '2.03';
+our $VERSION = '2.04';
use base qw/ Exporter /;
our @EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
# Since some ports may predefine cwd internally (e.g., NT)
# we take care not to override an existing definition for cwd().
-*cwd = \&_backtick_pwd unless defined &cwd;
+unless(defined &cwd) {
+ # The pwd command is not available in some chroot(2)'ed environments
+ if($^O eq 'MacOS' || grep { -x "$_/pwd" } split(':', $ENV{PATH})) {
+ *cwd = \&_backtick_pwd;
+ }
+ else {
+ *cwd = \&getcwd;
+ }
+}
+# set a reasonable (and very safe) default for fastgetcwd, in case it
+# isn't redefined later (20001212 rspier)
+*fastgetcwd = \&cwd;
# By Brandon S. Allbery
#
}
sub chdir {
- my $newdir = shift || ''; # allow for no arg (chdir to HOME dir)
+ my $newdir = @_ ? shift : ''; # allow for no arg (chdir to HOME dir)
$newdir =~ s|///*|/|g unless $^O eq 'MSWin32';
chdir_init() unless $chdir_init;
return 0 unless CORE::chdir $newdir;
if ($^O eq 'VMS') {
return $ENV{'PWD'} = $ENV{'DEFAULT'}
}
+ elsif ($^O eq 'MacOS') {
+ return $ENV{'PWD'} = cwd();
+ }
elsif ($^O eq 'MSWin32') {
$ENV{'PWD'} = Win32::GetFullPathName($newdir);
return 1;
sub fast_abs_path {
my $cwd = getcwd();
- my $path = shift || '.';
+ my $path = @_ ? shift : '.';
CORE::chdir($path) || croak "Cannot chdir to $path:$!";
my $realpath = getcwd();
CORE::chdir($cwd) || croak "Cannot chdir back to $cwd:$!";
}
sub _qnx_abs_path {
- my $path = shift || '.';
+ my $path = @_ ? shift : '.';
my $realpath=`/usr/bin/fullpath -t $path`;
chop $realpath;
return $realpath;
}
+sub _epoc_cwd {
+ $ENV{'PWD'} = EPOC::getcwd();
+ return $ENV{'PWD'};
+}
+
{
no warnings; # assignments trigger 'subroutine redefined' warning
*fastcwd = \&cwd;
*abs_path = \&fast_abs_path;
}
+ elsif ($^O eq 'epoc') {
+ *cwd = \&_epoc_cwd;
+ *getcwd = \&_epoc_cwd;
+ *fastgetcwd = \&_epoc_cwd;
+ *fastcwd = \&_epoc_cwd;
+ *abs_path = \&fast_abs_path;
+ }
+ elsif ($^O eq 'MacOS') {
+ *getcwd = \&cwd;
+ *fastgetcwd = \&cwd;
+ *fastcwd = \&cwd;
+ *abs_path = \&fast_abs_path;
+ }
}
# package main; eval join('',<DATA>) || die $@; # quick test