CONTENTS | INDEX | PREV | NEXT

 cmpmem
 memcmp
 bcmp 

 NAME
  cmpmem  - compare two memory buffers
  memcmp  - compare two memory buffers (ANSI)
  bcmp    - compare two memory buffers (UNIX)

 SYNOPSIS
  int r = cmpmem(s1, s2, bytes)
  int r = memcmp(s1, s2, bytes)
  int r = bcmp(s1, s2, bytes)
  void *s1;
  void *s2;
  size_t bytes;

 FUNCTION
  compare two memory buffers.  A byte by byte (unsigned) compare is
  done.  When a compare fails and the byte in s1 is less than the
  byte in s2 then -1 is returned.  If the byte in s1 is greater than
  the byte in s2 then 1 is returned.

  If the count is exhausted and all compares succeed then 0 is
  returned indicating the two buffers are the same.

 EXAMPLE
  #include <stdlib.h>
  #include <assert.h>

  main()
  {
      unsigned char buf1[4];
      unsigned char buf2[4];
      int r;

      buf1[0] = 0;    buf2[0] = 0;
      buf1[1] = 10;   buf2[1] = 10;
      buf1[2] = 15;   buf2[2] = 15;
      buf1[3] = 4;    buf2[3] = 4;

      r = memcmp(buf1, buf2, 4);
      assert(r == 0);

      buf1[2] = 12;
      r = memcmp(buf1, buf2, 4);
      assert(r < 0);

      buf1[2] = 200;
      r = memcmp(buf1, buf2, 4);
      assert(r > 0);
      return(0);
  }

 INPUTS
  void *s1;       pointer to first buffer
  void *s2;       pointer to second buffer
  size_t bytes;       size of each buffer

 RESULTS
  int r;          -1 if buf s1 < buf s2, 0 if buf s1 == buf s2,
              1 if buf s1 > buf s2.