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.

55 lines
1.1 KiB

  1. #
  2. # This library is no longer being maintained, and is included for backward
  3. # compatibility with Perl 4 programs which may require it.
  4. #
  5. # In particular, this should not be used as an example of modern Perl
  6. # programming techniques.
  7. #
  8. # Suggested alternative: FileCache
  9. # Open in their package.
  10. sub cacheout'open {
  11. open($_[0], $_[1]);
  12. }
  13. # Close as well
  14. sub cacheout'close {
  15. close($_[0]);
  16. }
  17. # But only this sub name is visible to them.
  18. sub cacheout {
  19. package cacheout;
  20. ($file) = @_;
  21. if (!$isopen{$file}) {
  22. if (++$numopen > $maxopen) {
  23. local(@lru) = sort {$isopen{$a} <=> $isopen{$b};} keys(%isopen);
  24. splice(@lru, $maxopen / 3);
  25. $numopen -= @lru;
  26. for (@lru) { &close($_); delete $isopen{$_}; }
  27. }
  28. &open($file, ($saw{$file}++ ? '>>' : '>') . $file)
  29. || die "Can't create $file: $!\n";
  30. }
  31. $isopen{$file} = ++$seq;
  32. }
  33. package cacheout;
  34. $seq = 0;
  35. $numopen = 0;
  36. if (open(PARAM,'/usr/include/sys/param.h')) {
  37. local($_, $.);
  38. while (<PARAM>) {
  39. $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/;
  40. }
  41. close PARAM;
  42. }
  43. $maxopen = 16 unless $maxopen;
  44. 1;