2000-11-14 Kazu Hirata <kazu@hxi.com>
[deliverable/binutils-gdb.git] / bfd / libbfd.c
index 1bc0f33ee1259997556af1bee145cac38330d263..47f1ebbe2bd3506742bf8e4eb6716f8ec6197b6b 100644 (file)
@@ -691,11 +691,31 @@ bfd_seek (abfd, position, direction)
       
       if ((bfd_size_type) abfd->where > bim->size)
        {
-         abfd->where = bim->size;
-         bfd_set_error (bfd_error_file_truncated);
-         return -1;
+         if ((abfd->direction == write_direction) || 
+             (abfd->direction == both_direction))
+           {
+             long newsize, oldsize = (bim->size + 127) & ~127;
+             bim->size = abfd->where;
+             /* Round up to cut down on memory fragmentation */
+             newsize = (bim->size + 127) & ~127;
+             if (newsize > oldsize)
+               {
+                 bim->buffer = bfd_realloc (bim->buffer, newsize);
+                 if (bim->buffer == 0)
+                   {
+                     bim->size = 0;
+                     bfd_set_error (bfd_error_no_memory);
+                     return -1;
+                   }
+               }
+           }
+         else
+           {
+             abfd->where = bim->size;
+             bfd_set_error (bfd_error_file_truncated);
+             return -1;
+           }   
        }
-      
       return 0;
     }
 
This page took 0.025874 seconds and 4 git commands to generate.