1169695Skan/* memcmp -- compare two memory regions.
2169695Skan   This function is in the public domain.  */
3169695Skan
4169695Skan/*
5169695Skan
6169695Skan@deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, size_t @var{count})
7169695Skan
8169695SkanCompares the first @var{count} bytes of two areas of memory.  Returns
9169695Skanzero if they are the same, a value less than zero if @var{x} is
10169695Skanlexically less than @var{y}, or a value greater than zero if @var{x}
11169695Skanis lexically greater than @var{y}.  Note that lexical order is determined
12169695Skanas if comparing unsigned char arrays.
13169695Skan
14169695Skan@end deftypefn
15169695Skan
16169695Skan*/
17169695Skan
18169695Skan#include <ansidecl.h>
19169695Skan#include <stddef.h>
20169695Skan
21169695Skanint
22169695Skanmemcmp (const PTR str1, const PTR str2, size_t count)
23169695Skan{
24169695Skan  register const unsigned char *s1 = (const unsigned char*)str1;
25169695Skan  register const unsigned char *s2 = (const unsigned char*)str2;
26169695Skan
27169695Skan  while (count-- > 0)
28169695Skan    {
29169695Skan      if (*s1++ != *s2++)
30169695Skan	  return s1[-1] < s2[-1] ? -1 : 1;
31169695Skan    }
32169695Skan  return 0;
33169695Skan}
34169695Skan
35