1
0
mirror of https://github.com/git/git.git synced 2024-09-21 10:52:56 +02:00

usage.c: move format processing out of die_errno()

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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2016-05-08 16:47:21 +07:00 committed by Junio C Hamano
parent 90f7b16b3a
commit 58e4e5118a

27
usage.c
View File

@ -109,19 +109,11 @@ void NORETURN die(const char *err, ...)
va_end(params);
}
void NORETURN die_errno(const char *fmt, ...)
static const char *fmt_with_err(char *buf, int n, const char *fmt)
{
va_list params;
char fmt_with_err[1024];
char str_error[256], *err;
int i, j;
if (die_is_recursing()) {
fputs("fatal: recursion detected in die_errno handler\n",
stderr);
exit(128);
}
err = strerror(errno);
for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
if ((str_error[j++] = err[i++]) != '%')
@ -136,10 +128,23 @@ void NORETURN die_errno(const char *fmt, ...)
}
}
str_error[j] = 0;
snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error);
snprintf(buf, n, "%s: %s", fmt, str_error);
return buf;
}
void NORETURN die_errno(const char *fmt, ...)
{
char buf[1024];
va_list params;
if (die_is_recursing()) {
fputs("fatal: recursion detected in die_errno handler\n",
stderr);
exit(128);
}
va_start(params, fmt);
die_routine(fmt_with_err, params);
die_routine(fmt_with_err(buf, sizeof(buf), fmt), params);
va_end(params);
}