mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-30 01:47:24 +03:00
virDomainHostdev{Insert,Delete}: Replace VIR_REALLOC_N by VIR_{APPEND,DELETE}_ELEMENT
With this change the code gets shorter and more readable. Signed-off-by: Matthieu Coudron <mattator@gmail.com>
This commit is contained in:
parent
c5d09fbdd1
commit
8fc98ac8cf
@ -9868,10 +9868,8 @@ virDomainChrTargetTypeToString(int deviceType,
|
|||||||
int
|
int
|
||||||
virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr hostdev)
|
virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr hostdev)
|
||||||
{
|
{
|
||||||
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs + 1) < 0)
|
|
||||||
return -1;
|
return VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev);
|
||||||
def->hostdevs[def->nhostdevs++] = hostdev;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virDomainHostdevDefPtr
|
virDomainHostdevDefPtr
|
||||||
@ -9879,19 +9877,7 @@ virDomainHostdevRemove(virDomainDefPtr def, size_t i)
|
|||||||
{
|
{
|
||||||
virDomainHostdevDefPtr hostdev = def->hostdevs[i];
|
virDomainHostdevDefPtr hostdev = def->hostdevs[i];
|
||||||
|
|
||||||
if (def->nhostdevs > 1) {
|
VIR_DELETE_ELEMENT(def->hostdevs, i, def->nhostdevs);
|
||||||
memmove(def->hostdevs + i,
|
|
||||||
def->hostdevs + i + 1,
|
|
||||||
sizeof(*def->hostdevs) *
|
|
||||||
(def->nhostdevs - (i + 1)));
|
|
||||||
def->nhostdevs--;
|
|
||||||
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs) < 0) {
|
|
||||||
/* ignore, harmless */
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
VIR_FREE(def->hostdevs);
|
|
||||||
def->nhostdevs = 0;
|
|
||||||
}
|
|
||||||
return hostdev;
|
return hostdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user