This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH, libiberty: eliminate build warning


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);
>>  }
>>
>>
>>
>>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]