Add new port: crx-elf
[deliverable/binutils-gdb.git] / bfd / cache.c
index 9146c05caca698febe0159986ad3665abcdc96d8..0d6529b209faef60df359535cae7646a39cc1710 100644 (file)
@@ -189,9 +189,9 @@ bfd *bfd_last_cache;
        otherwise, it has to perform the complicated lookup function.
 
   .#define bfd_cache_lookup(x) \
-  .    ((x)==bfd_last_cache? \
-  .      (FILE*) (bfd_last_cache->iostream): \
-  .       bfd_cache_lookup_worker(x))
+  .    ((x) == bfd_last_cache ? \
+  .      (FILE *) (bfd_last_cache->iostream): \
+  .       bfd_cache_lookup_worker (x))
 
  */
 
@@ -336,9 +336,40 @@ bfd_cache_close (bfd *abfd)
   if (abfd->iovec != &cache_iovec)
     return TRUE;
 
+  if (abfd->iostream == NULL)
+    /* Previously closed.  */
+    return TRUE;
+
   return bfd_cache_delete (abfd);
 }
 
+/*
+FUNCTION
+       bfd_cache_close_all
+
+SYNOPSIS
+       bfd_boolean bfd_cache_close_all (void);
+
+DESCRIPTION
+       Remove all BFDs from the cache. If the attached file is open,
+       then close it too.
+
+RETURNS
+       <<FALSE>> is returned if closing one of the file fails, <<TRUE>> is
+       returned if all is well.
+*/
+
+bfd_boolean
+bfd_cache_close_all ()
+{
+  bfd_boolean ret = TRUE;
+
+  while (bfd_last_cache != NULL)
+    ret &= bfd_cache_close (bfd_last_cache);
+
+  return ret;
+}
+
 /*
 INTERNAL_FUNCTION
        bfd_open_file
@@ -434,7 +465,8 @@ DESCRIPTION
        quick answer.  Find a file descriptor for @var{abfd}.  If
        necessary, it open it.  If there are already more than
        <<BFD_CACHE_MAX_OPEN>> files open, it tries to close one first, to
-       avoid running out of file descriptors.
+       avoid running out of file descriptors.  It will abort rather than
+       returning NULL if it is unable to (re)open the @var{abfd}.
 */
 
 FILE *
@@ -457,12 +489,10 @@ bfd_cache_lookup_worker (bfd *abfd)
     }
   else
     {
-      if (bfd_open_file (abfd) == NULL)
-       return NULL;
-      if (abfd->where != (unsigned long) abfd->where)
-       return NULL;
-      if (real_fseek ((FILE *) abfd->iostream, abfd->where, SEEK_SET) != 0)
-       return NULL;
+      if (bfd_open_file (abfd) == NULL
+         || abfd->where != (unsigned long) abfd->where
+         || real_fseek ((FILE *) abfd->iostream, abfd->where, SEEK_SET) != 0)
+       abort ();
     }
 
   return (FILE *) abfd->iostream;
This page took 0.024583 seconds and 4 git commands to generate.