OSDN Git Service

include/
[pf3gnuchains/pf3gnuchains3x.git] / bfd / opncls.c
index 3291cba..ffbf65d 100644 (file)
@@ -1,6 +1,6 @@
 /* opncls.c -- open and close a BFD.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
-   2001, 2002, 2003
+   2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    Written by Cygnus Support.
@@ -598,7 +598,7 @@ bfd_close (bfd *abfd)
   if (!(abfd->flags & BFD_IN_MEMORY))
     ret = abfd->iovec->bclose (abfd);
   else
-    ret = 0;
+    ret = TRUE;
 
   /* If the file was open for writing and is now executable,
      make it so.  */
@@ -813,7 +813,7 @@ INTERNAL_FUNCTION
        bfd_alloc
 
 SYNOPSIS
-       void *bfd_alloc (bfd *abfd, size_t wanted);
+       void *bfd_alloc (bfd *abfd, bfd_size_type wanted);
 
 DESCRIPTION
        Allocate a block of @var{wanted} bytes of memory attached to
@@ -859,9 +859,9 @@ bfd_release (bfd *abfd, void *block)
 }
 
 
-/* 
-   GNU Extension: separate debug-info files 
-   
+/*
+   GNU Extension: separate debug-info files
+
    The idea here is that a special section called .gnu_debuglink might be
    embedded in a binary file, which indicates that some *other* file
    contains the real debugging information. This special section contains a
@@ -889,7 +889,7 @@ DESCRIPTION
 
 RETURNS
        Return the updated CRC32 value.
-*/     
+*/
 
 unsigned long
 bfd_calc_gnu_debuglink_crc32 (unsigned long crc,
@@ -976,12 +976,11 @@ DESCRIPTION
 static char *
 get_debug_link_info (bfd *abfd, unsigned long *crc32_out)
 {
-  asection * sect;
-  bfd_size_type debuglink_size;
+  asection *sect;
   unsigned long crc32;
-  char * contents;
+  bfd_byte *contents;
   int crc_offset;
-  bfd_boolean ret;
+  char *name;
 
   BFD_ASSERT (abfd);
   BFD_ASSERT (crc32_out);
@@ -991,27 +990,22 @@ get_debug_link_info (bfd *abfd, unsigned long *crc32_out)
   if (sect == NULL)
     return NULL;
 
-  debuglink_size = bfd_section_size (abfd, sect);  
-
-  contents = malloc (debuglink_size);
-  if (contents == NULL)
-    return NULL;
-
-  ret = bfd_get_section_contents (abfd, sect, contents, 0, debuglink_size);
-  if (! ret)
+  if (!bfd_malloc_and_get_section (abfd, sect, &contents))
     {
-      free (contents);
+      if (contents != NULL)
+       free (contents);
       return NULL;
     }
 
   /* Crc value is stored after the filename, aligned up to 4 bytes.  */
-  crc_offset = strlen (contents) + 1;
+  name = (char *) contents;
+  crc_offset = strlen (name) + 1;
   crc_offset = (crc_offset + 3) & ~3;
 
   crc32 = bfd_get_32 (abfd, contents + crc_offset);
 
   *crc32_out = crc32;
-  return contents;
+  return name;
 }
 
 /*
@@ -1030,7 +1024,7 @@ DESCRIPTION
 static bfd_boolean
 separate_debug_file_exists (const char *name, const unsigned long crc)
 {
-  static char buffer [8 * 1024];
+  static unsigned char buffer [8 * 1024];
   unsigned long file_crc = 0;
   int fd;
   bfd_size_type count;
@@ -1100,19 +1094,19 @@ find_separate_debug_file (bfd *abfd, const char *debug_file_directory)
       return NULL;
     }
   BFD_ASSERT (strlen (dir) != 0);
-  
+
   /* Strip off filename part.  */
   for (i = strlen (dir) - 1; i >= 0; i--)
     if (IS_DIR_SEPARATOR (dir[i]))
       break;
 
   dir[i + 1] = '\0';
-  BFD_ASSERT (dir[i] == '/' || dir[0] == '\0')
+  BFD_ASSERT (dir[i] == '/' || dir[0] == '\0');
 
   debugfile = malloc (strlen (debug_file_directory) + 1
                      + strlen (dir)
                      + strlen (".debug/")
-                     + strlen (basename) 
+                     + strlen (basename)
                      + 1);
   if (debugfile == NULL)
     {
@@ -1197,10 +1191,6 @@ RETURNS
 char *
 bfd_follow_gnu_debuglink (bfd *abfd, const char *dir)
 {
-#if 0 /* Disabled until DEBUGDIR can be defined by configure.in.  */
-  if (dir == NULL)
-    dir = DEBUGDIR;
-#endif
   return find_separate_debug_file (abfd, dir);
 }
 
@@ -1219,7 +1209,7 @@ DESCRIPTION
 
 RETURNS
        A pointer to the new section is returned if all is ok.  Otherwise <<NULL>> is
-       returned and bfd_error is set.  
+       returned and bfd_error is set.
 */
 
 asection *
@@ -1236,7 +1226,7 @@ bfd_create_gnu_debuglink_section (bfd *abfd, const char *filename)
 
   /* Strip off any path components in filename.  */
   filename = lbasename (filename);
-  
+
   sect = bfd_get_section_by_name (abfd, GNU_DEBUGLINK);
   if (sect)
     {
@@ -1254,7 +1244,7 @@ bfd_create_gnu_debuglink_section (bfd *abfd, const char *filename)
     /* XXX Should we delete the section from the bfd ?  */
     return NULL;
 
-  
+
   debuglink_size = strlen (filename) + 1;
   debuglink_size += 3;
   debuglink_size &= ~3;
@@ -1263,7 +1253,7 @@ bfd_create_gnu_debuglink_section (bfd *abfd, const char *filename)
   if (! bfd_set_section_size (abfd, sect, debuglink_size))
     /* XXX Should we delete the section from the bfd ?  */
     return NULL;
-  
+
   return sect;
 }
 
@@ -1285,7 +1275,7 @@ DESCRIPTION
 
 RETURNS
        <<TRUE>> is returned if all is ok.  Otherwise <<FALSE>> is returned
-       and bfd_error is set.  
+       and bfd_error is set.
 */
 
 bfd_boolean
@@ -1298,7 +1288,7 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd,
   char * contents;
   bfd_size_type crc_offset;
   FILE * handle;
-  static char buffer[8 * 1024];
+  static unsigned char buffer[8 * 1024];
   size_t count;
 
   if (abfd == NULL || sect == NULL || filename == NULL)
@@ -1328,7 +1318,7 @@ bfd_fill_in_gnu_debuglink_section (bfd *abfd,
   /* Strip off any path components in filename,
      now that we no longer need them.  */
   filename = lbasename (filename);
-  
+
   debuglink_size = strlen (filename) + 1;
   debuglink_size += 3;
   debuglink_size &= ~3;