/* Assorted BFD support routines, only used internally.
- Copyright 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
+ Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
#include "sysdep.h"
#include "libbfd.h"
+#ifndef HAVE_GETPAGESIZE
+#define getpagesize() 2048
+#endif
+
static int real_read PARAMS ((PTR, size_t, size_t, FILE *));
/*
size_t b;
FILE *file;
{
+#if defined (__VAX) && defined (VMS)
+ /* Apparently fread on Vax VMS does not keep the record length
+ information. */
+ return read (fileno (file), where, a * b);
+#else
return fread (where, a, b, file);
+#endif
}
/* Return value is amount read (FIXME: how are errors and end of file dealt
}
nread = real_read (ptr, 1, (size_t)(size*nitems), bfd_cache_lookup(abfd));
-#ifdef FILE_OFFSET_IS_CHAR_INDEX
if (nread > 0)
abfd->where += nread;
-#endif
/* Set bfd_error if we did not read as much data as we expected.
windowp->i = 0;
windowp->size = 0;
}
+\f
+/* Currently, if USE_MMAP is undefined, none if the window stuff is
+ used. Okay, so it's mis-named. At least the command-line option
+ "--without-mmap" is more obvious than "--without-windows" or some
+ such. */
+#ifdef USE_MMAP
#undef HAVE_MPROTECT /* code's not tested yet */
#if HAVE_MMAP || HAVE_MPROTECT || HAVE_MADVISE
-#include <sys/types.h>
#include <sys/mman.h>
#endif
static int debug_windows;
-/* Currently, if USE_MMAP is undefined, none if the window stuff is
- used. Okay, so it's mis-named. At least the command-line option
- "--without-mmap" is more obvious than "--without-windows" or some
- such. */
-#ifdef USE_MMAP
-
void
bfd_free_window (windowp)
bfd_window *windowp;
/* There should be no more references to i at this point. */
free (i);
}
-#endif
static int ok_to_map = 1;
bfd_window_internal *i = windowp->i;
size_t size_to_alloc = size;
-#ifndef USE_MMAP
- abort ();
-#endif
-
if (debug_windows)
fprintf (stderr, "bfd_get_file_window (%p, %6ld, %6ld, %p<%p,%lx,%p>, %d)",
abfd, (long) offset, (long) size,
- windowp, windowp->data, windowp->size, windowp->i,
- writable);
+ windowp, windowp->data, (unsigned long) windowp->size,
+ windowp->i, writable);
/* Make sure we know the page size, so we can be friendly to mmap. */
if (pagesize == 0)
else if (debug_windows)
{
if (ok_to_map)
- fprintf (stderr, "not mapping: data=%lx mapped=%d\n",
+ fprintf (stderr, _("not mapping: data=%lx mapped=%d\n"),
(unsigned long) i->data, (int) i->mapped);
else
- fprintf (stderr, "not mapping: env var not set\n");
+ fprintf (stderr, _("not mapping: env var not set\n"));
}
#else
ok_to_map = 0;
return true;
}
+#endif /* USE_MMAP */
+\f
bfd_size_type
bfd_write (ptr, size, nitems, abfd)
CONST PTR ptr;
nwrote = fwrite (ptr, 1, (size_t) (size * nitems),
bfd_cache_lookup (abfd));
-#ifdef FILE_OFFSET_IS_CHAR_INDEX
if (nwrote > 0)
abfd->where += nwrote;
-#endif
if ((bfd_size_type) nwrote != size * nitems)
{
#ifdef ENOSPC
return 0;
}
-#ifdef FILE_OFFSET_IS_CHAR_INDEX
if (abfd->format != bfd_archive && abfd->my_archive == 0)
{
#if 0
In the meantime, no optimization for archives. */
}
-#endif
f = bfd_cache_lookup (abfd);
file_position = position;
if (result != 0)
{
+ int hold_errno = errno;
+
/* Force redetermination of `where' field. */
bfd_tell (abfd);
- bfd_set_error (bfd_error_system_call);
+
+ /* An EINVAL error probably means that the file offset was
+ absurd. */
+ if (hold_errno == EINVAL)
+ bfd_set_error (bfd_error_file_truncated);
+ else
+ {
+ bfd_set_error (bfd_error_system_call);
+ errno = hold_errno;
+ }
}
else
{
-#ifdef FILE_OFFSET_IS_CHAR_INDEX
/* Adjust `where' field. */
if (direction == SEEK_SET)
abfd->where = position;
else
abfd->where += position;
-#endif
}
return result;
}
@var{x} of 1025 returns 11.
*/
-unsigned
-bfd_log2(x)
+unsigned int
+bfd_log2 (x)
bfd_vma x;
{
- unsigned result = 0;
- while ( (bfd_vma)(1<< result) < x)
- result++;
+ unsigned int result = 0;
+
+ while ((((bfd_vma) 1) << result) < x)
+ ++result;
return result;
}
boolean
-bfd_generic_is_local_label (abfd, sym)
+bfd_generic_is_local_label_name (abfd, name)
bfd *abfd;
- asymbol *sym;
+ const char *name;
{
char locals_prefix = (bfd_get_symbol_leading_char (abfd) == '_') ? 'L' : '.';
- return (sym->name[0] == locals_prefix);
+ return (name[0] == locals_prefix);
}