Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
usage.c: move format processing out of die_errno()
author
Nguyễn Thái Ngọc Duy
<pclouds@gmail.com>
Sun, 8 May 2016 09:47:21 +0000
(16:47 +0700)
committer
Junio C Hamano
<gitster@pobox.com>
Mon, 9 May 2016 19:29:08 +0000
(12:29 -0700)
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>
usage.c
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
90f7b16
)
diff --git
a/usage.c
b/usage.c
index 82ff13163b542aab07e68bfa1056dc46316634a1..8675d72f30a1c3e98d890a8b1b6f111a1293258f 100644
(file)
--- a/
usage.c
+++ b/
usage.c
@@
-109,19
+109,11
@@
void NORETURN die(const char *err, ...)
va_end(params);
}
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;
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++]) != '%')
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;
}
}
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);
va_start(params, fmt);
- die_routine(fmt_with_err, params);
+ die_routine(fmt_with_err
(buf, sizeof(buf), fmt)
, params);
va_end(params);
}
va_end(params);
}