2 The file caching mechanism is embedded within BFD and allows
3 the application to open as many BFDs as it wants without
4 regard to the underlying operating system's file descriptor
5 limit (often as low as 20 open files). The module in
6 @code{cache.c} maintains a least recently used list of
7 @code{BFD_CACHE_MAX_OPEN} files, and exports the name
8 @code{bfd_cache_lookup}, which runs around and makes sure that
9 the required BFD is open. If not, then it chooses a file to
10 close, closes it and opens the one wanted, returning its file
13 @findex BFD_CACHE_MAX_OPEN macro
14 @subsubsection @code{BFD_CACHE_MAX_OPEN macro}
15 @strong{Description}@*
16 The maximum number of files which the cache will keep open at
19 #define BFD_CACHE_MAX_OPEN 10
22 @findex bfd_last_cache
23 @subsubsection @code{bfd_last_cache}
26 extern bfd *bfd_last_cache;
28 @strong{Description}@*
29 Zero, or a pointer to the topmost BFD on the chain. This is
30 used by the @code{bfd_cache_lookup} macro in @file{libbfd.h} to
31 determine when it can avoid a function call.
33 @findex bfd_cache_lookup
34 @subsubsection @code{bfd_cache_lookup}
35 @strong{Description}@*
36 Check to see if the required BFD is the same as the last one
37 looked up. If so, then it can use the stream in the BFD with
38 impunity, since it can't have changed since the last lookup;
39 otherwise, it has to perform the complicated lookup function.
41 #define bfd_cache_lookup(x) \
42 ((x)==bfd_last_cache? \
43 (FILE*) (bfd_last_cache->iostream): \
44 bfd_cache_lookup_worker(x))
47 @findex bfd_cache_init
48 @subsubsection @code{bfd_cache_init}
51 bfd_boolean bfd_cache_init (bfd *abfd);
53 @strong{Description}@*
54 Add a newly opened BFD to the cache.
56 @findex bfd_cache_close
57 @subsubsection @code{bfd_cache_close}
60 bfd_boolean bfd_cache_close (bfd *abfd);
62 @strong{Description}@*
63 Remove the BFD @var{abfd} from the cache. If the attached file is open,
67 @code{FALSE} is returned if closing the file fails, @code{TRUE} is
68 returned if all is well.
71 @subsubsection @code{bfd_open_file}
74 FILE* bfd_open_file (bfd *abfd);
76 @strong{Description}@*
77 Call the OS to open a file for @var{abfd}. Return the @code{FILE *}
78 (possibly @code{NULL}) that results from this operation. Set up the
79 BFD so that future accesses know the file is open. If the @code{FILE *}
80 returned is @code{NULL}, then it won't have been put in the
81 cache, so it won't have to be removed from it.
83 @findex bfd_cache_lookup_worker
84 @subsubsection @code{bfd_cache_lookup_worker}
87 FILE *bfd_cache_lookup_worker (bfd *abfd);
89 @strong{Description}@*
90 Called when the macro @code{bfd_cache_lookup} fails to find a
91 quick answer. Find a file descriptor for @var{abfd}. If
92 necessary, it open it. If there are already more than
93 @code{BFD_CACHE_MAX_OPEN} files open, it tries to close one first, to
94 avoid running out of file descriptors.