From: Wei Li <liwei391@huawei.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>
Cc: <linux-perf-users@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <rui.xiang@huawei.com>
Subject: [PATCH 1/2] perf string: Add strcmp_prefix()
Date: Fri, 31 Dec 2021 14:30:43 +0800 [thread overview]
Message-ID: <20211231063044.2405691-2-liwei391@huawei.com> (raw)
In-Reply-To: <20211231063044.2405691-1-liwei391@huawei.com>
Add a helper to check whether a string has the given prefix.
This function is stolen from fs/xattr.c
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:[~2021-12-31 6:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-31 6:30 [PATCH 0/2] perf tools: Fix mis-matching of perf sub-commands Wei Li
2021-12-31 6:30 ` Wei Li [this message]
2021-12-31 6:30 ` [PATCH 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=20211231063044.2405691-2-liwei391@huawei.com \
--to=liwei391@huawei.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).