133965Sjdp/* memcmp -- compare two memory regions.
233965Sjdp   This function is in the public domain.  */
333965Sjdp
433965Sjdp/*
533965Sjdp
689857Sobrien@deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, size_t @var{count})
733965Sjdp
889857SobrienCompares the first @var{count} bytes of two areas of memory.  Returns
989857Sobrienzero if they are the same, a value less than zero if @var{x} is
1089857Sobrienlexically less than @var{y}, or a value greater than zero if @var{x}
1189857Sobrienis lexically greater than @var{y}.  Note that lexical order is determined
1289857Sobrienas if comparing unsigned char arrays.
1389857Sobrien
1489857Sobrien@end deftypefn
1589857Sobrien
1633965Sjdp*/
1733965Sjdp
1833965Sjdp#include <ansidecl.h>
1933965Sjdp#include <stddef.h>
2033965Sjdp
2133965Sjdpint
22218822Sdimmemcmp (const PTR str1, const PTR str2, size_t count)
2333965Sjdp{
2477298Sobrien  register const unsigned char *s1 = (const unsigned char*)str1;
2577298Sobrien  register const unsigned char *s2 = (const unsigned char*)str2;
2633965Sjdp
2733965Sjdp  while (count-- > 0)
2833965Sjdp    {
2933965Sjdp      if (*s1++ != *s2++)
3033965Sjdp	  return s1[-1] < s2[-1] ? -1 : 1;
3133965Sjdp    }
3233965Sjdp  return 0;
3333965Sjdp}
3433965Sjdp
35