Re: [PATCH 01/41] usage.c: move format processing out of die_errno()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Eric Sunshine <sunshine@xxxxxxxxxxxxxx> writes:

> On Sun, May 1, 2016 at 7:14 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote:
>> fmt_with_err() will be shared with the coming error_errno() and
>> warning_errno().
>>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
>> ---
>> diff --git a/usage.c b/usage.c
>> @@ -109,19 +109,12 @@ void NORETURN die(const char *err, ...)
>> -void NORETURN die_errno(const char *fmt, ...)
>> +static const char *fmt_with_err(const char *fmt)
>>  {
>> -       va_list params;
>> -       char fmt_with_err[1024];
>> +       static char fmt_with_err[1024];
>
> Rather than this static buffer, did you consider having the caller
> pass in the buffer?
>
>     static const char *fmt_with_err(char *buf, size_t n, const char *fmt)
>     {
>         ...
>         snprintf(buf, n, "%s: %s", fmt, str_error);
>         return buf;
>     }
>
>     void die_errno(const char *fmt, ...)
>     {
>         char fmtbuf[1024];
>         ...
>         die_routine(fmt_with_err(fmtbuf, sizeof(fmtbuf), fmt),
>             params);
>         ...
>     }
>
> Better? Worse? Indifferent?

Caller supplied buffer would be the way to go when multiple threads
could be showing errors and warnings, right?

It would not make too much of a difference for die(), though.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]