Helper function for making a copy of virCPUDefPtr

This commit is contained in:
Jiri Denemark 2010-03-23 09:34:04 +01:00
parent 661ae104c2
commit 284805e666
3 changed files with 41 additions and 0 deletions

View File

@ -67,6 +67,43 @@ virCPUDefFree(virCPUDefPtr def)
}
virCPUDefPtr
virCPUDefCopy(const virCPUDefPtr cpu)
{
virCPUDefPtr copy;
unsigned int i;
if (!cpu)
return NULL;
if (VIR_ALLOC(copy) < 0
|| (cpu->arch && !(copy->arch = strdup(cpu->arch)))
|| (cpu->model && !(copy->model = strdup(cpu->model)))
|| VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
goto no_memory;
copy->type = cpu->type;
copy->match = cpu->match;
copy->sockets = cpu->sockets;
copy->cores = cpu->cores;
copy->threads = cpu->threads;
copy->nfeatures = cpu->nfeatures;
for (i = 0; i < copy->nfeatures; i++) {
copy->features[i].policy = cpu->features[i].policy;
if (!(copy->features[i].name = strdup(cpu->features[i].name)))
goto no_memory;
}
return copy;
no_memory:
virReportOOMError();
virCPUDefFree(copy);
return NULL;
}
#ifndef PROXY
virCPUDefPtr
virCPUDefParseXML(const xmlNodePtr node,

View File

@ -83,6 +83,9 @@ struct _virCPUDef {
void
virCPUDefFree(virCPUDefPtr def);
virCPUDefPtr
virCPUDefCopy(const virCPUDefPtr cpu);
# ifndef PROXY
virCPUDefPtr
virCPUDefParseXML(const xmlNodePtr node,

View File

@ -90,6 +90,7 @@ virCPUDefParseXML;
virCPUDefFormat;
virCPUDefFormatBuf;
virCPUDefAddFeature;
virCPUDefCopy;
# datatypes.h