From 8ef5c655fd12f2d964bb72a9df0f3d2295a8580c Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 1 Oct 2023 03:56:57 +0300 Subject: [PATCH 20/20] Add bv_match_dbv() utility function See osdn #48771 Signed-off-by: Marko Lindqvist --- utility/bitvector.c | 18 ++++++++++++++++++ utility/bitvector.h | 1 + 2 files changed, 19 insertions(+) diff --git a/utility/bitvector.c b/utility/bitvector.c index ae41172ab0..468e195cf2 100644 --- a/utility/bitvector.c +++ b/utility/bitvector.c @@ -198,6 +198,24 @@ bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2) _BV_BYTES(pdbv2->bits)); } +/*************************************************************************** + Is content of static bitvector same as that of dynamic one. + Comparison size is taken from the dynamic one. +***************************************************************************/ +bool bv_match_dbv(const struct dbv *match, const unsigned char *src) +{ + size_t bytes = _BV_BYTES(match->bits); + int i; + + for (i = 0; i < bytes; i++) { + if (match->vec[i] != src[i]) { + return FALSE; + } + } + + return TRUE; +} + /*************************************************************************** Copy dynamic bit vector content from another. ***************************************************************************/ diff --git a/utility/bitvector.h b/utility/bitvector.h index 9ce4230853..7c0879a4cf 100644 --- a/utility/bitvector.h +++ b/utility/bitvector.h @@ -50,6 +50,7 @@ void dbv_clr(struct dbv *pdbv, int bit); void dbv_clr_all(struct dbv *pdbv); bool dbv_are_equal(const struct dbv *pdbv1, const struct dbv *pdbv2); +bool bv_match_dbv(const struct dbv *match, const unsigned char *src); void dbv_copy(struct dbv *dest, const struct dbv *src); void dbv_to_bv(unsigned char *dest, const struct dbv *src); -- 2.40.1