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.

67 lines
1.5 KiB

  1. ;# pwd.pl - keeps track of current working directory in PWD environment var
  2. ;#
  3. #
  4. # This library is no longer being maintained, and is included for backward
  5. # compatibility with Perl 4 programs which may require it.
  6. #
  7. # In particular, this should not be used as an example of modern Perl
  8. # programming techniques.
  9. #
  10. # Suggested alternative: Cwd
  11. #
  12. ;# $RCSfile: pwd.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:11 $
  13. ;#
  14. ;# $Log: pwd.pl,v $
  15. ;#
  16. ;# Usage:
  17. ;# require "pwd.pl";
  18. ;# &initpwd;
  19. ;# ...
  20. ;# &chdir($newdir);
  21. package pwd;
  22. sub main'initpwd {
  23. if ($ENV{'PWD'}) {
  24. local($dd,$di) = stat('.');
  25. local($pd,$pi) = stat($ENV{'PWD'});
  26. if (!defined $dd or !defined $pd or $di != $pi or $dd != $pd) {
  27. chop($ENV{'PWD'} = `pwd`);
  28. }
  29. }
  30. else {
  31. chop($ENV{'PWD'} = `pwd`);
  32. }
  33. if ($ENV{'PWD'} =~ m|(/[^/]+(/[^/]+/[^/]+))(.*)|) {
  34. local($pd,$pi) = stat($2);
  35. local($dd,$di) = stat($1);
  36. if (defined $pd and defined $dd and $di == $pi and $dd == $pd) {
  37. $ENV{'PWD'}="$2$3";
  38. }
  39. }
  40. }
  41. sub main'chdir {
  42. local($newdir) = shift;
  43. $newdir =~ s|/{2,}|/|g;
  44. if (chdir $newdir) {
  45. if ($newdir =~ m#^/#) {
  46. $ENV{'PWD'} = $newdir;
  47. }
  48. else {
  49. local(@curdir) = split(m#/#,$ENV{'PWD'});
  50. @curdir = '' unless @curdir;
  51. foreach $component (split(m#/#, $newdir)) {
  52. next if $component eq '.';
  53. pop(@curdir),next if $component eq '..';
  54. push(@curdir,$component);
  55. }
  56. $ENV{'PWD'} = join('/',@curdir) || '/';
  57. }
  58. }
  59. else {
  60. 0;
  61. }
  62. }
  63. 1;