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
|
|
|
|
2010-03-06 18:40:39 +03:00
|
|
|
void vreportf(const char *prefix, const char *err, va_list params)
|
2005-04-19 00:04:43 +04:00
|
|
|
{
|
2009-11-23 00:19:53 +03:00
|
|
|
char msg[4096];
|
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
|
|
|
}
|
|
|
|
|
2009-11-09 18:05:02 +03:00
|
|
|
static NORETURN void usage_builtin(const char *err, va_list params)
|
2005-04-19 00:04:43 +04:00
|
|
|
{
|
2010-03-06 18:40:39 +03:00
|
|
|
vreportf("usage: ", err, params);
|
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
|
|
|
{
|
2010-03-06 18:40:39 +03:00
|
|
|
vreportf("fatal: ", err, params);
|
2006-06-24 06:34:38 +04:00
|
|
|
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
|
|
|
{
|
2010-03-06 18:40:39 +03:00
|
|
|
vreportf("error: ", err, params);
|
2006-06-24 06:34:38 +04:00
|
|
|
}
|
|
|
|
|
2006-12-22 03:48:32 +03:00
|
|
|
static void warn_builtin(const char *warn, va_list params)
|
|
|
|
{
|
2010-03-06 18:40:39 +03:00
|
|
|
vreportf("warning: ", warn, params);
|
2006-12-22 03:48:32 +03:00
|
|
|
}
|
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. */
|
2009-11-09 18:05:02 +03:00
|
|
|
static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = usage_builtin;
|
2009-09-30 22:05:50 +04:00
|
|
|
static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = die_builtin;
|
2006-06-24 06:34:38 +04:00
|
|
|
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
|
|
|
|
2009-09-30 22:05:50 +04:00
|
|
|
void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params))
|
2006-06-24 06:34:38 +04:00
|
|
|
{
|
|
|
|
die_routine = routine;
|
|
|
|
}
|
|
|
|
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 10:51:05 +03:00
|
|
|
void NORETURN usagef(const char *err, ...)
|
2009-11-09 18:05:02 +03:00
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
va_start(params, err);
|
|
|
|
usage_routine(err, params);
|
|
|
|
va_end(params);
|
|
|
|
}
|
|
|
|
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 10:51:05 +03:00
|
|
|
void NORETURN usage(const char *err)
|
2006-06-24 06:34:38 +04:00
|
|
|
{
|
2009-11-09 18:05:02 +03:00
|
|
|
usagef("%s", err);
|
2006-06-24 06:34:38 +04:00
|
|
|
}
|
|
|
|
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 10:51:05 +03:00
|
|
|
void NORETURN die(const char *err, ...)
|
2005-04-19 00:04:43 +04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
Fix sparse warnings
Fix warnings from 'make check'.
- These files don't include 'builtin.h' causing sparse to complain that
cmd_* isn't declared:
builtin/clone.c:364, builtin/fetch-pack.c:797,
builtin/fmt-merge-msg.c:34, builtin/hash-object.c:78,
builtin/merge-index.c:69, builtin/merge-recursive.c:22
builtin/merge-tree.c:341, builtin/mktag.c:156, builtin/notes.c:426
builtin/notes.c:822, builtin/pack-redundant.c:596,
builtin/pack-refs.c:10, builtin/patch-id.c:60, builtin/patch-id.c:149,
builtin/remote.c:1512, builtin/remote-ext.c:240,
builtin/remote-fd.c:53, builtin/reset.c:236, builtin/send-pack.c:384,
builtin/unpack-file.c:25, builtin/var.c:75
- These files have symbols which should be marked static since they're
only file scope:
submodule.c:12, diff.c:631, replace_object.c:92, submodule.c:13,
submodule.c:14, trace.c:78, transport.c:195, transport-helper.c:79,
unpack-trees.c:19, url.c:3, url.c:18, url.c:104, url.c:117, url.c:123,
url.c:129, url.c:136, thread-utils.c:21, thread-utils.c:48
- These files redeclare symbols to be different types:
builtin/index-pack.c:210, parse-options.c:564, parse-options.c:571,
usage.c:49, usage.c:58, usage.c:63, usage.c:72
- These files use a literal integer 0 when they really should use a NULL
pointer:
daemon.c:663, fast-import.c:2942, imap-send.c:1072, notes-merge.c:362
While we're in the area, clean up some unused #includes in builtin files
(mostly exec_cmd.h).
Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-22 10:51:05 +03:00
|
|
|
void NORETURN die_errno(const char *fmt, ...)
|
2009-06-27 19:58:44 +04:00
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
char fmt_with_err[1024];
|
2009-06-27 19:58:45 +04:00
|
|
|
char str_error[256], *err;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
err = strerror(errno);
|
|
|
|
for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) {
|
|
|
|
if ((str_error[j++] = err[i++]) != '%')
|
|
|
|
continue;
|
|
|
|
if (j < sizeof(str_error) - 1) {
|
|
|
|
str_error[j++] = '%';
|
|
|
|
} else {
|
|
|
|
/* No room to double the '%', so we overwrite it with
|
|
|
|
* '\0' below */
|
|
|
|
j--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
str_error[j] = 0;
|
|
|
|
snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error);
|
2009-06-27 19:58:44 +04:00
|
|
|
|
|
|
|
va_start(params, fmt);
|
|
|
|
die_routine(fmt_with_err, params);
|
|
|
|
va_end(params);
|
|
|
|
}
|
|
|
|
|
2005-04-19 00:04:43 +04:00
|
|
|
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);
|
|
|
|
}
|