]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* cache.c (cache_bread_1): Renames cache_bread.
authorJoel Brobecker <brobecker@gnat.com>
Thu, 1 May 2008 15:45:43 +0000 (15:45 +0000)
committerJoel Brobecker <brobecker@gnat.com>
Thu, 1 May 2008 15:45:43 +0000 (15:45 +0000)
        (cache_bread): New function.

bfd/ChangeLog
bfd/cache.c

index 8d994a8c6ae45d109465aab62464921879022722..75bc0b6d7bd824d1716b516caaed5c5d88e5fb99 100644 (file)
@@ -1,3 +1,8 @@
+2008-05-01  Joel Brobecker  <brobecker@adacore.com>
+
+       * cache.c (cache_bread_1): Renames cache_bread.
+       (cache_bread): New function.
+
 2008-05-01  Alan Modra  <amodra@bigpond.net.au>
 
        PR 2995, PR 6473
index eb6120dfbe2f00734a5cf3250adf51b0619ddc0e..3906335041d0cef17f31ef53357ae13b39eddda5 100644 (file)
@@ -250,7 +250,7 @@ cache_bseek (struct bfd *abfd, file_ptr offset, int whence)
    first octet in the file, NOT the beginning of the archive header.  */
 
 static file_ptr
-cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
+cache_bread_1 (struct bfd *abfd, void *buf, file_ptr nbytes)
 {
   FILE *f;
   file_ptr nread;
@@ -300,6 +300,43 @@ cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
   return nread;
 }
 
+static file_ptr
+cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
+{
+  file_ptr nread = 0;
+
+  /* Some filesystems are unable to handle reads that are too large
+     (for instance, NetApp shares with oplocks turned off).  To avoid
+     hitting this limitation, we read the buffer in chunks of 8MB max.  */
+  while (nread < nbytes)
+    {
+      const file_ptr max_chunk_size = 0x800000;
+      file_ptr chunk_size = nbytes - nread;
+      file_ptr chunk_nread;
+
+      if (chunk_size > max_chunk_size)
+        chunk_size = max_chunk_size;
+
+      chunk_nread = cache_bread_1 (abfd, buf + nread, chunk_size);
+
+      /* Update the nread count.
+
+         We just have to be careful of the case when cache_bread_1 returns
+         a negative count:  If this is our first read, then set nread to
+         that negative count in order to return that negative value to the
+         caller.  Otherwise, don't add it to our total count, or we would
+         end up returning a smaller number of bytes read than we actually
+         did.  */
+      if (nread == 0 || chunk_nread > 0)
+        nread += chunk_nread;
+
+      if (chunk_nread < chunk_size)
+        break;
+    }
+
+  return nread;
+}
+
 static file_ptr
 cache_bwrite (struct bfd *abfd, const void *where, file_ptr nbytes)
 {