Permalink
Browse files

Add function benc_strcmp.

  • Loading branch information...
1 parent ce0ef9d commit 00db1f1ced38f39a058e137dfb4092c4443a3e8f @rmn64k rmn64k committed Sep 17, 2006
Showing with 21 additions and 0 deletions.
  1. +19 −0 misc/benc.c
  2. +2 −0 misc/benc.h
View
@@ -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)
{
View
@@ -17,6 +17,8 @@ int benc_isdct(const char *p);
int benc_isint(const char *p);
int benc_isstr(const char *p);
+int benc_strcmp(const char *str1, const char *str2);
+
size_t benc_strlen(const char *p);
size_t benc_length(const char *p);
size_t benc_nelems(const char *p);

0 comments on commit 00db1f1

Please sign in to comment.