www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000012

When Created: 07/16/1995 20:40:48
Against DJGPP version: 2.00.beta1
By whom: terra@diku.dk
Abstract: bcmp() return value
For the return value, the docs say

	"The number of bytes remaining when the first mismatch occurred,
	or zero if all bytes were equal."

[This should be clarified with "including the mismatching postition itself"
or something to that effect.]

Codewise bcmp() is implemented as an alias of memcmp() which has a different
return value system, so only the zeroness of the return value can be counted
on.  I have yet to see a program that uses more than the zeroness, but who
knows what kind of code is out there?

Solution added: 07/16/1995 20:43:45
By whom: terra@diku.dk
[untested code follows.]

#include <string.h>

int
bcmp(const void *s1, const void *s2, size_t n)
{
  if (n != 0)
  {
    const unsigned char *p1 = s1, *p2 = s2;

    do {
      if (*p1++ != *p2++)
	return n;
    } while (--n != 0);
  }
  return 0;
}

Fixed in version 2.00.beta3 on 08/22/1995 21:06:02
By whom: dj@delorie.com



  webmaster     delorie software   privacy  
  Copyright © 2010   by DJ Delorie     Updated Jul 2010