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