bfd/
[binutils-gdb.git] / bfd / cache.c
index da16409d857c1daa98ff81550049dfbcd9f5aaf9..b3091659984c4c91d31ded8a49443b97f1fe76f1 100644 (file)
@@ -1,5 +1,5 @@
 /* BFD library -- caching of file descriptors.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001
+   Copyright 1990, 1991, 1992, 1993, 1994, 1996, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Hacked by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
@@ -40,10 +40,7 @@ SECTION
 #include "sysdep.h"
 #include "libbfd.h"
 
-static void insert PARAMS ((bfd *));
-static void snip PARAMS ((bfd *));
-static boolean close_one PARAMS ((void));
-static boolean bfd_cache_delete PARAMS ((bfd *));
+static bfd_boolean bfd_cache_delete (bfd *);
 
 /*
 INTERNAL_FUNCTION
@@ -95,9 +92,8 @@ bfd *bfd_last_cache;
 
 /* Insert a BFD into the cache.  */
 
-static INLINE void
-insert (abfd)
-     bfd *abfd;
+static void
+insert (bfd *abfd)
 {
   if (bfd_last_cache == NULL)
     {
@@ -116,9 +112,8 @@ insert (abfd)
 
 /* Remove a BFD from the cache.  */
 
-static INLINE void
-snip (abfd)
-     bfd *abfd;
+static void
+snip (bfd *abfd)
 {
   abfd->lru_prev->lru_next = abfd->lru_next;
   abfd->lru_next->lru_prev = abfd->lru_prev;
@@ -133,8 +128,8 @@ snip (abfd)
 /* We need to open a new file, and the cache is full.  Find the least
    recently used cacheable BFD and close it.  */
 
-static boolean
-close_one ()
+static bfd_boolean
+close_one (void)
 {
   register bfd *kill;
 
@@ -157,7 +152,7 @@ close_one ()
   if (kill == NULL)
     {
       /* There are no open cacheable BFD's.  */
-      return true;
+      return TRUE;
     }
 
   kill->where = ftell ((FILE *) kill->iostream);
@@ -167,17 +162,16 @@ close_one ()
 
 /* Close a BFD and remove it from the cache.  */
 
-static boolean
-bfd_cache_delete (abfd)
-     bfd *abfd;
+static bfd_boolean
+bfd_cache_delete (bfd *abfd)
 {
-  boolean ret;
+  bfd_boolean ret;
 
   if (fclose ((FILE *) abfd->iostream) == 0)
-    ret = true;
+    ret = TRUE;
   else
     {
-      ret = false;
+      ret = FALSE;
       bfd_set_error (bfd_error_system_call);
     }
 
@@ -194,25 +188,24 @@ INTERNAL_FUNCTION
        bfd_cache_init
 
 SYNOPSIS
-       boolean bfd_cache_init (bfd *abfd);
+       bfd_boolean bfd_cache_init (bfd *abfd);
 
 DESCRIPTION
        Add a newly opened BFD to the cache.
 */
 
-boolean
-bfd_cache_init (abfd)
-     bfd *abfd;
+bfd_boolean
+bfd_cache_init (bfd *abfd)
 {
   BFD_ASSERT (abfd->iostream != NULL);
   if (open_files >= BFD_CACHE_MAX_OPEN)
     {
       if (! close_one ())
-       return false;
+       return FALSE;
     }
   insert (abfd);
   ++open_files;
-  return true;
+  return TRUE;
 }
 
 /*
@@ -220,24 +213,23 @@ INTERNAL_FUNCTION
        bfd_cache_close
 
 SYNOPSIS
-       boolean bfd_cache_close (bfd *abfd);
+       bfd_boolean bfd_cache_close (bfd *abfd);
 
 DESCRIPTION
        Remove the BFD @var{abfd} from the cache. If the attached file is open,
        then close it too.
 
 RETURNS
-       <<false>> is returned if closing the file fails, <<true>> is
+       <<FALSE>> is returned if closing the file fails, <<TRUE>> is
        returned if all is well.
 */
 
-boolean
-bfd_cache_close (abfd)
-     bfd *abfd;
+bfd_boolean
+bfd_cache_close (bfd *abfd)
 {
   if (abfd->iostream == NULL
       || (abfd->flags & BFD_IN_MEMORY) != 0)
-    return true;
+    return TRUE;
 
   return bfd_cache_delete (abfd);
 }
@@ -247,7 +239,7 @@ INTERNAL_FUNCTION
        bfd_open_file
 
 SYNOPSIS
-       FILE* bfd_open_file(bfd *abfd);
+       FILE* bfd_open_file (bfd *abfd);
 
 DESCRIPTION
        Call the OS to open a file for @var{abfd}.  Return the <<FILE *>>
@@ -258,10 +250,9 @@ DESCRIPTION
 */
 
 FILE *
-bfd_open_file (abfd)
-     bfd *abfd;
+bfd_open_file (bfd *abfd)
 {
-  abfd->cacheable = true;      /* Allow it to be closed later.  */
+  abfd->cacheable = TRUE;      /* Allow it to be closed later.  */
 
   if (open_files >= BFD_CACHE_MAX_OPEN)
     {
@@ -277,7 +268,7 @@ bfd_open_file (abfd)
       break;
     case both_direction:
     case write_direction:
-      if (abfd->opened_once == true)
+      if (abfd->opened_once)
        {
          abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_RUB);
          if (abfd->iostream == NULL)
@@ -312,7 +303,7 @@ bfd_open_file (abfd)
            unlink (abfd->filename);
 #endif
          abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_WUB);
-         abfd->opened_once = true;
+         abfd->opened_once = TRUE;
        }
       break;
     }
@@ -331,7 +322,7 @@ INTERNAL_FUNCTION
        bfd_cache_lookup_worker
 
 SYNOPSIS
-       FILE *bfd_cache_lookup_worker(bfd *abfd);
+       FILE *bfd_cache_lookup_worker (bfd *abfd);
 
 DESCRIPTION
        Called when the macro <<bfd_cache_lookup>> fails to find a
@@ -342,8 +333,7 @@ DESCRIPTION
 */
 
 FILE *
-bfd_cache_lookup_worker (abfd)
-     bfd *abfd;
+bfd_cache_lookup_worker (bfd *abfd)
 {
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     abort ();
@@ -364,7 +354,9 @@ bfd_cache_lookup_worker (abfd)
     {
       if (bfd_open_file (abfd) == NULL)
        return NULL;
-      if (fseek ((FILE *) abfd->iostream, abfd->where, SEEK_SET) != 0)
+      if (abfd->where != (unsigned long) abfd->where)
+       return NULL;
+      if (fseek ((FILE *) abfd->iostream, (long) abfd->where, SEEK_SET) != 0)
        return NULL;
     }