daily update
[deliverable/binutils-gdb.git] / bfd / cache.c
index 58eda916bbc9052263f6e40527d0d0c5dab5502c..e2524fbf15f06cca89031a6f972266bee5cb3f74 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
@@ -36,11 +36,14 @@ SECTION
        close, closes it and opens the one wanted, returning its file
        handle.
 
+SUBSECTION
+       Caching functions
 */
 
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
+#include "libiberty.h"
 
 static bfd_boolean bfd_cache_delete (bfd *);
 
@@ -176,7 +179,7 @@ DESCRIPTION
        determine when it can avoid a function call.
 */
 
-bfd *bfd_last_cache;
+bfd *bfd_last_cache = NULL;
 
 /*
   INTERNAL_FUNCTION
@@ -343,6 +346,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 +439,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;
This page took 0.024689 seconds and 4 git commands to generate.