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.

71 lines
1.5 KiB

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