Re: [PATCH/RFC] split_cmdline: Allow caller to access error string
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:49:17
Greg Brockman [off-list ref] writes:
This allows the caller to add its own error message to that returned by split_cmdline. Thus error output following a failed split_cmdline can be of the form fatal: Bad alias.test string: cmdline ends with \ rather than error: cmdline ends with \ fatal: Bad alias.test string Signed-off-by: Greg Brockman <redacted> ---
quoted hunk ↗ jump to hunk
diff --git a/alias.c b/alias.c index 372b7d8..6f771cb 100644 --- a/alias.c +++ b/alias.c@@ -1,7 +1,9 @@... +#define SPLIT_CMDLINE_BAD_ENDING 1 +#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2 +static const char *split_cmdline_errors = { "cmdline ends with \\", "unclosed quote" }; ...@@ -53,7 +55,7 @@ int split_cmdline(char *cmdline, const char ***argv) if (!c) { free(*argv); *argv = NULL; - return error("cmdline ends with \\"); + return -SPLIT_CMDLINE_BAD_ENDING; } } cmdline[dst++] = c;...@@ -75,3 +77,6 @@ int split_cmdline(char *cmdline, const char ***argv) return count; } +const char *split_cmdline_strerror(int split_cmdline_errno) { + return split_cmdline_errors[-split_cmdline_errno-1]; +}
Looks like a reasonable way to go. Thanks.