All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Wei Li <liwei391@huawei.com>
Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com,
	jolsa@redhat.com, namhyung@kernel.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	rui.xiang@huawei.com, guohanjun@huawei.com
Subject: Re: [PATCH RESEND 1/2] perf string: Add strcmp_prefix()
Date: Tue, 22 Mar 2022 18:22:57 -0300	[thread overview]
Message-ID: <Yjo+MdJaauraN6eX@kernel.org> (raw)
In-Reply-To: <20220318092245.2700489-2-liwei391@huawei.com>

Em Fri, Mar 18, 2022 at 05:22:44PM +0800, Wei Li escreveu:
> Add a helper to check whether a string has the given prefix.
> This function is stolen from fs/xattr.c

Can't you use strstarts()? See tools/include/linux/string.h.

- Arnaldo
 
> Signed-off-by: Wei Li <liwei391@huawei.com>
> ---
>  tools/perf/util/string.c  | 17 +++++++++++++++++
>  tools/perf/util/string2.h |  1 +
>  2 files changed, 18 insertions(+)
> 
> diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
> index f6d90cdd9225..0ed3e2d0b70f 100644
> --- a/tools/perf/util/string.c
> +++ b/tools/perf/util/string.c
> @@ -209,6 +209,23 @@ int strtailcmp(const char *s1, const char *s2)
>  	return 0;
>  }
>  
> +/**
> + * strcmp_prefix - check string for given prefix
> + * @str: the target string to check
> + * @prefix: the given prefix to match
> + *
> + * Return the rest string in @str if @str has the given @prefix, return NULL
> + * otherwise.
> + */
> +const char *strcmp_prefix(const char *str, const char *prefix)
> +{
> +	while (*prefix && *str == *prefix) {
> +		str++;
> +		prefix++;
> +	}
> +	return *prefix ? NULL : str;
> +}
> +
>  char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints)
>  {
>  	/*
> diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
> index 56c30fef9682..58929ad928f7 100644
> --- a/tools/perf/util/string2.h
> +++ b/tools/perf/util/string2.h
> @@ -20,6 +20,7 @@ static inline bool strisglob(const char *str)
>  	return strpbrk(str, "*?[") != NULL;
>  }
>  int strtailcmp(const char *s1, const char *s2);
> +const char *strcmp_prefix(const char *str, const char *prefix);
>  
>  char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
>  
> -- 
> 2.25.1

-- 

- Arnaldo

  reply	other threads:[~2022-03-22 21:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18  9:22 [PATCH RESEND 0/2] perf tools: Fix mis-matching of perf sub-commands Wei Li
2022-03-18  9:22 ` [PATCH RESEND 1/2] perf string: Add strcmp_prefix() Wei Li
2022-03-22 21:22   ` Arnaldo Carvalho de Melo [this message]
2022-03-25  2:06     ` liwei (GF)
2022-03-18  9:22 ` [PATCH RESEND 2/2] perf tools: Enhance the matching of sub-commands Wei Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yjo+MdJaauraN6eX@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=guohanjun@huawei.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=liwei391@huawei.com \
    --cc=mark.rutland@arm.com \
    --cc=namhyung@kernel.org \
    --cc=rui.xiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.