Re: [for-next][PATCH 23/24] string.h: Add strncmp_prefix() helper macro
From: Steven Rostedt
Date: Fri Dec 21 2018 - 17:58:49 EST
On Fri, 21 Dec 2018 14:20:25 -0800
Joe Perches <joe@xxxxxxxxxxx> 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