Fix bug in new bcmp() function

Was revealed by ndk-build, ie, on a system with HAVE_BCMP false
This commit is contained in:
Andrew Bettison 2013-05-21 12:45:33 +09:30
parent f8386d5aed
commit 630c7cd57d

10
os.h
View File

@ -70,8 +70,14 @@ __SERVALDNA_OS_INLINE void bcopy(void *src, void *dst, size_t len) {
#endif
#ifndef HAVE_BCMP
__SERVALDNA_OS_INLINE int bcmp(const void *s1, const void *s2) {
return memcmp(s1, s2);
__SERVALDNA_OS_INLINE int bcmp(const void *s1, const void *s2, size_t n) {
// bcmp() is only an equality test, not an order test, so its return value
// is not specified as negative or positive, only non-zero. Hoewver
// memcmp() is an order test. We deliberately discard negative return
// values from memcmp(), to avoid misleading developers into assuming that
// bcmp() is an ordering operator and writing code that depends on that,
// which of course would fail on platforms with a native bcmp() function.
return memcmp(s1, s2, n) != 0;
}
#endif