develooper Front page | perl.perl5.porters | Postings from March 2001

Re: [PATCH] CwdXS, Take 2

Thread Previous
From:
Benjamin Sugars
Date:
March 29, 2001 11:49
Subject:
Re: [PATCH] CwdXS, Take 2
Message ID:
Pine.LNX.4.21.0103291450520.1944-100000@marmot.rim.canoe.ca
On Thu, 29 Mar 2001, I, Benjamin Sugars, wrote:

> This patch is take 2 of implementing Cwd in XS.  It replaces the patch I
> sent last week.  This patch resolves most of the issues related to the
> last patch, so I think it's ready for inclusion.  Let me know.

Oops.  I forgot to include the part that patches Cwd.pm.  Here it is.

Cheers,
-Ben

-- 
signer: can't create ~/.sig: Link has been severed

--- lib/Cwd.pm.orig	Thu Mar 29 15:39:01 2001
+++ lib/Cwd.pm	Thu Mar 29 15:42:38 2001
@@ -121,52 +121,15 @@
     abs_path('.');
 }
 
-# By John Bazik
-#
-# Usage: $cwd = &fastcwd;
-#
-# This is a faster version of getcwd.  It's also more dangerous because
-# you might chdir out of a directory that you can't chdir back into.
+# Now a callout to the Cwd::CwdXS XSUB.
     
-sub fastcwd {
-    my($odev, $oino, $cdev, $cino, $tdev, $tino);
-    my(@path, $path);
-    local(*DIR);
-
-    my($orig_cdev, $orig_cino) = stat('.');
-    ($cdev, $cino) = ($orig_cdev, $orig_cino);
-    for (;;) {
-	my $direntry;
-	($odev, $oino) = ($cdev, $cino);
-	CORE::chdir('..') || return undef;
-	($cdev, $cino) = stat('.');
-	last if $odev == $cdev && $oino == $cino;
-	opendir(DIR, '.') || return undef;
-	for (;;) {
-	    $direntry = readdir(DIR);
-	    last unless defined $direntry;
-	    next if $direntry eq '.';
-	    next if $direntry eq '..';
-
-	    ($tdev, $tino) = lstat($direntry);
-	    last unless $tdev != $odev || $tino != $oino;
-	}
-	closedir(DIR);
-	return undef unless defined $direntry; # should never happen
-	unshift(@path, $direntry);
+sub fastcwd
+{
+    require Cwd::CwdXS;
+    no warnings;
+    *fastcwd = \&Cwd::CwdXS::fastcwd;
+    goto &Cwd::CwdXS::fastcwd;
     }
-    $path = '/' . join('/', @path);
-    if ($^O eq 'apollo') { $path = "/".$path; }
-    # At this point $path may be tainted (if tainting) and chdir would fail.
-    # To be more useful we untaint it then check that we landed where we started.
-    $path = $1 if $path =~ /^(.*)\z/s;	# untaint
-    CORE::chdir($path) || return undef;
-    ($cdev, $cino) = stat('.');
-    die "Unstable directory path, current directory changed unexpectedly"
-	if $cdev != $orig_cdev || $cino != $orig_cino;
-    $path;
-}
-
 
 # Keeps track of current working directory in PWD environment var
 # Usage:


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About