diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0494e1f525bb4b203f2625e6e5b98023f1364716..8dfb4cee99ba16ae28f1ad7dc2b0e3a67a425866 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 53a8a3875c6cc88471aa01e85284a54de1595472..cd52802facc290e2bdd908e9d2314b057e375690 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 c3e6222b745d42021d14f707dcb19ec43219c3de..1d8750e8b094bd468bc552670c9f940254e8b681 100644 --- a/src/util/bitmap.h +++ b/src/util/bitmap.h @@ -41,6 +41,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 */