Add a virBitmapCopy API

Add an API allowing flags from one virBitmapPtr to be copied
into another instance.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-09-06 16:09:32 +01:00
parent 203ab129af
commit d2fdeb3b1e
3 changed files with 26 additions and 0 deletions

View File

@ -8,6 +8,7 @@
# bitmap.h
virBitmapAlloc;
virBitmapClearBit;
virBitmapCopy;
virBitmapFree;
virBitmapGetBit;
virBitmapSetBit;

View File

@ -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

View File

@ -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
*/