* elf-hppa.h (elf_hppa_reloc_final_type): Handle R_PARISC_GPREL64,
[deliverable/binutils-gdb.git] / bfd / bfdio.c
index a7505270199c7e972bf0bca0440c18e64eeb04d3..d8aa1de99926761fa015bab24c49798563cec37b 100644 (file)
@@ -1,33 +1,33 @@
 /* Low-level I/O routines for BFDs.
 
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+   Free Software Foundation, Inc.
 
    Written by Cygnus Support.
 
-This file is part of BFD, the Binary File Descriptor library.
+   This file is part of BFD, the Binary File Descriptor library.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   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.  */
+   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., 51 Franklin Street - Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 #include "sysdep.h"
-
+#include <limits.h>
 #include "bfd.h"
 #include "libbfd.h"
 
-#include <limits.h>
-
 #ifndef S_IXUSR
 #define S_IXUSR 0100    /* Execute by owner.  */
 #endif
@@ -62,6 +62,16 @@ real_fseek (FILE *file, file_ptr offset, int whence)
 #endif
 }
 
+FILE *
+real_fopen (const char *filename, const char *modes)
+{
+#if defined (HAVE_FOPEN64)
+  return fopen64 (filename, modes);
+#else
+  return fopen (filename, modes);
+#endif
+}
+
 /*
 INTERNAL_DEFINITION
        struct bfd_iovec
@@ -105,6 +115,15 @@ bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
 {
   size_t nread;
 
+  /* If this is an archive element, don't read past the end of
+     this element.  */
+  if (abfd->arelt_data != NULL)
+    {
+      size_t maxbytes = ((struct areltdata *) abfd->arelt_data)->parsed_size;
+      if (size > maxbytes)
+       size = maxbytes;
+    }
+
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     {
       struct bfd_in_memory *bim;
@@ -155,8 +174,8 @@ bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
          newsize = (bim->size + 127) & ~(bfd_size_type) 127;
          if (newsize > oldsize)
            {
-             bim->buffer = bfd_realloc (bim->buffer, newsize);
-             if (bim->buffer == 0)
+             bim->buffer = bfd_realloc_or_free (bim->buffer, newsize);
+             if (bim->buffer == NULL)
                {
                  bim->size = 0;
                  return 0;
@@ -279,8 +298,8 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
              newsize = (bim->size + 127) & ~(bfd_size_type) 127;
              if (newsize > oldsize)
                {
-                 bim->buffer = bfd_realloc (bim->buffer, newsize);
-                 if (bim->buffer == 0)
+                 bim->buffer = bfd_realloc_or_free (bim->buffer, newsize);
+                 if (bim->buffer == NULL)
                    {
                      bim->size = 0;
                      return -1;
@@ -299,20 +318,6 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
 
   if (abfd->format != bfd_archive && abfd->my_archive == 0)
     {
-#if 0
-      /* Explanation for this code: I'm only about 95+% sure that the above
-        conditions are sufficient and that all i/o calls are properly
-        adjusting the `where' field.  So this is sort of an `assert'
-        that the `where' field is correct.  If we can go a while without
-        tripping the abort, we can probably safely disable this code,
-        so that the real optimizations happen.  */
-      file_ptr where_am_i_now;
-      where_am_i_now = real_ftell (bfd_cache_lookup (abfd));
-      if (abfd->my_archive)
-       where_am_i_now -= abfd->origin;
-      if (where_am_i_now != abfd->where)
-       abort ();
-#endif
       if (direction == SEEK_SET && (bfd_vma) position == abfd->where)
        return 0;
     }
@@ -404,7 +409,7 @@ FUNCTION
        bfd_get_size
 
 SYNOPSIS
-       long bfd_get_size (bfd *abfd);
+       file_ptr bfd_get_size (bfd *abfd);
 
 DESCRIPTION
        Return the file size (as read from file system) for the file
@@ -432,7 +437,7 @@ DESCRIPTION
        size reasonable?".
 */
 
-long
+file_ptr
 bfd_get_size (bfd *abfd)
 {
   struct stat buf;
This page took 0.027876 seconds and 4 git commands to generate.