1N/A# By John Bazik
1N/A#
1N/A# This library is no longer being maintained, and is included for backward
1N/A# compatibility with Perl 4 programs which may require it.
1N/A#
1N/A# In particular, this should not be used as an example of modern Perl
1N/A# programming techniques.
1N/A#
1N/A# Suggested alternative: Cwd
1N/A#
1N/A# Usage: $cwd = &fastcwd;
1N/A#
1N/A# This is a faster version of getcwd. It's also more dangerous because
1N/A# you might chdir out of a directory that you can't chdir back into.
1N/A
1N/Asub fastcwd {
1N/A local($odev, $oino, $cdev, $cino, $tdev, $tino);
1N/A local(@path, $path);
1N/A local(*DIR);
1N/A
1N/A ($cdev, $cino) = stat('.');
1N/A for (;;) {
1N/A ($odev, $oino) = ($cdev, $cino);
1N/A chdir('..');
1N/A ($cdev, $cino) = stat('.');
1N/A last if $odev == $cdev && $oino == $cino;
1N/A opendir(DIR, '.');
1N/A for (;;) {
1N/A $_ = readdir(DIR);
1N/A next if $_ eq '.';
1N/A next if $_ eq '..';
1N/A
1N/A last unless $_;
1N/A ($tdev, $tino) = lstat($_);
1N/A last unless $tdev != $odev || $tino != $oino;
1N/A }
1N/A closedir(DIR);
1N/A unshift(@path, $_);
1N/A }
1N/A chdir($path = '/' . join('/', @path));
1N/A $path;
1N/A}
1N/A1;