* config/tc-xtensa.h (resource_table): Change units to unsigned chars.
[deliverable/binutils-gdb.git] / bfd / cache.c
index 0586061286a75a1633bfe715109898e86ca8819a..163fa2bb2666af88f3513cce9e6d9ebbfe884609 100644 (file)
@@ -19,7 +19,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 /*
 SECTION
@@ -41,6 +41,7 @@ SECTION
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
+#include "libiberty.h"
 
 static bfd_boolean bfd_cache_delete (bfd *);
 
@@ -189,9 +190,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))
 
  */
 
@@ -343,6 +344,33 @@ bfd_cache_close (bfd *abfd)
   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
@@ -409,7 +437,7 @@ bfd_open_file (bfd *abfd)
          struct stat s;
 
          if (stat (abfd->filename, &s) == 0 && s.st_size != 0)
-           unlink (abfd->filename);
+           unlink_if_ordinary (abfd->filename);
 #endif
          abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_WUB);
          abfd->opened_once = TRUE;
@@ -438,7 +466,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 *
@@ -461,12 +490,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.024541 seconds and 4 git commands to generate.