about summary refs log tree commit diff
path: root/misc/benc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/benc.c')
-rw-r--r--misc/benc.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/misc/benc.c b/misc/benc.c
index 82ed79f..153e1a0 100644
--- a/misc/benc.c
+++ b/misc/benc.c
@@ -7,6 +7,7 @@
 #include <string.h>
 
 #include "benc.h"
+#include "subr.h"
 
 #define benc_safeset(out, val) if ((out) != NULL) *(out) = (val)
 
@@ -78,6 +79,24 @@ benc_validate_aux(const char *p, const char *end)
     return p;
 }
 
+int
+benc_strcmp(const char *str1, const char *str2)
+{
+    size_t len1, len2;
+    const char *cs1 = benc_mem(str1, &len1, NULL);
+    const char *cs2 = benc_mem(str2, &len2, NULL);
+    int test = strncmp(cs1, cs2, min(len1, len2));
+    if (test == 0) {
+        if (len1 == len2)
+            return 0;
+        else if (len1 < len2)
+            return -1;
+        else
+            return 1;
+    } else
+        return test;
+}
+
 size_t
 benc_strlen(const char *p)
 {