summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/binutils/bfd/bfdio.c
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/binutils/bfd/bfdio.c')
-rw-r--r--gnu/usr.bin/binutils/bfd/bfdio.c94
1 files changed, 50 insertions, 44 deletions
diff --git a/gnu/usr.bin/binutils/bfd/bfdio.c b/gnu/usr.bin/binutils/bfd/bfdio.c
index 32293162367..a90cb33ea5f 100644
--- a/gnu/usr.bin/binutils/bfd/bfdio.c
+++ b/gnu/usr.bin/binutils/bfd/bfdio.c
@@ -1,6 +1,8 @@
/* Low-level I/O routines for BFDs.
- Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002 Free Software Foundation, Inc.
+
+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+ 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
@@ -36,6 +38,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#define S_IXOTH 0001 /* Execute by others. */
#endif
+file_ptr
+real_ftell (FILE *file)
+{
+#if defined (HAVE_FTELLO64)
+ return ftello64 (file);
+#elif defined (HAVE_FTELLO)
+ return ftello (file);
+#else
+ return ftell (file);
+#endif
+}
+
+int
+real_fseek (FILE *file, file_ptr offset, int whence)
+{
+#if defined (HAVE_FSEEKO64)
+ return fseeko64 (file, offset, whence);
+#elif defined (HAVE_FSEEKO)
+ return fseeko (file, offset, whence);
+#else
+ return fseek (file, offset, whence);
+#endif
+}
+
/* Note that archive entries don't have streams; they share their parent's.
This allows someone to play with the iostream behind BFD's back.
@@ -43,13 +69,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
contents (0 for non-archive elements). For archive entries this is the
first octet in the file, NOT the beginning of the archive header. */
-static size_t real_read PARAMS ((PTR where, size_t a, size_t b, FILE *file));
static size_t
-real_read (where, a, b, file)
- PTR where;
- size_t a;
- size_t b;
- FILE *file;
+real_read (void *where, size_t a, size_t b, FILE *file)
{
/* FIXME - this looks like an optimization, but it's really to cover
up for a feature of some OSs (not solaris - sigh) that
@@ -76,10 +97,7 @@ real_read (where, a, b, file)
/* Return value is amount read. */
bfd_size_type
-bfd_bread (ptr, size, abfd)
- PTR ptr;
- bfd_size_type size;
- bfd *abfd;
+bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
{
size_t nread;
@@ -88,7 +106,7 @@ bfd_bread (ptr, size, abfd)
struct bfd_in_memory *bim;
bfd_size_type get;
- bim = (struct bfd_in_memory *) abfd->iostream;
+ bim = abfd->iostream;
get = size;
if (abfd->where + get > bim->size)
{
@@ -126,16 +144,13 @@ bfd_bread (ptr, size, abfd)
}
bfd_size_type
-bfd_bwrite (ptr, size, abfd)
- const PTR ptr;
- bfd_size_type size;
- bfd *abfd;
+bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
{
size_t nwrote;
if ((abfd->flags & BFD_IN_MEMORY) != 0)
{
- struct bfd_in_memory *bim = (struct bfd_in_memory *) (abfd->iostream);
+ struct bfd_in_memory *bim = abfd->iostream;
size = (size_t) size;
if (abfd->where + size > bim->size)
{
@@ -147,7 +162,7 @@ bfd_bwrite (ptr, size, abfd)
newsize = (bim->size + 127) & ~(bfd_size_type) 127;
if (newsize > oldsize)
{
- bim->buffer = (bfd_byte *) bfd_realloc (bim->buffer, newsize);
+ bim->buffer = bfd_realloc (bim->buffer, newsize);
if (bim->buffer == 0)
{
bim->size = 0;
@@ -173,16 +188,15 @@ bfd_bwrite (ptr, size, abfd)
return nwrote;
}
-bfd_vma
-bfd_tell (abfd)
- bfd *abfd;
+file_ptr
+bfd_tell (bfd *abfd)
{
file_ptr ptr;
if ((abfd->flags & BFD_IN_MEMORY) != 0)
return abfd->where;
- ptr = ftell (bfd_cache_lookup (abfd));
+ ptr = real_ftell (bfd_cache_lookup (abfd));
if (abfd->my_archive)
ptr -= abfd->origin;
@@ -191,8 +205,7 @@ bfd_tell (abfd)
}
int
-bfd_flush (abfd)
- bfd *abfd;
+bfd_flush (bfd *abfd)
{
if ((abfd->flags & BFD_IN_MEMORY) != 0)
return 0;
@@ -202,9 +215,7 @@ bfd_flush (abfd)
/* Returns 0 for success, negative value for failure (in which case
bfd_get_error can retrieve the error code). */
int
-bfd_stat (abfd, statbuf)
- bfd *abfd;
- struct stat *statbuf;
+bfd_stat (bfd *abfd, struct stat *statbuf)
{
FILE *f;
int result;
@@ -228,14 +239,11 @@ bfd_stat (abfd, statbuf)
can retrieve the error code). */
int
-bfd_seek (abfd, position, direction)
- bfd *abfd;
- file_ptr position;
- int direction;
+bfd_seek (bfd *abfd, file_ptr position, int direction)
{
int result;
FILE *f;
- long file_position;
+ file_ptr file_position;
/* For the time being, a BFD may not seek to it's end. The problem
is that we don't easily have a way to recognize the end of an
element in an archive. */
@@ -249,7 +257,7 @@ bfd_seek (abfd, position, direction)
{
struct bfd_in_memory *bim;
- bim = (struct bfd_in_memory *) abfd->iostream;
+ bim = abfd->iostream;
if (direction == SEEK_SET)
abfd->where = position;
@@ -268,7 +276,7 @@ bfd_seek (abfd, position, direction)
newsize = (bim->size + 127) & ~(bfd_size_type) 127;
if (newsize > oldsize)
{
- bim->buffer = (bfd_byte *) bfd_realloc (bim->buffer, newsize);
+ bim->buffer = bfd_realloc (bim->buffer, newsize);
if (bim->buffer == 0)
{
bim->size = 0;
@@ -296,7 +304,7 @@ bfd_seek (abfd, position, direction)
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 = ftell (bfd_cache_lookup (abfd));
+ 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)
@@ -325,7 +333,7 @@ bfd_seek (abfd, position, direction)
if (direction == SEEK_SET && abfd->my_archive != NULL)
file_position += abfd->origin;
- result = fseek (f, file_position, direction);
+ result = real_fseek (f, file_position, direction);
if (result != 0)
{
int hold_errno = errno;
@@ -359,7 +367,7 @@ FUNCTION
bfd_get_mtime
SYNOPSIS
- long bfd_get_mtime(bfd *abfd);
+ long bfd_get_mtime (bfd *abfd);
DESCRIPTION
Return the file modification time (as read from the file system, or
@@ -368,8 +376,7 @@ DESCRIPTION
*/
long
-bfd_get_mtime (abfd)
- bfd *abfd;
+bfd_get_mtime (bfd *abfd)
{
FILE *fp;
struct stat buf;
@@ -390,7 +397,7 @@ FUNCTION
bfd_get_size
SYNOPSIS
- long bfd_get_size(bfd *abfd);
+ long bfd_get_size (bfd *abfd);
DESCRIPTION
Return the file size (as read from file system) for the file
@@ -414,13 +421,12 @@ DESCRIPTION
error when it tries to read the table, or a "virtual memory
exhausted" error when it tries to allocate 15 bazillon bytes
of space for the 15 bazillon byte table it is about to read.
- This function at least allows us to answer the quesion, "is the
+ This function at least allows us to answer the question, "is the
size reasonable?".
*/
long
-bfd_get_size (abfd)
- bfd *abfd;
+bfd_get_size (bfd *abfd)
{
FILE *fp;
struct stat buf;