struct _virPCIDeviceList {
virObjectLockable parent;
- unsigned int count;
+ size_t count;
virPCIDevicePtr *devs;
};
_("Device %s is already in use"), dev->name);
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, true);
}
return NULL;
ret = list->devs[idx];
-
- if (idx != --list->count) {
- memmove(&list->devs[idx],
- &list->devs[idx + 1],
- sizeof(*list->devs) * (list->count - idx));
- }
-
- if (VIR_REALLOC_N(list->devs, list->count) < 0) {
- ; /* not fatal */
- }
-
+ VIR_DELETE_ELEMENT(list->devs, idx, list->count);
return ret;
}
struct _virUSBDeviceList {
virObjectLockable parent;
- unsigned int count;
+ size_t count;
virUSBDevicePtr *devs;
};
dev->name);
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, true);
}
virUSBDevicePtr
size_t i;
for (i = 0; i < list->count; i++) {
- if (list->devs[i]->bus != dev->bus ||
- list->devs[i]->dev != dev->dev)
- 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]->bus == dev->bus &&
+ list->devs[i]->dev == dev->dev) {
+ ret = list->devs[i];
+ VIR_DELETE_ELEMENT(list->devs, i, list->count);
+ break;
}
-
- break;
}
return ret;
}