(int64e_type): Fix definition.
[deliverable/binutils-gdb.git] / bfd / cache.c
index d0d3f231b1941364edaf0a18ce90291444c14931..6be253cffb39021e20fa4d180beb199aa1e5676b 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD library -- caching of file descriptors.
-   Copyright (C) 1990-1991 Free Software Foundation, Inc.
+   Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
    Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
 This file is part of BFD, the Binary File Descriptor library.
@@ -35,8 +35,6 @@ SECTION
 
 */
 
-/* $Id$ */
-
 #include "bfd.h"
 #include "sysdep.h"
 #include "libbfd.h"
@@ -46,7 +44,7 @@ INTERNAL_FUNCTION
        BFD_CACHE_MAX_OPEN macro
 
 DESCRIPTION
-       The maxiumum number of files which the cache will keep open at
+       The maximum number of files which the cache will keep open at
        one time.
 
 .#define BFD_CACHE_MAX_OPEN 10
@@ -92,7 +90,7 @@ bfd *bfd_last_cache;
  *
  */
 
-static void bfd_cache_delete();
+static boolean EXFUN(bfd_cache_delete,(bfd *));
 
 
 static void
@@ -110,7 +108,7 @@ DEFUN_VOID(close_one)
     }
 
     kill->where = ftell((FILE *)(kill->iostream));
-    bfd_cache_delete(kill);
+    (void) bfd_cache_delete(kill);
 }
 
 /* Cuts the BFD abfd out of the chain in the cache */
@@ -123,15 +121,24 @@ DEFUN(snip,(abfd),
   if (cache_sentinel == abfd) cache_sentinel = (bfd *)NULL;
 }
 
-static void
+static boolean
 DEFUN(bfd_cache_delete,(abfd),
       bfd *abfd)
 {
-  fclose ((FILE *)(abfd->iostream));
+  boolean ret;
+
+  if (fclose ((FILE *)(abfd->iostream)) == 0)
+    ret = true;
+  else
+    {
+      ret = false;
+      bfd_error = system_call_error;
+    }
   snip (abfd);
   abfd->iostream = NULL;
   open_files--;
   bfd_last_cache = 0;
+  return ret;
 }
   
 static bfd *
@@ -182,16 +189,24 @@ DESCRIPTION
        then close it too.
 
 SYNOPSIS
-       void bfd_cache_close (bfd *);
+       boolean bfd_cache_close (bfd *);
+
+RETURNS
+       <<false>> is returned if closing the file fails, <<true>> is
+       returned if all is well.
 */
-void
+boolean
 DEFUN(bfd_cache_close,(abfd),
       bfd *abfd)
 {
   /* If this file is open then remove from the chain */
   if (abfd->iostream) 
     {
-      bfd_cache_delete(abfd);
+      return bfd_cache_delete(abfd);
+    }
+  else
+    {
+      return true;
     }
 }
 
@@ -215,28 +230,31 @@ DEFUN(bfd_open_file, (abfd),
       bfd *abfd)
 {
   abfd->cacheable = true;      /* Allow it to be closed later. */
+
   if(open_files >= BFD_CACHE_MAX_OPEN) {
     close_one();
   }
+
   switch (abfd->direction) {
   case read_direction:
   case no_direction:
-    abfd->iostream = (char *) fopen(abfd->filename, "rb");
+    abfd->iostream = (char *) fopen(abfd->filename, FOPEN_RB);
     break;
   case both_direction:
   case write_direction:
     if (abfd->opened_once == true) {
-      abfd->iostream = (char *) fopen(abfd->filename, "r+b");
+      abfd->iostream = (char *) fopen(abfd->filename, FOPEN_RUB);
       if (!abfd->iostream) {
-       abfd->iostream = (char *) fopen(abfd->filename, "w+b");
+       abfd->iostream = (char *) fopen(abfd->filename, FOPEN_WUB);
       }
     } else {
       /*open for creat */
-      abfd->iostream = (char *) fopen(abfd->filename, "wb");
+      abfd->iostream = (char *) fopen(abfd->filename, FOPEN_WB);
       abfd->opened_once = true;
     }
     break;
   }
+
   if (abfd->iostream) {
     open_files++;
     bfd_cache_init (abfd);
This page took 0.0246 seconds and 4 git commands to generate.