From: "Daniel P. Berrange" <berrange(a)redhat.com>
Add an API allowing flags from one virBitmapPtr to be copied
into another instance.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/libvirt_private.syms | 1 +
src/util/bitmap.c | 19 +++++++++++++++++++
src/util/bitmap.h | 6 ++++++
3 files changed, 26 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0494e1f..8dfb4ce 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -8,6 +8,7 @@
# bitmap.h
virBitmapAlloc;
virBitmapClearBit;
+virBitmapCopy;
virBitmapFree;
virBitmapGetBit;
virBitmapSetBit;
diff --git a/src/util/bitmap.c b/src/util/bitmap.c
index 53a8a38..cd52802 100644
--- a/src/util/bitmap.c
+++ b/src/util/bitmap.c
@@ -93,6 +93,25 @@ void virBitmapFree(virBitmapPtr bitmap)
}
}
+
+int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src)
+{
+ size_t sz;
+
+ if (dst->size != src->size) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ sz = (src->size + VIR_BITMAP_BITS_PER_UNIT - 1) /
+ VIR_BITMAP_BITS_PER_UNIT;
+
+ memcpy(dst->map, src->map, sz * sizeof(src->map[0]));
+
+ return 0;
+}
+
+
/**
* virBitmapSetBit:
* @bitmap: Pointer to bitmap
diff --git a/src/util/bitmap.h b/src/util/bitmap.h
index c3e6222..1d8750e 100644
--- a/src/util/bitmap.h
+++ b/src/util/bitmap.h
@@ -42,6 +42,12 @@ virBitmapPtr virBitmapAlloc(size_t size) ATTRIBUTE_RETURN_CHECK;
void virBitmapFree(virBitmapPtr bitmap);
/*
+ * Copy all bits from @src to @dst. The bitmap sizes
+ * must be the same
+ */
+int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src);
+
+/*
* Set bit position @b in @bitmap
*/
int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
--
1.7.11.4