info->id = id;
/* Make space on list */
- n = list->count;
- if (VIR_REALLOC_N(list->doms, n + 1) < 0) {
+ if (VIR_APPEND_ELEMENT(list->doms, list->count, info) < 0)
goto error;
- }
- list->doms[n] = info;
- list->count++;
return 0;
error:
if (info)
VIR_FREE(list->doms[i]->name);
VIR_FREE(list->doms[i]);
- if (i < (list->count - 1))
- memmove(list->doms + i,
- list->doms + i + 1,
- sizeof(*(list->doms)) *
- (list->count - (i + 1)));
-
- if (VIR_REALLOC_N(list->doms,
- list->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- list->count--;
-
+ VIR_DELETE_ELEMENT(list->doms, i, list->count);
return 0;
}
}
typedef xenUnifiedDomainInfo *xenUnifiedDomainInfoPtr;
struct _xenUnifiedDomainInfoList {
- unsigned int count;
+ size_t count;
xenUnifiedDomainInfoPtr *doms;
};
typedef struct _xenUnifiedDomainInfoList xenUnifiedDomainInfoList;
VIR_FREE(priv->configInfoList->doms[i]->name);
VIR_FREE(priv->configInfoList->doms[i]);
- if (i < (priv->configInfoList->count - 1))
- memmove(priv->configInfoList->doms + i,
- priv->configInfoList->doms + i + 1,
- sizeof(*(priv->configInfoList->doms)) *
- (priv->configInfoList->count - (i + 1)));
-
- if (VIR_REALLOC_N(priv->configInfoList->doms,
- priv->configInfoList->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- priv->configInfoList->count--;
+ VIR_DELETE_ELEMENT(priv->configInfoList->doms, i,
+ priv->configInfoList->count);
return 0;
}
}
case VIR_DOMAIN_DEVICE_NET:
{
- if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0)
+ if (VIR_APPEND_ELEMENT(def->nets, def->nnets, dev->data.net) < 0)
goto cleanup;
- def->nets[def->nnets++] = dev->data.net;
- dev->data.net = NULL;
break;
}
dev->data.disk->dst &&
STREQ(def->disks[i]->dst, dev->data.disk->dst)) {
virDomainDiskDefFree(def->disks[i]);
- if (i < (def->ndisks - 1))
- memmove(def->disks + i,
- def->disks + i + 1,
- sizeof(*def->disks) *
- (def->ndisks - (i + 1)));
- def->ndisks--;
+ VIR_DELETE_ELEMENT(def->disks, i, def->ndisks);
break;
}
}
for (i = 0; i < def->nnets; i++) {
if (!virMacAddrCmp(&def->nets[i]->mac, &dev->data.net->mac)) {
virDomainNetDefFree(def->nets[i]);
- if (i < (def->nnets - 1))
- memmove(def->nets + i,
- def->nets + i + 1,
- sizeof(*def->nets) *
- (def->nnets - (i + 1)));
- def->nnets--;
+ VIR_DELETE_ELEMENT(def->nets, i, def->nnets);
break;
}
}
VIR_STRDUP(watch->token, token) < 0)
goto error;
- /* Make space on list */
- n = list->count;
- if (VIR_REALLOC_N(list->watches, n + 1) < 0)
+ if (VIR_APPEND_ELEMENT_COPY(list->watches, list->count, watch) < 0)
goto error;
- list->watches[n] = watch;
- list->count++;
-
return xs_watch(priv->xshandle, watch->path, watch->token);
error:
VIR_FREE(list->watches[i]->token);
VIR_FREE(list->watches[i]);
- if (i < (list->count - 1))
- memmove(list->watches + i,
- list->watches + i + 1,
- sizeof(*(list->watches)) *
- (list->count - (i + 1)));
-
- if (VIR_REALLOC_N(list->watches,
- list->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- list->count--;
+ VIR_DELETE_ELEMENT(list->watches, i, list->count);
return 0;
}
}
typedef xenStoreWatch *xenStoreWatchPtr;
struct _xenStoreWatchList {
- unsigned int count;
+ size_t count;
xenStoreWatchPtr *watches;
};
typedef struct _xenStoreWatchList xenStoreWatchList;