int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list,
int idx);
-int virPCIDeviceListCount(virPCIDeviceListPtr list);
+size_t virPCIDeviceListCount(virPCIDeviceListPtr list);
virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list,
virPCIDevicePtr dev);
virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list,
struct _virSCSIDeviceList {
virObjectLockable parent;
- unsigned int count;
+ size_t count;
virSCSIDevicePtr *devs;
};
return -1;
}
- if (VIR_REALLOC_N(list->devs, list->count + 1) < 0)
- return -1;
-
- list->devs[list->count++] = dev;
-
- return 0;
+ return VIR_APPEND_ELEMENT(list->devs, list->count, dev);
}
virSCSIDevicePtr
return list->devs[idx];
}
-int
+size_t
virSCSIDeviceListCount(virSCSIDeviceListPtr list)
{
return list->count;
size_t i;
for (i = 0; i < list->count; i++) {
- if (list->devs[i]->adapter != dev->adapter ||
- list->devs[i]->bus != dev->bus ||
- list->devs[i]->target != dev->target ||
- list->devs[i]->unit != dev->unit)
- continue;
-
- ret = list->devs[i];
-
- if (i != list->count--)
- memmove(&list->devs[i],
- &list->devs[i+1],
- sizeof(*list->devs) * (list->count - i));
-
- if (VIR_REALLOC_N(list->devs, list->count) < 0) {
- ; /* not fatal */
+ if (list->devs[i]->adapter == dev->adapter &&
+ list->devs[i]->bus == dev->bus &&
+ list->devs[i]->target == dev->target &&
+ list->devs[i]->unit == dev->unit) {
+ ret = list->devs[i];
+ VIR_DELETE_ELEMENT(list->devs, i, list->count);
+ break;
}
-
- break;
}
return ret;
virSCSIDevicePtr dev);
virSCSIDevicePtr virSCSIDeviceListGet(virSCSIDeviceListPtr list,
int idx);
-int virSCSIDeviceListCount(virSCSIDeviceListPtr list);
+size_t virSCSIDeviceListCount(virSCSIDeviceListPtr list);
virSCSIDevicePtr virSCSIDeviceListSteal(virSCSIDeviceListPtr list,
virSCSIDevicePtr dev);
void virSCSIDeviceListDel(virSCSIDeviceListPtr list,
virUSBDevicePtr dev);
virUSBDevicePtr virUSBDeviceListGet(virUSBDeviceListPtr list,
int idx);
-int virUSBDeviceListCount(virUSBDeviceListPtr list);
+size_t virUSBDeviceListCount(virUSBDeviceListPtr list);
virUSBDevicePtr virUSBDeviceListSteal(virUSBDeviceListPtr list,
virUSBDevicePtr dev);
void virUSBDeviceListDel(virUSBDeviceListPtr list,