Commit | Line | Data |
39c3038c |
1 | # Open in their package. |
2 | |
3 | sub cacheout'open { |
4 | open($_[0], $_[1]); |
5 | } |
6 | |
7 | # But only this sub name is visible to them. |
8 | |
9 | sub cacheout { |
10 | package cacheout; |
11 | |
12 | ($file) = @_; |
39c3038c |
13 | if (!$isopen{$file}) { |
14 | if (++$numopen > $maxopen) { |
55204971 |
15 | local(@lru) = sort {$isopen{$a} <=> $isopen{$b};} keys(%isopen); |
39c3038c |
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 | |
26 | package cacheout; |
27 | |
28 | $seq = 0; |
29 | $numopen = 0; |
30 | |
31 | if (open(PARAM,'/usr/include/sys/param.h')) { |
32 | local($.); |
33 | while (<PARAM>) { |
55204971 |
34 | $maxopen = $1 - 4 if /^\s*#\s*define\s+NOFILE\s+(\d+)/; |
39c3038c |
35 | } |
36 | close PARAM; |
37 | } |
38 | $maxopen = 16 unless $maxopen; |
39 | |
40 | 1; |