summaryrefslogtreecommitdiff
path: root/usage.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-10-15 15:30:04 -0400
committerJunio C Hamano <gitster@pobox.com>2020-10-16 08:33:58 -0700
commit5710dcce74ac2a8a8d6f8f131aaa498cb04aa253 (patch)
tree8ac5b6b0b4d1e5e95e0bb902f148d754f79ddacd /usage.c
parent47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc (diff)
downloadgit-5710dcce74ac2a8a8d6f8f131aaa498cb04aa253.tar.gz
usage: define a type for a reporting function
The usage, die, warning, and error routines all work with a function pointer that takes the message to be reported. We usually just mention the function's full type inline. But this makes the use of these pointers hard to read, especially because C's syntax for returning a function pointer is so awful: void (*get_error_routine(void))(const char *err, va_list params); Unless you read it very carefully, this looks like a function pointer declaration. Let's instead use a single typedef to define a reporting function, which is the same for all four types. Note that this also removes the "extern" from these declarations to match the surrounding functions. They were missed in 554544276a (*.[ch]: remove extern from function declarations using spatch, 2019-04-29) presumably because of the unusual syntax. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/usage.c b/usage.c
index 58fb5fff5f..06665823a2 100644
--- a/usage.c
+++ b/usage.c
@@ -108,33 +108,33 @@ static int die_is_recursing_builtin(void)
/* If we are in a dlopen()ed .so write to a global variable would segfault
* (ugh), so keep things static. */
-static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = usage_builtin;
-static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = die_builtin;
-static void (*error_routine)(const char *err, va_list params) = error_builtin;
-static void (*warn_routine)(const char *err, va_list params) = warn_builtin;
+static NORETURN_PTR report_fn usage_routine = usage_builtin;
+static NORETURN_PTR report_fn die_routine = die_builtin;
+static report_fn error_routine = error_builtin;
+static report_fn warn_routine = warn_builtin;
static int (*die_is_recursing)(void) = die_is_recursing_builtin;
-void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params))
+void set_die_routine(NORETURN_PTR report_fn routine)
{
die_routine = routine;
}
-void set_error_routine(void (*routine)(const char *err, va_list params))
+void set_error_routine(report_fn routine)
{
error_routine = routine;
}
-void (*get_error_routine(void))(const char *err, va_list params)
+report_fn get_error_routine(void)
{
return error_routine;
}
-void set_warn_routine(void (*routine)(const char *warn, va_list params))
+void set_warn_routine(report_fn routine)
{
warn_routine = routine;
}
-void (*get_warn_routine(void))(const char *warn, va_list params)
+report_fn get_warn_routine(void)
{
return warn_routine;
}