]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/libbfd-in.h
_bfd_alloc_and_read
[thirdparty/binutils-gdb.git] / bfd / libbfd-in.h
index 00650c3c86d13bbd6e453fff0701e0c8b48e64ba..a8f9bcd47d3362d2095b7f6bbd3ac1e8eb213f6a 100644 (file)
@@ -903,3 +903,29 @@ extern bfd_vma _bfd_safe_read_leb128
 #define _bfd_mul_overflow(a, b, res) \
   ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
 #endif
+
+static inline bfd_byte *
+_bfd_alloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
+{
+  bfd_byte *mem = bfd_alloc (abfd, asize);
+  if (mem != NULL)
+    {
+      if (bfd_bread (mem, rsize, abfd) == rsize)
+       return mem;
+      bfd_release (abfd, mem);
+    }
+  return NULL;
+}
+
+static inline bfd_byte *
+_bfd_malloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
+{
+  bfd_byte *mem = bfd_malloc (asize);
+  if (mem != NULL)
+    {
+      if (bfd_bread (mem, rsize, abfd) == rsize)
+       return mem;
+      free (mem);
+    }
+  return NULL;
+}