package Cwd;
use strict;
use Exporter;
-use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
-$VERSION = '3.3.65';
+
+our $VERSION = '3.72';
my $xs_version = $VERSION;
$VERSION =~ tr/_//d;
-@ISA = qw/ Exporter /;
-@EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
+our @ISA = qw/ Exporter /;
+our @EXPORT = qw(cwd getcwd fastcwd fastgetcwd);
push @EXPORT, qw(getdcwd) if $^O eq 'MSWin32';
-@EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath);
+our @EXPORT_OK = qw(chdir abs_path fast_abs_path realpath fast_realpath);
# sys_cwd may keep the builtin command
# If loading the XS stuff doesn't work, we can fall back to pure perl
-if(! defined &getcwd && defined &DynaLoader::boot_DynaLoader) {
- eval {#eval is questionable since we are handling potential errors like
- #"Cwd object version 3.48 does not match bootstrap parameter 3.50
- #at lib/DynaLoader.pm line 216." by having this eval
- if ( $] >= 5.006 ) {
- require XSLoader;
- XSLoader::load( __PACKAGE__, $xs_version);
- } else {
- require DynaLoader;
- push @ISA, 'DynaLoader';
- __PACKAGE__->bootstrap( $xs_version );
- }
- };
+if(! defined &getcwd && defined &DynaLoader::boot_DynaLoader) { # skipped on miniperl
+ require XSLoader;
+ XSLoader::load( __PACKAGE__, $xs_version);
}
# Big nasty table of function aliases
realpath => 'fast_abs_path',
},
- epoc =>
- {
- cwd => '_epoc_cwd',
- getcwd => '_epoc_cwd',
- fastgetcwd => '_epoc_cwd',
- fastcwd => '_epoc_cwd',
- abs_path => 'fast_abs_path',
- },
-
- MacOS =>
- {
- getcwd => 'cwd',
- fastgetcwd => 'cwd',
- fastcwd => 'cwd',
- abs_path => 'fast_abs_path',
- },
-
amigaos =>
{
getcwd => '_backtick_pwd',
}
}
- # MacOS has some special magic to make `pwd` work.
- if( $os eq 'MacOS' || $found_pwd_cmd )
+ if( $found_pwd_cmd )
{
*cwd = \&_backtick_pwd;
}
if ($^O eq 'VMS') {
return $ENV{'PWD'} = $ENV{'DEFAULT'}
}
- elsif ($^O eq 'MacOS') {
- return $ENV{'PWD'} = cwd();
- }
elsif ($^O eq 'MSWin32') {
$ENV{'PWD'} = $newpwd;
return 1;
unless (@cst = stat( $start ))
{
- _carp("stat($start): $!");
- return '';
+ return undef;
}
unless (-d _) {
}
unless (@cst = stat($dotdots))
{
- _carp("stat($dotdots): $!");
+ my $e = $!;
closedir(PARENT);
- return '';
+ $! = $e;
+ return undef;
}
if ($pst[0] == $cst[0] && $pst[1] == $cst[1])
{
{
unless (defined ($dir = readdir(PARENT)))
{
- _carp("readdir($dotdots): $!");
closedir(PARENT);
- return '';
+ require Errno;
+ $! = Errno::ENOENT();
+ return undef;
}
$tst[0] = $pst[0]+1 unless (@tst = lstat("$dotdots/$dir"))
}
return $realpath;
}
-sub _epoc_cwd {
- return $ENV{'PWD'} = EPOC::getcwd();
-}
-
-
# Now that all the base-level functions are set up, alias the
# user-level functions to the right places
my $cwd = getcwd();
-Returns the current working directory.
+Returns the current working directory. On error returns C<undef>,
+with C<$!> set to indicate the error.
Exposes the POSIX function getcwd(3) or re-implements it if it's not
available.
Uses the same algorithm as getcwd(). Symbolic links and relative-path
components ("." and "..") are resolved to return the canonical
-pathname, just like realpath(3).
+pathname, just like realpath(3). On error returns C<undef>, with C<$!>
+set to indicate the error.
=item realpath