Added ndn_memcmp
diff --git a/ndn-cpp/c/util/ndn_memory.c b/ndn-cpp/c/util/ndn_memory.c
index d0e8bf4..12ee131 100644
--- a/ndn-cpp/c/util/ndn_memory.c
+++ b/ndn-cpp/c/util/ndn_memory.c
@@ -5,6 +5,24 @@
#include "ndn_memory.h"
+#if !HAVE_MEMCMP
+int ndn_memcmp(unsigned char *buf1, unsigned char *buf2, unsigned int len)
+{
+ unsigned int i;
+
+ for (i = 0; i < len; i++) {
+ if (buf1[i] > buf2[i])
+ return 1;
+ else if (buf1[i] < buf2[i])
+ return -1;
+ }
+
+ return 0;
+}
+#else
+int ndn_memcmp_stub_to_avoid_empty_file_warning = 0;
+#endif
+
#if !HAVE_MEMCPY
void ndn_memcpy(unsigned char *dest, unsigned char *src, unsigned int len)
{
@@ -27,4 +45,4 @@
}
#else
int ndn_memset_stub_to_avoid_empty_file_warning = 0;
-#endif
\ No newline at end of file
+#endif
diff --git a/ndn-cpp/c/util/ndn_memory.h b/ndn-cpp/c/util/ndn_memory.h
index 378b6b7..a35ef89 100644
--- a/ndn-cpp/c/util/ndn_memory.h
+++ b/ndn-cpp/c/util/ndn_memory.h
@@ -16,6 +16,19 @@
extern "C" {
#endif
+#if HAVE_MEMCMP
+#include <memory.h>
+/**
+ * Use the library version of memcmp.
+ */
+static inline int ndn_memcmp(unsigned char *buf1, unsigned char *buf2, unsigned int len) { memcpy(buf1, buf2, len); }
+#else
+/**
+ * Use a local implementation of memcmp instead of the library version.
+ */
+int ndn_memcmp(unsigned char *buf1, unsigned char *buf2, unsigned int len);
+#endif
+
#if HAVE_MEMCPY
#include <memory.h>
/**