From f1d7b2ae5340098206c4200163f1b6b7e7725c79 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Sat, 2 Jul 2016 06:44:55 +0300 Subject: [PATCH] sxt: sxtrdb_cmp() added; --- include/sxt/rdb.h | 3 +++ sxt/rdb.c | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/include/sxt/rdb.h b/include/sxt/rdb.h index ee84bb9..fc73d10 100644 --- a/include/sxt/rdb.h +++ b/include/sxt/rdb.h @@ -145,6 +145,9 @@ void sxtrdb_exflags(sxtrdb_t *, int); /* reset all the flags */ #define sxtrdb_flagsreset(a) sxtrdb_exflags((a), 0) +/* compare buffers, returns 0 if equal */ +int sxtrdb_cmp(sxtrdb_t *, sxtrdb_t *); + /* let the buffer to use actually used bytes, not all allocated space * will return SXT_SUCCESS on success (or in case if it doesn't required), * SXT_ENOMEM or other error if fails diff --git a/sxt/rdb.c b/sxt/rdb.c index e2c2ffc..e39edf5 100644 --- a/sxt/rdb.c +++ b/sxt/rdb.c @@ -692,6 +692,22 @@ int sxtrdb_setlength(sxtrdb_t *b, uint32_t s) return SXT_SUCCESS; } +/* compare buffers, returns 0 if equal */ +int sxtrdb_cmp(sxtrdb_t *b1, sxtrdb_t *b2) +{ + int c = 0; + + if(!b1 | !b2) return -1; + + if((c = sxtrdb_length(b1) - sxtrdb_length(b2)) != 0) return c; + else c = memcmp((const void *)sxtrdb_rdata(b1), + (const void *)sxtrdb_rdata(b2), + sxtrdb_length(b1)); + + return c; +} + + /* let the buffer to use actually used bytes, not all allocated space * will return SXT_SUCCESS on success (or in case if it doesn't required), * SXT_ENOMEM or other error if fails