xref: /openbsd-src/gnu/lib/libiberty/src/memcmp.c (revision 150b7e42cfa21e6546d96ae514ca23e80d970ac7)
100bf4279Sespie /* memcmp -- compare two memory regions.
200bf4279Sespie    This function is in the public domain.  */
300bf4279Sespie 
400bf4279Sespie /*
500bf4279Sespie 
637c53322Sespie @deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, size_t @var{count})
700bf4279Sespie 
837c53322Sespie Compares the first @var{count} bytes of two areas of memory.  Returns
937c53322Sespie zero if they are the same, a value less than zero if @var{x} is
1037c53322Sespie lexically less than @var{y}, or a value greater than zero if @var{x}
1137c53322Sespie is lexically greater than @var{y}.  Note that lexical order is determined
1237c53322Sespie as if comparing unsigned char arrays.
1337c53322Sespie 
1437c53322Sespie @end deftypefn
1537c53322Sespie 
1600bf4279Sespie */
1700bf4279Sespie 
1800bf4279Sespie #include <ansidecl.h>
1900bf4279Sespie #include <stddef.h>
2000bf4279Sespie 
2100bf4279Sespie int
memcmp(const PTR str1,const PTR str2,size_t count)22*150b7e42Smiod memcmp (const PTR str1, const PTR str2, size_t count)
2300bf4279Sespie {
24f5dd06f4Sespie   register const unsigned char *s1 = (const unsigned char*)str1;
25f5dd06f4Sespie   register const unsigned char *s2 = (const unsigned char*)str2;
2600bf4279Sespie 
2700bf4279Sespie   while (count-- > 0)
2800bf4279Sespie     {
2900bf4279Sespie       if (*s1++ != *s2++)
3000bf4279Sespie 	  return s1[-1] < s2[-1] ? -1 : 1;
3100bf4279Sespie     }
3200bf4279Sespie   return 0;
3300bf4279Sespie }
3400bf4279Sespie 
35