This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH, libiberty: eliminate build warning
* pex-unix.c (pex_child_error): Improve warning avoidance by
checking the results of write(3) and exiting with -2 if any write
returns a non-zero value.
+#define writeerr(s) retval |= write (STDERR_FILE_NO, s, strlen (s))
+ _exit (retval == 0 ? -1 : -2);
Calling _exit(-1) will be exceedingly rare.
write() is the classic UNIX system call interface declared in <unistd.h>.
Upon success write() returns the number of bytes written, which will be
equal to its third argument. The third argument is almost never zero,
so the patch uses 'retval' inconsistently.
Something such as
#define writeerr(s) retval |= (strlen (s) != write (STDERR_FILE_NO, s, strlen (s)))
could be used, although that is somewhat messy because of the two strlen().
I prefer to use an explicit function such as
static int uwrite (int fd, char const *msg, ssize_t len)
{
return len != write (fd, msg, len);
}
which a compile may decide to inline if 'len' is a constant.
--