This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH, libiberty: eliminate build warning
Hi Ian
> I think this needs a comment. In context checking the return value of
> write is completely pointless.
Right.
> Personally, I would just write
>
> int err;
> #define writeerr(s) err = write (STDERR_FILE_NO, s, strlen (s))
After an off-list discussion with Ian, we concluded that this approach
might trigger future warnings from GCC about dead assignments. Instead,
here is a version of a patch sketched out by Ian. For reading ease, the
diff below is made against revision of 1.14 in CVS (the version before
the predecessor patch).
OK for trunk?
Ben
Index: pex-unix.c
===================================================================
RCS file: /cvs/src/src/libiberty/pex-unix.c,v
retrieving revision 1.14
diff -u -p -r1.14 pex-unix.c
--- pex-unix.c 27 Jul 2009 19:01:17 -0000 1.14
+++ pex-unix.c 22 Nov 2009 23:44:20 -0000
@@ -368,7 +368,8 @@ static void
pex_child_error (struct pex_obj *obj, const char *executable,
const char *errmsg, int err)
{
-#define writeerr(s) (void) write (STDERR_FILE_NO, s, strlen (s))
+ int retval = 0;
+#define writeerr(s) retval |= write (STDERR_FILE_NO, s, strlen (s))
writeerr (obj->pname);
writeerr (": error trying to exec '");
writeerr (executable);
@@ -377,7 +378,9 @@ pex_child_error (struct pex_obj *obj, co
writeerr (": ");
writeerr (xstrerror (err));
writeerr ("\n");
- _exit (-1);
+#undef writeerr
+ /* Exit with -2 if the error output failed, too. */
+ _exit (retval == 0 ? -1 : -2);
}