CoInitialize(NULL);
- if (virAsprintf(&mbsVirtualBoxIID, "{%s}", pszVirtualBoxIID) < 0 ||
- virAsprintf(&mbsSessionIID, "{%s}", pszSessionIID) < 0)
+ mbsVirtualBoxIID = g_strdup_printf("{%s}", pszVirtualBoxIID);
+ mbsSessionIID = g_strdup_printf("{%s}", pszSessionIID)
goto cleanup;
if (vboxUtf8ToUtf16(mbsVirtualBoxIID, &wcsVirtualBoxIID) < 0 ||
PFNVBOXGETXPCOMCFUNCTIONS pfnGetFunctions;
if (dir != NULL) {
- if (virAsprintf(&name, "%s/%s", dir, DYNLIB_NAME) < 0)
- return -1;
+ name = g_strdup_printf("%s/%s", dir, DYNLIB_NAME);
if (!virFileExists(name)) {
if (!ignoreMissing)
/* Zero pad for nice alignment when fewer than 9999
* devices.
*/
- if (virAsprintf(&filtername, "filter%04zu", i) >= 0) {
- VBOX_UTF8_TO_UTF16(filtername, &filternameUtf16);
- VIR_FREE(filtername);
- gVBoxAPI.UIUSBCommon.CreateDeviceFilter(USBCommon,
- filternameUtf16,
- &filter);
- }
+ filtername = g_strdup_printf("filter%04zu", i);
+ VBOX_UTF8_TO_UTF16(filtername, &filternameUtf16);
+ VIR_FREE(filtername);
+ gVBoxAPI.UIUSBCommon.CreateDeviceFilter(USBCommon,
+ filternameUtf16,
+ &filter);
VBOX_UTF16_FREE(filternameUtf16);
if (!filter)
if (guiPresent) {
if (guiDisplay) {
char *displayutf8;
- if (virAsprintf(&displayutf8, "DISPLAY=%s", guiDisplay) >= 0) {
- VBOX_UTF8_TO_UTF16(displayutf8, &env);
- VIR_FREE(displayutf8);
- }
+ displayutf8 = g_strdup_printf("DISPLAY=%s", guiDisplay);
+ VBOX_UTF8_TO_UTF16(displayutf8, &env);
+ VIR_FREE(displayutf8);
VIR_FREE(guiDisplay);
}
if (sdlPresent) {
if (sdlDisplay) {
char *displayutf8;
- if (virAsprintf(&displayutf8, "DISPLAY=%s", sdlDisplay) >= 0) {
- VBOX_UTF8_TO_UTF16(displayutf8, &env);
- VIR_FREE(displayutf8);
- }
+ displayutf8 = g_strdup_printf("DISPLAY=%s", sdlDisplay);
+ VBOX_UTF8_TO_UTF16(displayutf8, &env);
+ VIR_FREE(displayutf8);
VIR_FREE(sdlDisplay);
}
}
VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
- if (virAsprintf(&nameTmpUse, "%s.vbox", machineName) < 0)
- goto cleanup;
+ nameTmpUse = g_strdup_printf("%s.vbox", machineName);
machineLocationPath = virStringReplace(settingsFilePath_Utf8, nameTmpUse, "");
if (machineLocationPath == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
goto cleanup;
}
if (snapshotMachineDesc->currentSnapshot != NULL) {
- if (virAsprintf(¤tSnapshotXmlFilePath, "%s%s.xml", machineLocationPath,
- snapshotMachineDesc->currentSnapshot) < 0)
- goto cleanup;
+ currentSnapshotXmlFilePath = g_strdup_printf("%s%s.xml",
+ machineLocationPath, snapshotMachineDesc->currentSnapshot);
snapshotFileExists = virFileExists(currentSnapshotXmlFilePath);
}
vboxIIDUnalloc(&parentiid);
VBOX_UTF8_TO_UTF16("VDI", &formatUtf16);
- if (virAsprintf(&newLocationUtf8, "%sfakedisk-%d.vdi", machineLocationPath, it) < 0)
- goto cleanup;
+ newLocationUtf8 = g_strdup_printf("%sfakedisk-%d.vdi",
+ machineLocationPath, it);
VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation);
rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj,
formatUtf16,
* next define. This file is saved as "'machineLocation'/snapshot-'uuid'.xml"
*/
VIR_FREE(currentSnapshotXmlFilePath);
- if (virAsprintf(¤tSnapshotXmlFilePath, "%s%s.xml", machineLocationPath, snapshotMachineDesc->currentSnapshot) < 0)
- goto cleanup;
+ currentSnapshotXmlFilePath = g_strdup_printf("%s%s.xml",
+ machineLocationPath, snapshotMachineDesc->currentSnapshot);
char *snapshotContent = virDomainSnapshotDefFormat(NULL, def,
data->caps,
data->xmlopt,
goto cleanup;
}
VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
- if (virAsprintf(&nameTmpUse, "%s.vbox", machineName) < 0)
- goto cleanup;
+ nameTmpUse = g_strdup_printf("%s.vbox", machineName);
machineLocationPath = virStringReplace(settingsFilepath, nameTmpUse, "");
if (machineLocationPath == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
VBOX_UTF16_FREE(locationUtf16);
VBOX_UTF8_TO_UTF16("VDI", &formatUtf16);
- if (virAsprintf(&newLocationUtf8, "%sfakedisk-%s-%d.vdi",
- machineLocationPath, def->parent.parent_name, it) < 0)
- goto cleanup;
+ newLocationUtf8 = g_strdup_printf("%sfakedisk-%s-%d.vdi",
+ machineLocationPath, def->parent.parent_name, it);
VBOX_UTF8_TO_UTF16(newLocationUtf8, &newLocation);
rc = gVBoxAPI.UIVirtualBox.CreateHardDisk(data->vboxObj,
formatUtf16,
return NULL;
}
- if ((privileged && virAsprintf(&cacheDir, "%s/cache/libvirt", LOCALSTATEDIR) < 0) ||
- (!privileged && !(cacheDir = virGetUserCacheDirectory()))) {
+ if (privileged) {
+ cacheDir = g_strdup_printf("%s/cache/libvirt", LOCALSTATEDIR);
+ } else if (!(cacheDir = virGetUserCacheDirectory())) {
VBOX_RELEASE(machine);
return NULL;
}
- if (virAsprintf(&tmp, "%s/vbox.screendump.XXXXXX", cacheDir) < 0) {
- VBOX_RELEASE(machine);
- VIR_FREE(cacheDir);
- return NULL;
- }
+ tmp = g_strdup_printf("%s/vbox.screendump.XXXXXX", cacheDir);
if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp);
VBOX_UTF16_TO_UTF8(networkInterfaceNameUtf16, &networkInterfaceNameUtf8);
- if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", networkInterfaceNameUtf8) < 0)
- goto cleanup;
+ networkNameUtf8 = g_strdup_printf("HostInterfaceNetworking-%s",
+ networkInterfaceNameUtf8);
VBOX_UTF8_TO_UTF16(networkNameUtf8, &networkNameUtf16);
* show up in the net-list in virsh
*/
- if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0)
- goto cleanup;
+ networkNameUtf8 = g_strdup_printf("HostInterfaceNetworking-%s", network->name);
VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);
* server by giving the machine static IP
*/
- if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0)
- goto cleanup;
+ networkNameUtf8 = g_strdup_printf("HostInterfaceNetworking-%s", network->name);
VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);
def->ips = ipdef;
def->nips = 1;
- if (virAsprintf(&networkNameUtf8, "HostInterfaceNetworking-%s", network->name) < 0)
- goto cleanup;
+ networkNameUtf8 = g_strdup_printf("HostInterfaceNetworking-%s", network->name);
VBOX_UTF8_TO_UTF16(network->name, &networkInterfaceNameUtf16);
}
if (location[0] != '/') {
/*The location is a relative path, so we must change it into an absolute one. */
- if (virAsprintf(&tmp, "%s%s", machineLocation, location) < 0)
- goto cleanup;
+ tmp = g_strdup_printf("%s%s", machineLocation, location);
hardDisk->location = g_strdup(tmp);
} else {
hardDisk->location = g_strdup(location);
size_t i = 0;
char *uuid = NULL;
xmlNodePtr ret = xmlNewNode(NULL, BAD_CAST "HardDisk");
- if (virAsprintf(&uuid, "{%s}", hardDisk->uuid) < 0)
- goto cleanup;
+ uuid = g_strdup_printf("{%s}", hardDisk->uuid);
if (xmlNewProp(ret, BAD_CAST "uuid", BAD_CAST uuid) == NULL)
goto cleanup;
char **secondRegex = NULL;
int secondRegexResult = 0;
- if (virAsprintf(&uuid, "{%s}", snapshot->uuid) < 0)
- goto cleanup;
+ uuid = g_strdup_printf("{%s}", snapshot->uuid);
if (xmlNewProp(node, BAD_CAST "uuid", BAD_CAST uuid) == NULL)
goto cleanup;
goto cleanup;
if (secondRegexResult < 1)
goto cleanup;
- if (virAsprintf(&timeStamp, "%sT%sZ", firstRegex[0], secondRegex[0]) < 0)
- goto cleanup;
+ timeStamp = g_strdup_printf("%sT%sZ", firstRegex[0], secondRegex[0]);
if (xmlNewProp(node, BAD_CAST "timeStamp", BAD_CAST timeStamp) == NULL)
goto cleanup;
}
if (machine->currentSnapshot != NULL) {
- if (virAsprintf(¤tSnapshot, "{%s}", machine->currentSnapshot) < 0)
- goto cleanup;
+ currentSnapshot = g_strdup_printf("{%s}", machine->currentSnapshot);
if (!xmlNewProp(machineNode, BAD_CAST "currentSnapshot", BAD_CAST currentSnapshot)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Error in xmlNewProp"));
if (secondRegexResult < 1)
goto cleanup;
- if (virAsprintf(&timeStamp, "%sT%sZ", firstRegex[0], secondRegex[0]) < 0)
- goto cleanup;
+ timeStamp = g_strdup_printf("%sT%sZ", firstRegex[0], secondRegex[0]);
if (!xmlNewProp(machineNode, BAD_CAST "lastStateChange", BAD_CAST timeStamp)) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Error in xmlNewProp"));
}
/* If target.path isn't given, use default path ~/.VirtualBox/image_name */
- if (def->target.path == NULL &&
- virAsprintf(&def->target.path, "%s/.VirtualBox/%s", virGetUserDirectory(), def->name) < 0)
- goto cleanup;
+ if (!def->target.path)
+ def->target.path = g_strdup_printf("%s/.VirtualBox/%s", virGetUserDirectory(), def->name);
VBOX_UTF8_TO_UTF16(def->target.path, &hddNameUtf16);
if (!hddFormatUtf16 || !hddNameUtf16)
{
vboxIID iid = VBOX_IID_INITIALIZER;
PRUnichar *machineNameUtf16 = NULL;
+ char *createFlags = NULL;
+ PRUnichar *createFlagsUtf16 = NULL;
nsresult rc = -1;
VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16);
vboxIIDFromUUID(&iid, def->uuid);
- {
- char *createFlags = NULL;
- PRUnichar *createFlagsUtf16 = NULL;
-
- if (virAsprintf(&createFlags,
- "UUID=%s,forceOverwrite=0", uuidstr) < 0)
- goto cleanup;
- VBOX_UTF8_TO_UTF16(createFlags, &createFlagsUtf16);
- rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
- NULL,
- machineNameUtf16,
- 0,
- nsnull,
- nsnull,
- createFlagsUtf16,
- machine);
- cleanup:
- VIR_FREE(createFlags);
- }
+ createFlags = g_strdup_printf("UUID=%s,forceOverwrite=0", uuidstr);
+ VBOX_UTF8_TO_UTF16(createFlags, &createFlagsUtf16);
+ rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
+ NULL,
+ machineNameUtf16,
+ 0,
+ nsnull,
+ nsnull,
+ createFlagsUtf16,
+ machine);
+ VIR_FREE(createFlags);
VBOX_UTF16_FREE(machineNameUtf16);
vboxIIDUnalloc(&iid);
return rc;