This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Commit: objcopy: Add --dump-section option
- From: Anthony Green <green at moxielogic dot com>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: binutils at sourceware dot org
- Date: Sat, 08 Mar 2014 23:14:36 -0500
- Subject: Re: Commit: objcopy: Add --dump-section option
- Authentication-results: sourceware.org; auth=none
- References: <87d2kdgxft dot fsf at redhat dot com>
Nick Clifton <nickc@redhat.com> writes:
> Hi Guys,
>
> I am applying the attached patch to add a new command line option to
> objcopy: --dump-section. This option is the inverse of --add-section
> in that it dumps the contents of a specified section to a specified
> file. The dump is just a raw copy of the contents of the section. It
> is not formatted in any way. This is useful if the section cannot be
> copied via the --only-section option, or if it needs to be passed to a
> --add-section option later on.
Hi Nick,
This patch adds a check of the return code of fwrite. It was required
to build with full warnings enabled. Ok to commit?
AG
2014-03-08 Anthony Green <green@moxielogic.com>
* objcopy.c (copy_object): Check fwrite return code.
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index cb2be49..6215919 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1875,7 +1875,12 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
bfd_byte * contents = xmalloc (size);
if (bfd_get_section_contents (ibfd, sec, contents, 0, size))
- fwrite (contents, 1, size, f);
+ {
+ if (fwrite (contents, 1, size, f) != size)
+ fatal (_("error writing section contents to %s (error: %s)"),
+ pdump->filename,
+ strerror (errno));
+ }
else
bfd_nonfatal_message (NULL, ibfd, sec,
_("could not retrieve section contents"));