1@section File caching
2The file caching mechanism is embedded within BFD and allows
3the application to open as many BFDs as it wants without
4regard to the underlying operating system's file descriptor
5limit (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
9the required BFD is open. If not, then it chooses a file to
10close, closes it and opens the one wanted, returning its file
11handle.
12
13@findex BFD_CACHE_MAX_OPEN macro
14@subsubsection @code{BFD_CACHE_MAX_OPEN macro}
15@strong{Description}@*
16The maximum number of files which the cache will keep open at
17one time.
18@example
19#define BFD_CACHE_MAX_OPEN 10
20@end example
21
22@findex bfd_last_cache
23@subsubsection @code{bfd_last_cache}
24@strong{Synopsis}
25@example
26extern bfd *bfd_last_cache;
27@end example
28@strong{Description}@*
29Zero, or a pointer to the topmost BFD on the chain.  This is
30used by the @code{bfd_cache_lookup} macro in @file{libbfd.h} to
31determine when it can avoid a function call.
32
33@findex bfd_cache_lookup
34@subsubsection @code{bfd_cache_lookup}
35@strong{Description}@*
36Check to see if the required BFD is the same as the last one
37looked up. If so, then it can use the stream in the BFD with
38impunity, since it can't have changed since the last lookup;
39otherwise, it has to perform the complicated lookup function.
40@example
41#define bfd_cache_lookup(x) \
42    ((x)==bfd_last_cache? \
43      (FILE*) (bfd_last_cache->iostream): \
44       bfd_cache_lookup_worker(x))
45@end example
46
47@findex bfd_cache_init
48@subsubsection @code{bfd_cache_init}
49@strong{Synopsis}
50@example
51bfd_boolean bfd_cache_init (bfd *abfd);
52@end example
53@strong{Description}@*
54Add a newly opened BFD to the cache.
55
56@findex bfd_cache_close
57@subsubsection @code{bfd_cache_close}
58@strong{Synopsis}
59@example
60bfd_boolean bfd_cache_close (bfd *abfd);
61@end example
62@strong{Description}@*
63Remove the BFD @var{abfd} from the cache. If the attached file is open,
64then close it too.
65
66@strong{Returns}@*
67@code{FALSE} is returned if closing the file fails, @code{TRUE} is
68returned if all is well.
69
70@findex bfd_open_file
71@subsubsection @code{bfd_open_file}
72@strong{Synopsis}
73@example
74FILE* bfd_open_file (bfd *abfd);
75@end example
76@strong{Description}@*
77Call 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
79BFD so that future accesses know the file is open. If the @code{FILE *}
80returned is @code{NULL}, then it won't have been put in the
81cache, so it won't have to be removed from it.
82
83@findex bfd_cache_lookup_worker
84@subsubsection @code{bfd_cache_lookup_worker}
85@strong{Synopsis}
86@example
87FILE *bfd_cache_lookup_worker (bfd *abfd);
88@end example
89@strong{Description}@*
90Called when the macro @code{bfd_cache_lookup} fails to find a
91quick answer.  Find a file descriptor for @var{abfd}.  If
92necessary, it open it.  If there are already more than
93@code{BFD_CACHE_MAX_OPEN} files open, it tries to close one first, to
94avoid running out of file descriptors.
95
96