* Copyright (C) Linus Torvalds, 2005
*/
#include "git-compat-util.h"
+#include "cache.h"
+
+static int dying;
void vreportf(const char *prefix, const char *err, va_list params)
{
fprintf(stderr, "%s%s\n", prefix, msg);
}
+void vwritef(int fd, const char *prefix, const char *err, va_list params)
+{
+ char msg[4096];
+ int len = vsnprintf(msg, sizeof(msg), err, params);
+ if (len > sizeof(msg))
+ len = sizeof(msg);
+
+ write_in_full(fd, prefix, strlen(prefix));
+ write_in_full(fd, msg, len);
+ write_in_full(fd, "\n", 1);
+}
+
static NORETURN void usage_builtin(const char *err, va_list params)
{
vreportf("usage: ", err, params);
die_routine = routine;
}
-void usagef(const char *err, ...)
+void set_error_routine(void (*routine)(const char *err, va_list params))
+{
+ error_routine = routine;
+}
+
+void NORETURN usagef(const char *err, ...)
{
va_list params;
va_end(params);
}
-void usage(const char *err)
+void NORETURN usage(const char *err)
{
usagef("%s", err);
}
-void die(const char *err, ...)
+void NORETURN die(const char *err, ...)
{
va_list params;
+ if (dying) {
+ fputs("fatal: recursion detected in die handler\n", stderr);
+ exit(128);
+ }
+ dying = 1;
+
va_start(params, err);
die_routine(err, params);
va_end(params);
}
-void die_errno(const char *fmt, ...)
+void NORETURN die_errno(const char *fmt, ...)
{
va_list params;
char fmt_with_err[1024];
char str_error[256], *err;
int i, j;
+ if (dying) {
+ fputs("fatal: recursion detected in die_errno handler\n",
+ stderr);
+ exit(128);
+ }
+ dying = 1;
+
err = strerror(errno);
for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
if ((str_error[j++] = err[i++]) != '%')