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.

62 lines
1.1 KiB

  1. # By Brandon S. Allbery
  2. #
  3. # Usage: $cwd = &getcwd;
  4. sub getcwd
  5. {
  6. local($dotdots, $cwd, @pst, @cst, $dir, @tst);
  7. unless (@cst = stat('.'))
  8. {
  9. warn "stat(.): $!";
  10. return '';
  11. }
  12. $cwd = '';
  13. do
  14. {
  15. $dotdots .= '/' if $dotdots;
  16. $dotdots .= '..';
  17. @pst = @cst;
  18. unless (opendir(getcwd'PARENT, $dotdots)) #'))
  19. {
  20. warn "opendir($dotdots): $!";
  21. return '';
  22. }
  23. unless (@cst = stat($dotdots))
  24. {
  25. warn "stat($dotdots): $!";
  26. closedir(getcwd'PARENT); #');
  27. return '';
  28. }
  29. if ($pst[$[] == $cst[$[] && $pst[$[ + 1] == $cst[$[ + 1])
  30. {
  31. $dir = '';
  32. }
  33. else
  34. {
  35. do
  36. {
  37. unless (defined ($dir = readdir(getcwd'PARENT))) #'))
  38. {
  39. warn "readdir($dotdots): $!";
  40. closedir(getcwd'PARENT); #');
  41. return '';
  42. }
  43. unless (@tst = lstat("$dotdots/$dir"))
  44. {
  45. # warn "lstat($dotdots/$dir): $!";
  46. # closedir(getcwd'PARENT); #');
  47. # return '';
  48. }
  49. }
  50. while ($dir eq '.' || $dir eq '..' || $tst[$[] != $pst[$[] ||
  51. $tst[$[ + 1] != $pst[$[ + 1]);
  52. }
  53. $cwd = "$dir/$cwd";
  54. closedir(getcwd'PARENT); #');
  55. } while ($dir ne '');
  56. chop($cwd);
  57. $cwd;
  58. }
  59. 1;