1 1.1 christos /* memcmp -- compare two memory regions. 2 1.1 christos This function is in the public domain. */ 3 1.1 christos 4 1.1 christos /* 5 1.1 christos 6 1.1 christos @deftypefn Supplemental int memcmp (const void *@var{x}, const void *@var{y}, @ 7 1.1 christos size_t @var{count}) 8 1.1 christos 9 1.1 christos Compares the first @var{count} bytes of two areas of memory. Returns 10 1.1 christos zero if they are the same, a value less than zero if @var{x} is 11 1.1 christos lexically less than @var{y}, or a value greater than zero if @var{x} 12 1.1 christos is lexically greater than @var{y}. Note that lexical order is determined 13 1.1 christos as if comparing unsigned char arrays. 14 1.1 christos 15 1.1 christos @end deftypefn 16 1.1 christos 17 1.1 christos */ 18 1.1 christos 19 1.1 christos #include <ansidecl.h> 20 1.1 christos #include <stddef.h> 21 1.1 christos 22 1.1 christos int 23 1.1.1.2 christos memcmp (const void *str1, const void *str2, size_t count) 24 1.1 christos { 25 1.1 christos register const unsigned char *s1 = (const unsigned char*)str1; 26 1.1 christos register const unsigned char *s2 = (const unsigned char*)str2; 27 1.1 christos 28 1.1 christos while (count-- > 0) 29 1.1 christos { 30 1.1 christos if (*s1++ != *s2++) 31 1.1 christos return s1[-1] < s2[-1] ? -1 : 1; 32 1.1 christos } 33 1.1 christos return 0; 34 1.1 christos } 35 1.1 christos 36