This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH, libiberty: eliminate build warning
- From: =?big5?b?RG91ZyBLd2FuICjD9q62vHcp?= <dougkwan at google dot com>
- To: Ben Elliston <bje at au1 dot ibm dot com>
- Cc: binutils <binutils at sourceware dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>, ian at airs dot com, dj at redhat dot com
- Date: Fri, 20 Nov 2009 00:43:45 +0800
- Subject: Re: PATCH, libiberty: eliminate build warning
- References: <1258625975.11150.8.camel@bapbop> <498552560911190814j6ede7dcbsa89cc3bb7eae3067@mail.gmail.com>
Oh, I did not realize the original warning. May be it is better to do
something like:
#define writerr(s) \
do \
{ \
const char *p = (s); \
if (write(STDERR_FILE_NO, p, strlen(p))) \
{} \
} while (0)
This should eliminate the unused result warning and is safe even if s
has side-effects or the macro is used before an "else".
2009/11/20 Doug Kwan (Ãö®¶¼w) <dougkwan@google.com>:
> If the macro is used before an "else" keyword, would there be a
> problem? I would instead do something like:
>
> #define writeerr(s) do {write (STDERR_FILE_NO, s, strlen (s)); } while (0)
>
> -Doug
>
> 2009/11/19 Ben Elliston <bje@au1.ibm.com>:
>> This patch eliminates a warning in pex-unix.c due to write(3) being
>> marked as warn_unused_result on some GNU/Linux distributions. As the
>> coment in pex_child_error says, there is no alternative such as using
>> fwrite(3).
>>
>> Okay for binutils and gcc trunk?
>>
>> Thanks, Ben
>>
>> 2009-11-19 Ben Elliston <bje@au.ibm.com>
>>
>> * pex-unix.c (pex_child_error): Define writeerr macro to avoid
>> unused result warnings from write(3) calls. Undefine writeerr
>> after all uses.
>>
>> 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 19 Nov 2009 10:09:16 -0000
>> @@ -368,7 +368,7 @@ 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))
>> +#define writeerr(s) if (write (STDERR_FILE_NO, s, strlen (s))) {}
>> writeerr (obj->pname);
>> writeerr (": error trying to exec '");
>> writeerr (executable);
>> @@ -377,6 +377,7 @@ pex_child_error (struct pex_obj *obj, co
>> writeerr (": ");
>> writeerr (xstrerror (err));
>> writeerr ("\n");
>> +#undef writeerr
>> _exit (-1);
>> }
>>
>>
>>
>>
>