Author: infinoid
Date: Wed Jan  7 22:53:19 2009
New Revision: 35190

Modified:
   trunk/src/charset/binary.c

Log:
Make a first stab at implementing compare() for the binary charset plugin.

Modified: trunk/src/charset/binary.c
==============================================================================
--- trunk/src/charset/binary.c  (original)
+++ trunk/src/charset/binary.c  Wed Jan  7 22:53:19 2009
@@ -345,17 +345,22 @@
 
 =item C<static INTVAL compare>
 
-Returns 0. We can't directly compare two binary buffers (yet).
+Compare the two buffers, first by size, then with memcmp.
 
 =cut
 
 */
 
 static INTVAL
-compare(SHIM_INTERP, SHIM(const STRING *lhs), SHIM(const STRING *rhs))
+compare(SHIM_INTERP, ARGIN(const STRING *lhs), ARGIN(const STRING *rhs))
 {
     ASSERT_ARGS(compare)
-    return 0;
+    const UINTVAL l_len = lhs->strlen;
+    const UINTVAL r_len = rhs->strlen;
+    if (l_len != r_len)
+        return l_len - r_len;
+
+    return memcmp(lhs->strstart, rhs->strstart, l_len);
 }
 
 /*

Reply via email to