sxt: sxtrdb_cmp() added;

master
Alexander Vdolainen 8 years ago
parent 65e0837fdd
commit f1d7b2ae53

@ -145,6 +145,9 @@ void sxtrdb_exflags(sxtrdb_t *, int);
/* reset all the flags */ /* reset all the flags */
#define sxtrdb_flagsreset(a) sxtrdb_exflags((a), 0) #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 /* 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), * will return SXT_SUCCESS on success (or in case if it doesn't required),
* SXT_ENOMEM or other error if fails * SXT_ENOMEM or other error if fails

@ -692,6 +692,22 @@ int sxtrdb_setlength(sxtrdb_t *b, uint32_t s)
return SXT_SUCCESS; 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 /* 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), * will return SXT_SUCCESS on success (or in case if it doesn't required),
* SXT_ENOMEM or other error if fails * SXT_ENOMEM or other error if fails

Loading…
Cancel
Save