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