+ }
+
+ return nread;
+}
+
+static file_ptr
+cache_bwrite (struct bfd *abfd, const void *from, file_ptr nbytes)
+{
+ file_ptr nwrite;
+ FILE *f = bfd_cache_lookup (abfd, CACHE_NORMAL);
+
+ if (f == NULL)
+ return 0;
+ nwrite = fwrite (from, 1, nbytes, f);
+ if (nwrite < nbytes && ferror (f))
+ {
+ bfd_set_error (bfd_error_system_call);
+ return -1;
+ }
+ return nwrite;
+}
+
+static int
+cache_bclose (struct bfd *abfd)
+{
+ return bfd_cache_close (abfd) - 1;
+}
+
+static int
+cache_bflush (struct bfd *abfd)
+{
+ int sts;
+ FILE *f = bfd_cache_lookup (abfd, CACHE_NO_OPEN);
+
+ if (f == NULL)
+ return 0;
+ sts = fflush (f);
+ if (sts < 0)
+ bfd_set_error (bfd_error_system_call);
+ return sts;
+}
+
+static int
+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);
+ if (sts < 0)
+ bfd_set_error (bfd_error_system_call);
+ return sts;
+}
+
+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 **map_addr ATTRIBUTE_UNUSED,
+ bfd_size_type *map_len ATTRIBUTE_UNUSED)
+{
+ void *ret = (void *) -1;
+
+ if ((abfd->flags & BFD_IN_MEMORY) != 0)
+ abort ();
+#ifdef HAVE_MMAP
+ else
+ {
+ static uintptr_t pagesize_m1;
+ FILE *f;
+ file_ptr pg_offset;
+ bfd_size_type pg_len;
+
+ f = bfd_cache_lookup (abfd, CACHE_NO_SEEK_ERROR);
+ if (f == NULL)
+ return ret;
+
+ if (pagesize_m1 == 0)
+ pagesize_m1 = getpagesize () - 1;
+
+ /* Align. */
+ pg_offset = offset & ~pagesize_m1;
+ pg_len = (len + (offset - pg_offset) + pagesize_m1) & ~pagesize_m1;
+
+ ret = mmap (addr, pg_len, prot, flags, fileno (f), pg_offset);
+ if (ret == (void *) -1)
+ bfd_set_error (bfd_error_system_call);
+ else
+ {
+ *map_addr = ret;
+ *map_len = pg_len;
+ ret = (char *) ret + (offset & pagesize_m1);