if (!strchr(fileName, '/') && !strchr(fileName, '\\')) {
/* Plain file name, use same directory as for the .vmx file */
- if (virAsprintf(&result, "%s/%s",
- data->datastorePathWithoutFileName, fileName) < 0)
- goto cleanup;
+ result = g_strdup_printf("%s/%s", data->datastorePathWithoutFileName,
+ fileName);
} else {
if (esxVI_String_AppendValueToList(&propertyNameList,
"summary.name") < 0 ||
++tmp;
}
- if (virAsprintf(&result, "[%s] %s", datastoreName,
- strippedFileName) < 0)
- goto cleanup;
+ result = g_strdup_printf("[%s] %s", datastoreName, strippedFileName);
break;
}
goto cleanup;
}
- if (virAsprintf(&result, "[%s] %s", datastoreName,
- directoryAndFileName) < 0)
- goto cleanup;
+ result = g_strdup_printf("[%s] %s", datastoreName,
+ directoryAndFileName);
}
/* If it's an absolute path outside of a datastore just use it as is */
conn->uri->server)))
goto cleanup;
- if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
- conn->uri->server, conn->uri->port) < 0)
- goto cleanup;
+ url = g_strdup_printf("%s://%s:%d/sdk", priv->parsedUri->transport,
+ conn->uri->server, conn->uri->port);
if (esxVI_Context_Alloc(&priv->host) < 0 ||
esxVI_Context_Connect(priv->host, url, ipAddress, username, password,
if (!(password = virAuthGetPassword(conn, auth, "esx", username, hostname)))
goto cleanup;
- if (virAsprintf(&url, "%s://%s:%d/sdk", priv->parsedUri->transport,
- hostname, conn->uri->port) < 0)
- goto cleanup;
+ url = g_strdup_printf("%s://%s:%d/sdk", priv->parsedUri->transport, hostname,
+ conn->uri->port);
if (esxVI_Context_Alloc(&priv->vCenter) < 0 ||
esxVI_Context_Connect(priv->vCenter, url, ipAddress, username,
if (!domainName || strlen(domainName) < 1) {
complete = g_strdup(hostName);
} else {
- if (virAsprintf(&complete, "%s.%s", hostName, domainName) < 0)
- goto cleanup;
+ complete = g_strdup_printf("%s.%s", hostName, domainName);
}
cleanup:
data.ctx = priv->primary;
if (!directoryName) {
- if (virAsprintf(&data.datastorePathWithoutFileName, "[%s]",
- datastoreName) < 0)
- goto cleanup;
+ data.datastorePathWithoutFileName = g_strdup_printf("[%s]", datastoreName);
} else {
- if (virAsprintf(&data.datastorePathWithoutFileName, "[%s] %s",
- datastoreName, directoryName) < 0)
- goto cleanup;
+ data.datastorePathWithoutFileName = g_strdup_printf("[%s] %s",
+ datastoreName, directoryName);
}
ctx.opaque = &data;
/* Register the domain */
if (directoryName) {
- if (virAsprintf(&datastoreRelatedPath, "[%s] %s/%s.vmx", datastoreName,
- directoryName, escapedName) < 0)
- goto cleanup;
+ datastoreRelatedPath = g_strdup_printf("[%s] %s/%s.vmx", datastoreName,
+ directoryName, escapedName);
} else {
- if (virAsprintf(&datastoreRelatedPath, "[%s] %s.vmx", datastoreName,
- escapedName) < 0)
- goto cleanup;
+ datastoreRelatedPath = g_strdup_printf("[%s] %s.vmx", datastoreName,
+ escapedName);
}
if (esxVI_RegisterVM_Task(priv->primary, priv->primary->datacenter->vmFolder,
virCheckFlags(ESX_MIGRATION_FLAGS, -1);
if (!uri_in) {
- if (virAsprintf(uri_out, "vpxmigr://%s/%s/%s",
- priv->vCenter->ipAddress,
- priv->vCenter->computeResource->resourcePool->value,
- priv->vCenter->hostSystem->_reference->value) < 0)
- return -1;
+ *uri_out = g_strdup_printf("vpxmigr://%s/%s/%s", priv->vCenter->ipAddress,
+ priv->vCenter->computeResource->resourcePool->value,
+ priv->vCenter->hostSystem->_reference->value);
}
return 0;
fileInfo = fileInfo->_next) {
if (length < 1) {
names[count] = g_strdup(fileInfo->path);
- } else if (virAsprintf(&names[count], "%s/%s", directoryAndFileName,
- fileInfo->path) < 0) {
- goto cleanup;
+ } else {
+ names[count] = g_strdup_printf("%s/%s",
+ directoryAndFileName, fileInfo->path);
}
++count;
char *datastorePath = NULL;
char *key = NULL;
- if (virAsprintf(&datastorePath, "[%s] %s", pool->name, name) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s", pool->name, name);
if (esxVI_LookupStorageVolumeKeyByDatastorePath(priv->primary,
datastorePath, &key) < 0) {
if (length < 1) {
volumeName = g_strdup(fileInfo->path);
- } else if (virAsprintf(&volumeName, "%s/%s",
- directoryAndFileName,
- fileInfo->path) < 0) {
- goto cleanup;
+ } else {
+ volumeName = g_strdup_printf("%s/%s",
+ directoryAndFileName, fileInfo->path);
}
- if (virAsprintf(&datastorePath, "[%s] %s", datastoreName,
- volumeName) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s", datastoreName, volumeName);
if (!esxVI_VmDiskFileInfo_DynamicCast(fileInfo)) {
/* Only a VirtualDisk has a UUID */
goto cleanup;
}
- if (virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name,
- def->name) < 0)
- goto cleanup;
+ unescapedDatastorePath = g_strdup_printf("[%s] %s", pool->name, def->name);
if (def->target.format == VIR_STORAGE_FILE_VMDK) {
/* Parse and escape datastore path */
if (!fileName)
goto cleanup;
- if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
- directoryName) < 0)
- goto cleanup;
+ datastorePathWithoutFileName = g_strdup_printf("[%s] %s", pool->name,
+ directoryName);
- if (virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName,
- fileName) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s/%s", pool->name, directoryName,
+ fileName);
/* Create directory, if it doesn't exist yet */
if (esxVI_LookupFileInfoByDatastorePath
goto cleanup;
}
- if (virAsprintf(&sourceDatastorePath, "[%s] %s", sourceVolume->pool,
- sourceVolume->name) < 0)
- goto cleanup;
+ sourceDatastorePath = g_strdup_printf("[%s] %s", sourceVolume->pool,
+ sourceVolume->name);
/* Parse config */
def = virStorageVolDefParseString(&poolDef, xmldesc, 0);
goto cleanup;
}
- if (virAsprintf(&unescapedDatastorePath, "[%s] %s", pool->name,
- def->name) < 0)
- goto cleanup;
+ unescapedDatastorePath = g_strdup_printf("[%s] %s", pool->name, def->name);
if (def->target.format == VIR_STORAGE_FILE_VMDK) {
/* Parse and escape datastore path */
if (!fileName)
goto cleanup;
- if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s", pool->name,
- directoryName) < 0)
- goto cleanup;
+ datastorePathWithoutFileName = g_strdup_printf("[%s] %s", pool->name,
+ directoryName);
- if (virAsprintf(&datastorePath, "[%s] %s/%s", pool->name, directoryName,
- fileName) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s/%s", pool->name, directoryName,
+ fileName);
/* Create directory, if it doesn't exist yet */
if (esxVI_LookupFileInfoByDatastorePath
virCheckFlags(0, -1);
- if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s", volume->pool, volume->name);
if (esxVI_DeleteVirtualDisk_Task(priv->primary, datastorePath,
priv->primary->datacenter->_reference,
virCheckFlags(0, -1);
- if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s", volume->pool, volume->name);
if (esxVI_ZeroFillVirtualDisk_Task(priv->primary, datastorePath,
priv->primary->datacenter->_reference,
memset(info, 0, sizeof(*info));
- if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s", volume->pool, volume->name);
if (esxVI_LookupFileInfoByDatastorePath(priv->primary, datastorePath,
false, &fileInfo,
}
/* Lookup file info */
- if (virAsprintf(&datastorePath, "[%s] %s", volume->pool, volume->name) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s] %s", volume->pool, volume->name);
if (esxVI_LookupFileInfoByDatastorePath(priv->primary, datastorePath,
false, &fileInfo,
{
char *path;
- ignore_value(virAsprintf(&path, "[%s] %s", volume->pool, volume->name));
+ path = g_strdup_printf("[%s] %s", volume->pool, volume->name);
return path;
}
streamPriv->mode = mode;
if (length > 0) {
- if (virAsprintf(&range, "%llu-%llu", offset, offset + length - 1) < 0)
- goto cleanup;
+ range = g_strdup_printf("%llu-%llu", offset, offset + length - 1);
} else if (offset > 0) {
- if (virAsprintf(&range, "%llu-", offset) < 0)
- goto cleanup;
+ range = g_strdup_printf("%llu-", offset);
}
if (esxVI_CURL_Alloc(&streamPriv->curl) < 0 ||
curl_easy_setopt(streamPriv->curl->handle, CURLOPT_PASSWORD,
priv->primary->password);
#else
- if (virAsprintf(&userpwd, "%s:%s", priv->primary->username,
- priv->primary->password) < 0)
- goto cleanup;
+ userpwd = g_strdup_printf("%s:%s", priv->primary->username,
+ priv->primary->password);
curl_easy_setopt(streamPriv->curl->handle, CURLOPT_USERPWD, userpwd);
#endif
return -1;
}
- if (virAsprintf(&range, "%llu-%llu", offset, offset + *length - 1) < 0)
- goto cleanup;
+ range = g_strdup_printf("%llu-%llu", offset, offset + *length - 1);
} else if (offset > 0) {
- if (virAsprintf(&range, "%llu-", offset) < 0)
- goto cleanup;
+ range = g_strdup_printf("%llu-", offset);
}
virMutexLock(&curl->lock);
goto cleanup;
} else {
- if (virAsprintf(&xpathExpression,
- "/soapenv:Envelope/soapenv:Body/vim:%sResponse",
- methodName) < 0)
- goto cleanup;
+ xpathExpression = g_strdup_printf("/soapenv:Envelope/soapenv:Body/vim:%sResponse",
+ methodName);
responseNode = virXPathNode(xpathExpression, xpathContext);
* The <path> part of the datatore path didn't contain a '/', assume
* that the <path> part is actually the file name.
*/
- if (virAsprintf(&datastorePathWithoutFileName, "[%s]",
- datastoreName) < 0)
- goto cleanup;
+ datastorePathWithoutFileName = g_strdup_printf("[%s]", datastoreName);
fileName = g_strdup(directoryAndFileName);
} else {
- if (virAsprintf(&datastorePathWithoutFileName, "[%s] %s",
- datastoreName, directoryName) < 0)
- goto cleanup;
+ datastorePathWithoutFileName = g_strdup_printf("[%s] %s", datastoreName,
+ directoryName);
length = strlen(directoryName);
floppyImageFileQuery = NULL;
/* Search datastore for files */
- if (virAsprintf(&datastorePath, "[%s]", datastoreName) < 0)
- goto cleanup;
+ datastorePath = g_strdup_printf("[%s]", datastoreName);
if (esxVI_SearchDatastoreSubFolders_Task(ctx, hostDatastoreBrowser,
datastorePath, searchSpec,
} else if (!taskInfo->error->localizedMessage) {
*errorMessage = g_strdup(taskInfo->error->fault->_actualType);
} else {
- if (virAsprintf(errorMessage, "%s - %s",
- taskInfo->error->fault->_actualType,
- taskInfo->error->localizedMessage) < 0)
- goto cleanup;
+ *errorMessage = g_strdup_printf("%s - %s",
+ taskInfo->error->fault->_actualType,
+ taskInfo->error->localizedMessage);
}
}