Re: [PATCH 01/41] usage.c: move format processing out of die_errno()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 2, 2016, 18:26 UTC
- Message-ID
- <xmqqlh3stiyt.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <CAPig+cQhQ2C-gOuQwJ9RBXM7HBBJkWORfRkq-t-PY=vvxgAonA@mail.gmail.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 35 quoted lines
> On Sun, May 1, 2016 at 7:14 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> 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@gmail.com>
>> ---
>> 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.