Source code of Windows XP (NT5)
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.

35 lines
754 B

  1. # By John Bazik
  2. #
  3. # Usage: $cwd = &fastcwd;
  4. #
  5. # This is a faster version of getcwd. It's also more dangerous because
  6. # you might chdir out of a directory that you can't chdir back into.
  7. sub fastcwd {
  8. local($odev, $oino, $cdev, $cino, $tdev, $tino);
  9. local(@path, $path);
  10. local(*DIR);
  11. ($cdev, $cino) = stat('.');
  12. for (;;) {
  13. ($odev, $oino) = ($cdev, $cino);
  14. chdir('..');
  15. ($cdev, $cino) = stat('.');
  16. last if $odev == $cdev && $oino == $cino;
  17. opendir(DIR, '.');
  18. for (;;) {
  19. $_ = readdir(DIR);
  20. next if $_ eq '.';
  21. next if $_ eq '..';
  22. last unless $_;
  23. ($tdev, $tino) = lstat($_);
  24. last unless $tdev != $odev || $tino != $oino;
  25. }
  26. closedir(DIR);
  27. unshift(@path, $_);
  28. }
  29. chdir($path = '/' . join('/', @path));
  30. $path;
  31. }
  32. 1;