Re: [PATCH v3] string.h: Add str_has_prefix() helper

From: Steven Rostedt
Date: Fri Dec 21 2018 - 19:06:34 EST


On Fri, 21 Dec 2018 18:13:16 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> +static __always_inline int str_has_prefix(const char *str, const char *prefix)

I'm thinking it is cleaner to have two helper functions and have them
both return bool.

static __always_inline bool str_has_prefix(const char *str, const char *prefix)
{
return !strncmp(str, prefix, strlen(prefix));
}

( I still like to keep the __always_inline, it doesn't hurt )

And I'll make a separate patch that adds:

static __always_inline bool
str_has_prefix_len(const char *str, const char *prefix, unsigned int *len)
{
*len = strlen(prefix);
return !strncmp(str, prefix, *len) ? *len : 0;
}

Everyone OK with that?

-- Steve