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.

46 lines
850 B

  1. # Open in their package.
  2. sub cacheout'open {
  3. open($_[0], $_[1]);
  4. }
  5. # Close as well
  6. sub cacheout'close {
  7. close($_[0]);
  8. }
  9. # But only this sub name is visible to them.
  10. sub cacheout {
  11. package cacheout;
  12. ($file) = @_;
  13. if (!$isopen{$file}) {
  14. if (++$numopen > $maxopen) {
  15. local(@lru) = sort {$isopen{$a} <=> $isopen{$b};} keys(%isopen);
  16. splice(@lru, $maxopen / 3);
  17. $numopen -= @lru;
  18. for (@lru) { &close($_); delete $isopen{$_}; }
  19. }
  20. &open($file, ($saw{$file}++ ? '>>' : '>') . $file)
  21. || die "Can't create $file: $!\n";
  22. }
  23. $isopen{$file} = ++$seq;
  24. }
  25. package cacheout;
  26. $seq = 0;
  27. $numopen = 0;
  28. if (open(PARAM,'/usr/include/sys/param.h')) {
  29. local($_, $.);
  30. while (<PARAM>) {
  31. $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/;
  32. }
  33. close PARAM;
  34. }
  35. $maxopen = 16 unless $maxopen;
  36. 1;