From: Felix Fietkau Date: Fri, 29 Jul 2016 08:58:55 +0000 (+0200) Subject: avl: add blob comparator function X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=72613ca2c8f9b9905c6372c1b19ecbcd7cace007;p=project%2Flibubox.git avl: add blob comparator function Signed-off-by: Felix Fietkau --- diff --git a/avl-cmp.c b/avl-cmp.c index 2d0acec..39c1f5b 100644 --- a/avl-cmp.c +++ b/avl-cmp.c @@ -15,6 +15,12 @@ */ #include #include "avl-cmp.h" +#include "blob.h" + +static inline int _min(int v1, int v2) +{ + return v1 < v2 ? v1 : v2; +} int avl_strcmp(const void *k1, const void *k2, void *ptr) @@ -22,3 +28,10 @@ avl_strcmp(const void *k1, const void *k2, void *ptr) return strcmp(k1, k2); } +int +avl_blobcmp(const void *k1, const void *k2, void *ptr) +{ + int len = _min(blob_raw_len(k1), blob_raw_len(k2)); + + return memcmp(k1, k2, len); +} diff --git a/avl-cmp.h b/avl-cmp.h index 5adb495..f97ae8d 100644 --- a/avl-cmp.h +++ b/avl-cmp.h @@ -17,5 +17,6 @@ #define __AVL_CMP_H int avl_strcmp(const void *k1, const void *k2, void *ptr); +int avl_blobcmp(const void *k1, const void *k2, void *ptr); #endif