Re: [PATCH 2/4] quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array

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

 



Christian Couder <chriscool@xxxxxxxxxxxxx> writes:

> This new function unwraps the space separated shell quoted elements in
> its first argument and put a copy of them in the argv array passed as
> its second argument.
>
> Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
> ---
>  quote.c |   17 +++++++++++++++++
>  quote.h |    2 ++
>  2 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/quote.c b/quote.c
> index 8cf0ef4..5b12a4a 100644
> --- a/quote.c
> +++ b/quote.c
> @@ -120,6 +120,23 @@ char *sq_dequote(char *arg)
>  	return sq_dequote_many(arg, NULL);
>  }
>  
> +int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)
> +{
> +	char *next = arg;
> +
> +	if (!*arg)
> +		return 0;
> +	do {
> +		char *dequoted = sq_dequote_many(next, &next);
> +		if (!dequoted)
> +			return 1;

Usually we signal an error with a negative value, e.g. -1.

> +		ALLOC_GROW(*argv, *nr + 1, *alloc);
> +		(*argv)[(*nr)++] = xstrdup(dequoted);

The original sq_dequote() interface takes advantage of the fact that the
result of single-quote unquoting is always shorter than the original and
it can rewrite the argument in-place to return the result.  I would expect
dequote_step() to retain that trait and allow the caller to use its return
value without xstrdup().

But please do not send in replacements just yet.
--
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]

  Powered by Linux