Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro

Steven Rostedt
2018-12-21T22:55:19Z

On Fri, 21 Dec 2018 14:20:25 -0800
Joe Perches <joe@perches.com> wrote:

> static inline bool str_has_prefix(const char *str, const char prefix[])
> {
> return !strncmp(str, prefix, strlen(prefix));
> }
>
> eliminates the strlen with gcc 4.8 (oldest I still have)

I tested it a bit more before posting.

I tested it against:

gcc 4.5.1, 4.5.4, 4.6.3, 6.2.0, 7.2.0 and 8.2

And the strlen was eliminated each time.

So this looks like the right approach :-)

-- Steve