2009-04-20 20:00:56 +07:00
|
|
|
/*
|
2011-12-13 20:52:03 +07:00
|
|
|
* usage.c
|
|
|
|
*
|
|
|
|
* Various reporting routines.
|
|
|
|
* Originally copied from GIT source.
|
2009-04-20 20:00:56 +07:00
|
|
|
*
|
|
|
|
* Copyright (C) Linus Torvalds, 2005
|
|
|
|
*/
|
|
|
|
#include "util.h"
|
2012-01-19 23:08:15 +07:00
|
|
|
#include "debug.h"
|
2009-04-20 20:00:56 +07:00
|
|
|
|
|
|
|
static void report(const char *prefix, const char *err, va_list params)
|
|
|
|
{
|
|
|
|
char msg[1024];
|
|
|
|
vsnprintf(msg, sizeof(msg), err, params);
|
2009-06-07 22:31:52 +07:00
|
|
|
fprintf(stderr, " %s%s\n", prefix, msg);
|
2009-04-20 20:00:56 +07:00
|
|
|
}
|
|
|
|
|
2017-06-16 21:39:15 +07:00
|
|
|
static __noreturn void usage_builtin(const char *err)
|
2009-04-20 20:00:56 +07:00
|
|
|
{
|
2009-06-07 22:31:52 +07:00
|
|
|
fprintf(stderr, "\n Usage: %s\n", err);
|
2009-04-20 20:00:56 +07:00
|
|
|
exit(129);
|
|
|
|
}
|
|
|
|
|
2017-06-16 21:39:15 +07:00
|
|
|
static __noreturn void die_builtin(const char *err, va_list params)
|
2009-04-20 20:00:56 +07:00
|
|
|
{
|
2009-06-07 22:31:52 +07:00
|
|
|
report(" Fatal: ", err, params);
|
2009-04-20 20:00:56 +07:00
|
|
|
exit(128);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we are in a dlopen()ed .so write to a global variable would segfault
|
|
|
|
* (ugh), so keep things static. */
|
2017-06-16 21:39:15 +07:00
|
|
|
static void (*usage_routine)(const char *err) __noreturn = usage_builtin;
|
2015-10-19 22:23:49 +07:00
|
|
|
|
2009-04-20 20:00:56 +07:00
|
|
|
void usage(const char *err)
|
|
|
|
{
|
|
|
|
usage_routine(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void die(const char *err, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
va_start(params, err);
|
2016-03-23 22:32:31 +07:00
|
|
|
die_builtin(err, params);
|
2009-04-20 20:00:56 +07:00
|
|
|
va_end(params);
|
|
|
|
}
|