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

From: Steven Rostedt
Date: Sat Dec 22 2018 - 12:25:00 EST


On Sat, 22 Dec 2018 12:23:35 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> On Sat, 22 Dec 2018 12:19:11 -0500
> Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> > Because memcmp() isn't required to test byte by byte. In fact, most
> > implementations don't which is why memcmp is faster than strcncmp.
>
> In fact, if memcmp() was safe to use if we only knew the size of one of
> the parameters, then there would be no reason for strncmp to exist.
>

Also, I believe there are some memcmp implementations that start at the
end of the memory locations, not the beginning. That is, it compares
backwards. Which is also legit for memcmp to do.

-- Steve