2005-04-19 00:04:43 +04:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) Linus Torvalds, 2005
|
|
|
|
*/
|
2005-12-05 22:54:29 +03:00
|
|
|
#include "git-compat-util.h"
|
2005-04-19 00:04:43 +04:00
|
|
|
|
|
|
|
static void report(const char *prefix, const char *err, va_list params)
|
|
|
|
{
|
2009-03-25 02:10:35 +03:00
|
|
|
char msg[1024];
|
2007-11-09 22:33:54 +03:00
|
|
|
vsnprintf(msg, sizeof(msg), err, params);
|
|
|
|
fprintf(stderr, "%s%s\n", prefix, msg);
|
2005-04-19 00:04:43 +04:00
|
|
|
}
|
|
|
|
|
2006-06-24 09:44:33 +04:00
|
|
|
static NORETURN void usage_builtin(const char *err)
|
2005-04-19 00:04:43 +04:00
|
|
|
{
|
|
|
|
fprintf(stderr, "usage: %s\n", err);
|
2005-10-02 00:24:27 +04:00
|
|
|
exit(129);
|
2005-04-19 00:04:43 +04:00
|
|
|
}
|
|
|
|
|
2006-06-24 09:44:33 +04:00
|
|
|
static NORETURN void die_builtin(const char *err, va_list params)
|
2006-06-24 06:34:38 +04:00
|
|
|
{
|
|
|
|
report("fatal: ", err, params);
|
|
|
|
exit(128);
|
|
|
|
}
|
|
|
|
|
2006-06-24 09:44:33 +04:00
|
|
|
static void error_builtin(const char *err, va_list params)
|
2006-06-24 06:34:38 +04:00
|
|
|
{
|
|
|
|
report("error: ", err, params);
|
|
|
|
}
|
|
|
|
|
2006-12-22 03:48:32 +03:00
|
|
|
static void warn_builtin(const char *warn, va_list params)
|
|
|
|
{
|
|
|
|
report("warning: ", warn, params);
|
|
|
|
}
|
2006-06-24 06:34:38 +04:00
|
|
|
|
|
|
|
/* If we are in a dlopen()ed .so write to a global variable would segfault
|
|
|
|
* (ugh), so keep things static. */
|
|
|
|
static void (*usage_routine)(const char *err) NORETURN = usage_builtin;
|
|
|
|
static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin;
|
|
|
|
static void (*error_routine)(const char *err, va_list params) = error_builtin;
|
2006-12-22 03:48:32 +03:00
|
|
|
static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
|
2006-06-24 06:34:38 +04:00
|
|
|
|
|
|
|
void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN)
|
|
|
|
{
|
|
|
|
die_routine = routine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void usage(const char *err)
|
|
|
|
{
|
|
|
|
usage_routine(err);
|
|
|
|
}
|
|
|
|
|
2005-04-19 00:04:43 +04:00
|
|
|
void die(const char *err, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
va_start(params, err);
|
2006-06-24 06:34:38 +04:00
|
|
|
die_routine(err, params);
|
2005-04-19 00:04:43 +04:00
|
|
|
va_end(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
int error(const char *err, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
va_start(params, err);
|
2006-06-24 06:34:38 +04:00
|
|
|
error_routine(err, params);
|
2005-04-19 00:04:43 +04:00
|
|
|
va_end(params);
|
|
|
|
return -1;
|
|
|
|
}
|
2006-12-22 03:48:32 +03:00
|
|
|
|
2007-03-31 03:07:05 +04:00
|
|
|
void warning(const char *warn, ...)
|
2006-12-22 03:48:32 +03:00
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
va_start(params, warn);
|
|
|
|
warn_routine(warn, params);
|
|
|
|
va_end(params);
|
|
|
|
}
|