}
pciDevice *
-pciDeviceListSteal(pciDeviceList *list,
- pciDevice *dev)
+pciDeviceListStealIndex(pciDeviceList *list,
+ int idx)
{
- pciDevice *ret = NULL;
- int i;
-
- for (i = 0; i < list->count; i++) {
- if (list->devs[i]->domain != dev->domain ||
- list->devs[i]->bus != dev->bus ||
- list->devs[i]->slot != dev->slot ||
- list->devs[i]->function != dev->function)
- continue;
+ pciDevice *ret;
- ret = list->devs[i];
+ if (idx < 0 || idx >= list->count)
+ return NULL;
- if (i != --list->count)
- memmove(&list->devs[i],
- &list->devs[i+1],
- sizeof(*list->devs) * (list->count-i));
+ ret = list->devs[idx];
- if (VIR_REALLOC_N(list->devs, list->count) < 0) {
- ; /* not fatal */
- }
+ if (idx != --list->count) {
+ memmove(&list->devs[idx],
+ &list->devs[idx + 1],
+ sizeof(*list->devs) * (list->count - idx));
+ }
- break;
+ if (VIR_REALLOC_N(list->devs, list->count) < 0) {
+ ; /* not fatal */
}
+
return ret;
}
+pciDevice *
+pciDeviceListSteal(pciDeviceList *list,
+ pciDevice *dev)
+{
+ return pciDeviceListStealIndex(list, pciDeviceListFindIndex(list, dev));
+}
+
void
pciDeviceListDel(pciDeviceList *list,
pciDevice *dev)
pciFreeDevice(ret);
}
-pciDevice *
-pciDeviceListFind(pciDeviceList *list, pciDevice *dev)
+int
+pciDeviceListFindIndex(pciDeviceList *list, pciDevice *dev)
{
int i;
list->devs[i]->bus == dev->bus &&
list->devs[i]->slot == dev->slot &&
list->devs[i]->function == dev->function)
- return list->devs[i];
- return NULL;
+ return i;
+ return -1;
+}
+
+pciDevice *
+pciDeviceListFind(pciDeviceList *list, pciDevice *dev)
+{
+ int i;
+
+ if ((i = pciDeviceListFindIndex(list, dev)) >= 0)
+ return list->devs[i];
+ else
+ return NULL;
}
int pciDeviceListCount (pciDeviceList *list);
pciDevice * pciDeviceListSteal (pciDeviceList *list,
pciDevice *dev);
+pciDevice * pciDeviceListStealIndex(pciDeviceList *list,
+ int idx);
void pciDeviceListDel (pciDeviceList *list,
pciDevice *dev);
pciDevice * pciDeviceListFind (pciDeviceList *list,
pciDevice *dev);
+int pciDeviceListFindIndex(pciDeviceList *list,
+ pciDevice *dev);
/*
* Callback that will be invoked once for each file