From: "liwei (GF)" <liwei391@huawei.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
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: Fri, 25 Mar 2022 10:06:47 +0800 [thread overview]
Message-ID: <da8c82ac-3895-f4ef-9887-dae9ba80787a@huawei.com> (raw)
In-Reply-To: <Yjo+MdJaauraN6eX@kernel.org>
On 2022/3/23 5:22, Arnaldo Carvalho de Melo wrote:
> 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.
>
Sorry, i haven't known that before, will use strstarts() in v2.
Thanks,
Wei
>
>> 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
>
next prev parent reply other threads:[~2022-03-25 2:10 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
2022-03-25 2:06 ` liwei (GF) [this message]
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=da8c82ac-3895-f4ef-9887-dae9ba80787a@huawei.com \
--to=liwei391@huawei.com \
--cc=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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®