This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
disable cwd_enoent test
[perl5.git] / dist / PathTools / Cwd.pm
index e9f9d61..d6c65e9 100644 (file)
@@ -1,16 +1,16 @@
 package Cwd;
 use strict;
 use Exporter;
-use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
 
-$VERSION = '3.64';
+
+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
 
@@ -77,19 +77,9 @@ sub _vms_efs {
 
 
 # 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
@@ -145,23 +135,6 @@ my %METHOD_MAP =
     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',
@@ -254,8 +227,7 @@ unless ($METHOD_MAP{$^O}{cwd} or defined &cwd) {
        }
     }
 
-    # MacOS has some special magic to make `pwd` work.
-    if( $os eq 'MacOS' || $found_pwd_cmd )
+    if( $found_pwd_cmd )
     {
        *cwd = \&_backtick_pwd;
     }
@@ -384,9 +356,6 @@ sub chdir {
     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;
@@ -418,8 +387,7 @@ sub _perl_abs_path
 
     unless (@cst = stat( $start ))
     {
-       _carp("stat($start): $!");
-       return '';
+       return undef;
     }
 
     unless (-d _) {
@@ -459,9 +427,10 @@ sub _perl_abs_path
        }
        unless (@cst = stat($dotdots))
        {
-           _carp("stat($dotdots): $!");
+           my $e = $!;
            closedir(PARENT);
-           return '';
+           $! = $e;
+           return undef;
        }
        if ($pst[0] == $cst[0] && $pst[1] == $cst[1])
        {
@@ -473,9 +442,10 @@ sub _perl_abs_path
            {
                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"))
            }
@@ -676,11 +646,6 @@ sub _qnx_abs_path {
     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
 
@@ -737,7 +702,8 @@ absolute path of the current working directory.
 
     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.
@@ -800,7 +766,8 @@ given they'll use the current working directory.
 
 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