Re: [PATCH/RFC] split_cmdline: Allow caller to access error string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greg Brockman <gdb@xxxxxxx> 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 <gdb@xxxxxxx>
> ---

> 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.

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]