Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / fastcwd.pl
blobecd87c8a0350aa445117b8c23203be88b048195d
1 # By John Bazik
3 # This library is no longer being maintained, and is included for backward
4 # compatibility with Perl 4 programs which may require it.
6 # In particular, this should not be used as an example of modern Perl
7 # programming techniques.
9 # Suggested alternative: Cwd
11 # Usage: $cwd = &fastcwd;
13 # This is a faster version of getcwd. It's also more dangerous because
14 # you might chdir out of a directory that you can't chdir back into.
16 sub fastcwd {
17 local($odev, $oino, $cdev, $cino, $tdev, $tino);
18 local(@path, $path);
19 local(*DIR);
21 ($cdev, $cino) = stat('.');
22 for (;;) {
23 ($odev, $oino) = ($cdev, $cino);
24 chdir('..');
25 ($cdev, $cino) = stat('.');
26 last if $odev == $cdev && $oino == $cino;
27 opendir(DIR, '.');
28 for (;;) {
29 $_ = readdir(DIR);
30 next if $_ eq '.';
31 next if $_ eq '..';
33 last unless $_;
34 ($tdev, $tino) = lstat($_);
35 last unless $tdev != $odev || $tino != $oino;
37 closedir(DIR);
38 unshift(@path, $_);
40 chdir($path = '/' . join('/', @path));
41 $path;