-extern bfd_vma _bfd_read_unsigned_leb128 (bfd *, bfd_byte *, unsigned int *);
-extern bfd_signed_vma _bfd_read_signed_leb128 (bfd *, bfd_byte *, unsigned int *);
-extern bfd_vma _bfd_safe_read_leb128 (bfd *, bfd_byte *, unsigned int *,
- bfd_boolean, const bfd_byte * const);
+static inline bfd_byte *
+_bfd_alloc_and_read (bfd *abfd, bfd_size_type asize, bfd_size_type rsize)
+{
+ bfd_byte *mem;
+ if (!_bfd_constant_p (rsize))
+ {
+ ufile_ptr filesize = bfd_get_file_size (abfd);
+ if (filesize != 0 && rsize > filesize)
+ {
+ bfd_set_error (bfd_error_file_truncated);
+ return NULL;
+ }
+ }
+ 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;
+ if (!_bfd_constant_p (rsize))
+ {
+ ufile_ptr filesize = bfd_get_file_size (abfd);
+ if (filesize != 0 && rsize > filesize)
+ {
+ bfd_set_error (bfd_error_file_truncated);
+ return NULL;
+ }
+ }
+ mem = bfd_malloc (asize);
+ if (mem != NULL)
+ {
+ if (bfd_bread (mem, rsize, abfd) == rsize)
+ return mem;
+ free (mem);
+ }
+ return NULL;
+}