home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / config / fastcwd.pl < prev    next >
Encoding:
Perl Script  |  1998-04-08  |  1.5 KB  |  54 lines

  1. #!perl5
  2. #
  3. # The contents of this file are subject to the Netscape Public License
  4. # Version 1.0 (the "NPL"); you may not use this file except in
  5. # compliance with the NPL.  You may obtain a copy of the NPL at
  6. # http://www.mozilla.org/NPL/
  7. #
  8. # Software distributed under the NPL is distributed on an "AS IS" basis,
  9. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10. # for the specific language governing rights and limitations under the
  11. # NPL.
  12. #
  13. # The Initial Developer of this code under the NPL is Netscape
  14. # Communications Corporation.  Portions created by Netscape are
  15. # Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16. # Reserved.
  17. #
  18. # By John Bazik
  19. #
  20. # Usage: $cwd = &fastcwd;
  21. #
  22. # This is a faster version of getcwd.  It's also more dangerous because
  23. # you might chdir out of a directory that you can't chdir back into.
  24.  
  25. sub fastcwd {
  26.     local($odev, $oino, $cdev, $cino, $tdev, $tino);
  27.     local(@path, $path);
  28.     local(*DIR);
  29.  
  30.     ($cdev, $cino) = stat('.');
  31.     for (;;) {
  32.         ($odev, $oino) = ($cdev, $cino);
  33.         chdir('..');
  34.         ($cdev, $cino) = stat('.');
  35.         last if $odev == $cdev && $oino == $cino;
  36.         opendir(DIR, '.');
  37.         for (;;) {
  38.             $_ = readdir(DIR);
  39.             next if $_ eq '.';
  40.             next if $_ eq '..';
  41.  
  42.             last unless $_;
  43.             ($tdev, $tino) = lstat($_);
  44.             last unless $tdev != $odev || $tino != $oino;
  45.         }
  46.         closedir(DIR);
  47.         unshift(@path, $_);
  48.     }
  49.     chdir($path = '/' . join('/', @path));
  50.     $path;
  51. }
  52. 1;
  53.