From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: Chaitanya S Prakash <ChaitanyaS.Prakash@arm.com>
Cc: linux-perf-users@vger.kernel.org, anshuman.khandual@arm.com,
james.clark@arm.com,
Chaitanya S Prakash <chaitanyas.prakash@arm.com>
Subject: Re: [PATCH V2 4/8] tools lib: Adopt str_has_prefix() from kernel
Date: Tue, 9 Apr 2024 08:33:59 +0900 [thread overview]
Message-ID: <20240409083359.e02be97c6a19ef2a5014e894@kernel.org> (raw)
In-Reply-To: <20240408062230.1949882-5-ChaitanyaS.Prakash@arm.com>
On Mon, 8 Apr 2024 11:52:26 +0530
Chaitanya S Prakash <ChaitanyaS.Prakash@arm.com> wrote:
> From: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
>
> Add str_has_prefix() to tools/include with the intention to replace
> strstarts().
>
> Signed-off-by: Chaitanya S Prakash <chaitanyas.prakash@arm.com>
> ---
> tools/include/linux/string.h | 2 ++
> tools/lib/string.c | 16 ++++++++++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
> index e43c8f78d63c..e02292fa1fab 100644
> --- a/tools/include/linux/string.h
> +++ b/tools/include/linux/string.h
> @@ -44,6 +44,8 @@ static inline bool strstarts(const char *str, const char *prefix)
>
> size_t str_has_suffix(const char *str, const char *suffix);
>
> +size_t str_has_prefix(const char *str, const char *prefix);
> +
> extern char * __must_check skip_spaces(const char *);
>
> extern char *strim(char *);
> diff --git a/tools/lib/string.c b/tools/lib/string.c
> index 9cb515048239..76b15ee6493e 100644
> --- a/tools/lib/string.c
> +++ b/tools/lib/string.c
> @@ -252,3 +252,19 @@ size_t str_has_suffix(const char *str, const char *suffix)
>
> return suffix_len;
> }
> +
> +/**
> + * str_has_prefix - Test is a string has a given prefix
> + * @str: The string to be tested
> + * @prefix: The string to see if @str starts with
> + *
> + * Returns:
> + * * strlen(@prefix) if @str starts with @prefix
> + * * 0 if @str does not start with @prefix
Here, too. Is there any reason to return strlen(@prefix)?
Thank you,
> + */
> +size_t str_has_prefix(const char *str, const char *prefix)
> +{
> + size_t prefix_len = strlen(prefix);
> +
> + return strncmp(str, prefix, prefix_len) == 0 ? prefix_len : 0;
> +}
> --
> 2.30.2
>
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2024-04-08 23:34 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-08 6:22 [PATCH V2 0/8] perf tools: Fix test "perf probe of function from different CU" Chaitanya S Prakash
2024-04-08 6:22 ` Chaitanya S Prakash
2024-04-08 6:22 ` [PATCH V2 1/8] tools lib: adopt str_has_suffix() from bpftool/gen.c Chaitanya S Prakash
2024-04-08 23:32 ` Masami Hiramatsu
2024-04-11 12:15 ` Chaitanya S Prakash
2024-04-11 15:41 ` Arnaldo Carvalho de Melo
2024-04-08 6:22 ` [PATCH V2 2/8] perf util: Delete ends_with() and replace its use with str_has_suffix() Chaitanya S Prakash
2024-04-08 6:22 ` [PATCH V2 3/8] perf util: Replace an instance of strtailcmp() by str_has_suffix() Chaitanya S Prakash
2024-04-08 23:20 ` Masami Hiramatsu
2024-04-08 6:22 ` [PATCH V2 4/8] tools lib: Adopt str_has_prefix() from kernel Chaitanya S Prakash
2024-04-08 23:33 ` Masami Hiramatsu [this message]
2024-04-08 6:22 ` [PATCH V2 5/8] tools: Delete strstarts() and replace its usage with str_has_prefix() Chaitanya S Prakash
2024-04-08 6:22 ` [PATCH V2 6/8] perf tools: Enable configs required for test_uprobe_from_different_cu.sh Chaitanya S Prakash
2024-04-08 23:11 ` Masami Hiramatsu
2024-04-16 21:19 ` Arnaldo Carvalho de Melo
2024-04-08 6:22 ` [PATCH V2 7/8] perf tools: Only treat files as map files when they have the extension .map Chaitanya S Prakash
2024-04-09 10:21 ` James Clark
2024-04-08 6:22 ` [PATCH V2 8/8] perf test: Check output of the probe ... --funcs command Chaitanya S Prakash
2024-04-08 23:09 ` Masami Hiramatsu
2024-04-16 21:22 ` Arnaldo Carvalho de Melo
2024-04-17 18:26 ` Arnaldo Carvalho de Melo
2024-04-23 11:53 ` Chaitanya S Prakash
2024-04-09 5:32 ` [PATCH V2 0/8] perf tools: Fix test "perf probe of function from different CU" Alexey Dobriyan
2024-04-09 5:32 ` Alexey Dobriyan
2024-04-11 12:10 ` Chaitanya S Prakash
2024-04-11 12:10 ` Chaitanya S Prakash
2024-04-14 11:41 ` Alexey Dobriyan
2024-04-14 11:41 ` Alexey Dobriyan
2024-04-17 13:24 ` James Clark
2024-04-17 13:24 ` James Clark
2024-04-17 13:39 ` Arnaldo Carvalho de Melo
2024-04-17 13:39 ` Arnaldo Carvalho de Melo
2024-04-10 3:34 ` Chaitanya S Prakash
2024-04-10 3:34 ` Chaitanya S Prakash
2024-04-11 18:49 ` Arnaldo Carvalho de Melo
2024-04-11 18:49 ` Arnaldo Carvalho de Melo
-- strict thread matches above, loose matches on Subject: below --
2024-04-17 4:19 [PATCH V2 5/8] tools: Delete strstarts() and replace its usage with str_has_prefix() kernel test robot
2024-04-18 7:32 ` kernel test robot
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=20240409083359.e02be97c6a19ef2a5014e894@kernel.org \
--to=mhiramat@kernel.org \
--cc=ChaitanyaS.Prakash@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=james.clark@arm.com \
--cc=linux-perf-users@vger.kernel.org \
/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.