* do this before the config is loaded properly, since the port
* numbers are configurable now */
if ((qemu_driver->reservedRemotePorts =
- virBitmapAlloc(qemu_driver->remotePortMax - qemu_driver->remotePortMin)) == NULL)
+ virBitmapNew(qemu_driver->remotePortMax - qemu_driver->remotePortMin)) == NULL)
goto out_of_memory;
/* We should always at least have the 'nop' manager, so
struct _virBitmap {
- size_t size;
+ size_t max_bit;
+ size_t map_len;
unsigned long *map;
};
/**
- * virBitmapAlloc:
+ * virBitmapNew:
* @size: number of bits
*
* Allocate a bitmap capable of containing @size bits.
* Returns a pointer to the allocated bitmap or NULL if
* memory cannot be allocated.
*/
-virBitmapPtr virBitmapAlloc(size_t size)
+virBitmapPtr virBitmapNew(size_t size)
{
virBitmapPtr bitmap;
size_t sz;
return NULL;
}
- bitmap->size = size;
+ bitmap->max_bit = size;
+ bitmap->map_len = sz;
return bitmap;
}
* virBitmapFree:
* @bitmap: previously allocated bitmap
*
- * Free @bitmap previously allocated by virBitmapAlloc.
+ * Free @bitmap previously allocated by virBitmapNew.
*/
void virBitmapFree(virBitmapPtr bitmap)
{
int virBitmapCopy(virBitmapPtr dst, virBitmapPtr src)
{
- size_t sz;
-
- if (dst->size != src->size) {
+ if (dst->max_bit != src->max_bit) {
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]));
+ memcpy(dst->map, src->map, src->map_len * sizeof(src->map[0]));
return 0;
}
*/
int virBitmapSetBit(virBitmapPtr bitmap, size_t b)
{
- if (bitmap->size <= b)
+ if (bitmap->max_bit <= b)
return -1;
bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] |= VIR_BITMAP_BIT(b);
*/
int virBitmapClearBit(virBitmapPtr bitmap, size_t b)
{
- if (bitmap->size <= b)
+ if (bitmap->max_bit <= b)
return -1;
bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] &= ~VIR_BITMAP_BIT(b);
*/
int virBitmapGetBit(virBitmapPtr bitmap, size_t b, bool *result)
{
- if (bitmap->size <= b)
+ if (bitmap->max_bit <= b)
return -1;
*result = !!(bitmap->map[VIR_BITMAP_UNIT_OFFSET(b)] & VIR_BITMAP_BIT(b));
virBufferAddLit(&buf, "0x");
- sz = (bitmap->size + VIR_BITMAP_BITS_PER_UNIT - 1) /
- VIR_BITMAP_BITS_PER_UNIT;
+ sz = bitmap->map_len;
while (sz--) {
virBufferAsprintf(&buf, "%0*lx",