From 00db1f1ced38f39a058e137dfb4092c4443a3e8f Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Sun, 17 Sep 2006 08:29:05 +0000 Subject: [PATCH] Add function benc_strcmp. --- misc/benc.c | 19 +++++++++++++++++++ misc/benc.h | 2 ++ 2 files changed, 21 insertions(+) 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 #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) { diff --git a/misc/benc.h b/misc/benc.h index 38a0fba..df100a8 100644 --- a/misc/benc.h +++ b/misc/benc.h @@ -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);