* aout-arm.c, aout-target.h, aoutx.h, archive.c, armnetbsd.c,
[deliverable/binutils-gdb.git] / bfd / bfdio.c
index 53534f4f66f6f02f40019bd484396e64a51b9413..51deabc48a1c32e9c1eda66a0380c092c4228ac6 100644 (file)
@@ -125,7 +125,10 @@ bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
       return get;
     }
 
-  nread = abfd->iovec->bread (abfd, ptr, size);
+  if (abfd->iovec)
+    nread = abfd->iovec->bread (abfd, ptr, size);
+  else
+    nread = 0;
   if (nread != (size_t) -1)
     abfd->where += nread;
 
@@ -140,6 +143,7 @@ bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     {
       struct bfd_in_memory *bim = abfd->iostream;
+
       size = (size_t) size;
       if (abfd->where + size > bim->size)
        {
@@ -164,7 +168,11 @@ bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
       return size;
     }
 
-  nwrote = abfd->iovec->bwrite (abfd, ptr, size);
+  if (abfd->iovec)
+    nwrote = abfd->iovec->bwrite (abfd, ptr, size);
+  else
+    nwrote = 0;
+
   if (nwrote != (size_t) -1)
     abfd->where += nwrote;
   if (nwrote != size)
@@ -185,10 +193,16 @@ bfd_tell (bfd *abfd)
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     return abfd->where;
 
-  ptr = abfd->iovec->btell (abfd);
+  if (abfd->iovec)
+    {
+      ptr = abfd->iovec->btell (abfd);
+
+      if (abfd->my_archive)
+       ptr -= abfd->origin;
+    }
+  else
+    ptr = 0;
 
-  if (abfd->my_archive)
-    ptr -= abfd->origin;
   abfd->where = ptr;
   return ptr;
 }
@@ -198,7 +212,10 @@ bfd_flush (bfd *abfd)
 {
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     return 0;
-  return abfd->iovec->bflush (abfd);
+
+  if (abfd->iovec)
+    return abfd->iovec->bflush (abfd);
+  return 0;
 }
 
 /* Returns 0 for success, negative value for failure (in which case
@@ -211,7 +228,11 @@ bfd_stat (bfd *abfd, struct stat *statbuf)
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     abort ();
 
-  result = abfd->iovec->bstat (abfd, statbuf);
+  if (abfd->iovec)
+    result = abfd->iovec->bstat (abfd, statbuf);
+  else
+    result = -1;
+
   if (result < 0)
     bfd_set_error (bfd_error_system_call);
   return result;
@@ -251,6 +272,7 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
              (abfd->direction == both_direction))
            {
              bfd_size_type newsize, oldsize;
+
              oldsize = (bim->size + 127) & ~(bfd_size_type) 127;
              bim->size = abfd->where;
              /* Round up to cut down on memory fragmentation */
@@ -277,20 +299,6 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
 
   if (abfd->format != bfd_archive && abfd->my_archive == 0)
     {
-#if 0
-      /* Explanation for this code: I'm only about 95+% sure that the above
-        conditions are sufficient and that all i/o calls are properly
-        adjusting the `where' field.  So this is sort of an `assert'
-        that the `where' field is correct.  If we can go a while without
-        tripping the abort, we can probably safely disable this code,
-        so that the real optimizations happen.  */
-      file_ptr where_am_i_now;
-      where_am_i_now = real_ftell (bfd_cache_lookup (abfd));
-      if (abfd->my_archive)
-       where_am_i_now -= abfd->origin;
-      if (where_am_i_now != abfd->where)
-       abort ();
-#endif
       if (direction == SEEK_SET && (bfd_vma) position == abfd->where)
        return 0;
     }
@@ -313,7 +321,11 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
   if (direction == SEEK_SET && abfd->my_archive != NULL)
     file_position += abfd->origin;
 
-  result = abfd->iovec->bseek (abfd, file_position, direction);
+  if (abfd->iovec)
+    result = abfd->iovec->bseek (abfd, file_position, direction);
+  else
+    result = -1;
+
   if (result != 0)
     {
       int hold_errno = errno;
@@ -363,6 +375,9 @@ bfd_get_mtime (bfd *abfd)
   if (abfd->mtime_set)
     return abfd->mtime;
 
+  if (abfd->iovec == NULL)
+    return 0;
+
   if (abfd->iovec->bstat (abfd, &buf) != 0)
     return 0;
 
@@ -411,6 +426,9 @@ bfd_get_size (bfd *abfd)
   if ((abfd->flags & BFD_IN_MEMORY) != 0)
     return ((struct bfd_in_memory *) abfd->iostream)->size;
 
+  if (abfd->iovec == NULL)
+    return 0;
+
   if (abfd->iovec->bstat (abfd, &buf) != 0)
     return 0;
 
This page took 0.037784 seconds and 4 git commands to generate.