* po/fi.po: Updated Finnish translation.
[deliverable/binutils-gdb.git] / bfd / cache.c
index 3906335041d0cef17f31ef53357ae13b39eddda5..c6873a96de5ce324a3d2f0b10b09ab77b0f3f829 100644 (file)
@@ -46,6 +46,10 @@ SUBSECTION
 #include "libbfd.h"
 #include "libiberty.h"
 
+#ifdef HAVE_MMAP
+#include <sys/mman.h>
+#endif
+
 /* In some cases we can optimize cache operation when reopening files.
    For instance, a flush is entirely unnecessary if the file is already
    closed, so a flush would use CACHE_NO_OPEN.  Similarly, a seek using
@@ -317,7 +321,7 @@ cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
       if (chunk_size > max_chunk_size)
         chunk_size = max_chunk_size;
 
-      chunk_nread = cache_bread_1 (abfd, buf + nread, chunk_size);
+      chunk_nread = cache_bread_1 (abfd, (char *) buf + nread, chunk_size);
 
       /* Update the nread count.
 
@@ -342,6 +346,7 @@ cache_bwrite (struct bfd *abfd, const void *where, file_ptr nbytes)
 {
   file_ptr nwrite;
   FILE *f = bfd_cache_lookup (abfd, 0);
+
   if (f == NULL)
     return 0;
   nwrite = fwrite (where, 1, nbytes, f);
@@ -364,6 +369,7 @@ cache_bflush (struct bfd *abfd)
 {
   int sts;
   FILE *f = bfd_cache_lookup (abfd, CACHE_NO_OPEN);
+
   if (f == NULL)
     return 0;
   sts = fflush (f);
@@ -377,6 +383,7 @@ cache_bstat (struct bfd *abfd, struct stat *sb)
 {
   int sts;
   FILE *f = bfd_cache_lookup (abfd, CACHE_NO_SEEK_ERROR);
+
   if (f == NULL)
     return -1;
   sts = fstat (fileno (f), sb);
@@ -385,9 +392,38 @@ cache_bstat (struct bfd *abfd, struct stat *sb)
   return sts;
 }
 
-static const struct bfd_iovec cache_iovec = {
+static void *
+cache_bmmap (struct bfd *abfd ATTRIBUTE_UNUSED,
+            void *addr ATTRIBUTE_UNUSED,
+            bfd_size_type len ATTRIBUTE_UNUSED,
+            int prot ATTRIBUTE_UNUSED,
+            int flags ATTRIBUTE_UNUSED,
+            file_ptr offset ATTRIBUTE_UNUSED)
+{
+  void *ret = (void *) -1;
+
+  if ((abfd->flags & BFD_IN_MEMORY) != 0)
+    abort ();
+#ifdef HAVE_MMAP
+  else
+    {
+      FILE *f = bfd_cache_lookup (abfd, CACHE_NO_SEEK_ERROR);
+      if (f == NULL)
+       return ret;
+
+      ret = mmap (addr, len, prot, flags, fileno (f), offset);
+      if (ret == (void *) -1)
+       bfd_set_error (bfd_error_system_call);
+    }
+#endif
+
+  return ret;
+}
+
+static const struct bfd_iovec cache_iovec =
+{
   &cache_bread, &cache_bwrite, &cache_btell, &cache_bseek,
-  &cache_bclose, &cache_bflush, &cache_bstat
+  &cache_bclose, &cache_bflush, &cache_bstat, &cache_bmmap
 };
 
 /*
This page took 0.025849 seconds and 4 git commands to generate.