diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/szstr.h | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/common/szstr.h b/src/common/szstr.h index 54beb9a..d73e489 100644 --- a/src/common/szstr.h +++ b/src/common/szstr.h @@ -29,6 +29,9 @@ #include <sys/types.h> +#include "sort.h" + + /* Structure associant une chaƮne et sa taille */ typedef struct _sized_string_t @@ -66,9 +69,28 @@ typedef struct _sized_string_t } \ } \ while (0) - -#define szstrcmp(ss, rs) \ - strncmp((ss)->data, (rs)/*->data*/, (ss)->len) + +#define szstrcmp(s1, s2) \ + ({ \ + int __ret; \ + size_t __n; \ + __n = (s1)->len < (s2)->len ? (s1)->len : (s2)->len; \ + __ret = strncmp((s1)->data, (s2)->data, __n); \ + if (__ret == 0) \ + __ret = sort_unsigned_long_long((s1)->len, (s2)->len); \ + __ret; \ + }) + +#define szmemcmp(s1, s2) \ + ({ \ + int __ret; \ + size_t __n; \ + __n = (s1)->len < (s2)->len ? (s1)->len : (s2)->len; \ + __ret = memcmp((s1)->data, (s2)->data, __n); \ + if (__ret == 0) \ + __ret = sort_unsigned_long_long((s1)->len, (s2)->len); \ + __ret; \ + }) |