Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.0 KiB

  1. # By John Bazik
  2. #
  3. # This library is no longer being maintained, and is included for backward
  4. # compatibility with Perl 4 programs which may require it.
  5. #
  6. # In particular, this should not be used as an example of modern Perl
  7. # programming techniques.
  8. #
  9. # Suggested alternative: Cwd
  10. #
  11. # Usage: $cwd = &fastcwd;
  12. #
  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.
  15. sub fastcwd {
  16. local($odev, $oino, $cdev, $cino, $tdev, $tino);
  17. local(@path, $path);
  18. local(*DIR);
  19. ($cdev, $cino) = stat('.');
  20. for (;;) {
  21. ($odev, $oino) = ($cdev, $cino);
  22. chdir('..');
  23. ($cdev, $cino) = stat('.');
  24. last if $odev == $cdev && $oino == $cino;
  25. opendir(DIR, '.');
  26. for (;;) {
  27. $_ = readdir(DIR);
  28. next if $_ eq '.';
  29. next if $_ eq '..';
  30. last unless $_;
  31. ($tdev, $tino) = lstat($_);
  32. last unless $tdev != $odev || $tino != $oino;
  33. }
  34. closedir(DIR);
  35. unshift(@path, $_);
  36. }
  37. chdir($path = '/' . join('/', @path));
  38. $path;
  39. }
  40. 1;