Lines Matching refs:abfd
48 static FILE *_bfd_open_file_unlocked (bfd *abfd);
127 insert (bfd *abfd)
131 abfd->lru_next = abfd;
132 abfd->lru_prev = abfd;
136 abfd->lru_next = bfd_last_cache;
137 abfd->lru_prev = bfd_last_cache->lru_prev;
138 abfd->lru_prev->lru_next = abfd;
139 abfd->lru_next->lru_prev = abfd;
141 bfd_last_cache = abfd;
147 snip (bfd *abfd)
149 abfd->lru_prev->lru_next = abfd->lru_next;
150 abfd->lru_next->lru_prev = abfd->lru_prev;
151 if (abfd == bfd_last_cache)
153 bfd_last_cache = abfd->lru_next;
154 if (abfd == bfd_last_cache)
162 bfd_cache_delete (bfd *abfd)
166 if (fclose ((FILE *) abfd->iostream) == 0)
174 snip (abfd);
176 abfd->iostream = NULL;
179 abfd->flags |= BFD_CLOSED_BY_CACHE;
180 abfd->last_io = bfd_io_force;
230 /* A helper function that returns true if ABFD can possibly be cached
234 possibly_cached (bfd *abfd)
236 if ((abfd->flags & BFD_IN_MEMORY) != 0)
238 if (abfd->my_archive != NULL
239 && !bfd_is_thin_archive (abfd->my_archive))
245 quick answer. Find a file descriptor for @var{abfd}. If
249 if it is unable to (re)open the @var{abfd}. */
252 bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag)
254 if (!possibly_cached (abfd))
259 if (abfd->in_format_matches)
261 if (abfd->iostream == NULL)
263 return (FILE *) abfd->iostream;
266 if (abfd->iostream != NULL)
269 if (abfd != bfd_last_cache)
271 snip (abfd);
272 insert (abfd);
274 return (FILE *) abfd->iostream;
280 if (_bfd_open_file_unlocked (abfd) == NULL)
283 && _bfd_real_fseek ((FILE *) abfd->iostream,
284 abfd->where, SEEK_SET) != 0
288 return (FILE *) abfd->iostream;
292 abfd, bfd_errmsg (bfd_get_error ()));
297 cache_btell (struct bfd *abfd)
301 FILE *f = bfd_cache_lookup (abfd, CACHE_NO_OPEN);
306 return abfd->where;
315 cache_bseek (struct bfd *abfd, file_ptr offset, int whence)
319 FILE *f = bfd_cache_lookup (abfd, whence != SEEK_CUR ? CACHE_NO_SEEK : CACHE_NORMAL);
374 cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
381 f = bfd_cache_lookup (abfd, CACHE_NORMAL);
423 cache_bwrite (struct bfd *abfd, const void *from, file_ptr nbytes)
428 FILE *f = bfd_cache_lookup (abfd, CACHE_NORMAL);
449 cache_bclose (struct bfd *abfd)
452 return bfd_cache_close (abfd) - 1;
456 cache_bflush (struct bfd *abfd)
461 FILE *f = bfd_cache_lookup (abfd, CACHE_NO_OPEN);
478 cache_bstat (struct bfd *abfd, struct stat *sb)
483 FILE *f = bfd_cache_lookup (abfd, CACHE_NO_SEEK_ERROR);
499 cache_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED,
512 if ((abfd->flags & BFD_IN_MEMORY) != 0)
522 f = bfd_cache_lookup (abfd, CACHE_NO_SEEK_ERROR);
557 _bfd_cache_init_unlocked (bfd *abfd)
559 BFD_ASSERT (abfd->iostream != NULL);
565 abfd->iovec = &cache_iovec;
566 insert (abfd);
567 abfd->flags &= ~BFD_CLOSED_BY_CACHE;
577 bool bfd_cache_init (bfd *abfd);
584 bfd_cache_init (bfd *abfd)
588 bool result = _bfd_cache_init_unlocked (abfd);
595 _bfd_cache_close_unlocked (bfd *abfd)
598 if (abfd->iovec != &cache_iovec)
601 if (abfd->iostream == NULL)
607 return bfd_cache_delete (abfd);
615 bool bfd_cache_close (bfd *abfd);
618 Remove the BFD @var{abfd} from the cache. If the attached file is open,
626 bfd_cache_close (bfd *abfd)
630 bool result = _bfd_cache_close_unlocked (abfd);
682 bool bfd_cache_set_uncloseable (bfd *abfd, bool value, bool *old);
685 Internal function to mark ABFD as either closeable or not.
695 bfd_cache_set_uncloseable (bfd *abfd, bool value, bool *old)
702 *old = abfd->in_format_matches;
706 if (value != abfd->in_format_matches
707 && abfd->iovec == &cache_iovec
708 && possibly_cached (abfd))
714 FILE *f = bfd_cache_lookup (abfd, CACHE_NORMAL);
718 snip (abfd);
723 insert (abfd);
726 abfd->in_format_matches = value;
752 _bfd_open_file_unlocked (bfd *abfd)
754 abfd->cacheable = true; /* Allow it to be closed later. */
762 switch (abfd->direction)
766 abfd->iostream = _bfd_real_fopen (bfd_get_filename (abfd), FOPEN_RB);
770 if (abfd->opened_once)
772 abfd->iostream = _bfd_real_fopen (bfd_get_filename (abfd),
774 if (abfd->iostream == NULL)
775 abfd->iostream = _bfd_real_fopen (bfd_get_filename (abfd),
803 if (stat (bfd_get_filename (abfd), &s) == 0 && s.st_size != 0)
804 unlink_if_ordinary (bfd_get_filename (abfd));
806 abfd->iostream = _bfd_real_fopen (bfd_get_filename (abfd),
808 abfd->opened_once = true;
813 if (abfd->iostream == NULL)
817 if (! _bfd_cache_init_unlocked (abfd))
821 return (FILE *) abfd->iostream;
829 FILE* bfd_open_file (bfd *abfd);
832 Call the OS to open a file for @var{abfd}. Return the <<FILE *>>
840 bfd_open_file (bfd *abfd)
844 FILE *result = _bfd_open_file_unlocked (abfd);