lkml.org 
[lkml]   [2018]   [Dec]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4] string.h: Add str_has_prefix() helper function
On Sat, Dec 22, 2018 at 12:24:54PM -0500, Steven Rostedt wrote:
> On Sat, 22 Dec 2018 12:23:35 -0500
> Steven Rostedt <rostedt@goodmis.org> wrote:
>
> > On Sat, 22 Dec 2018 12:19:11 -0500
> > Steven Rostedt <rostedt@goodmis.org> 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.

I'm not sure, the man page says:

RETURN VALUE
The memcmp() function returns an integer less than, equal to,
or greater than zero if the first n bytes of s1 is found,
respectively, to be less than, to match, or be greater than
the first n bytes of s2.

For a nonzero return value, the sign is determined by the sign
of the difference between the first pair of bytes (interpreted
as unsigned char) that differ in s1 and s2.

If n is zero, the return value is zero.


It should return difference in the first pair of bytes that differ so
I guess implementations should compare from the beginning.

Thanks,
Namhyung

\
 
 \ /
  Last update: 2022-09-17 16:05    [W:0.085 / U:0.468 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site