mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: typedparam: Separate code to assign value to typed parameter
The code will be reused in other function. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
d6fca62e63
commit
803d19a68d
@ -205,24 +205,12 @@ virTypedParameterToString(virTypedParameterPtr param)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Assign name, type, and the appropriately typed arg to param; in the
|
|
||||||
* case of a string, the caller is assumed to have malloc'd a string,
|
static int
|
||||||
* or can pass NULL to have this function malloc an empty string.
|
virTypedParameterAssignValueVArgs(virTypedParameterPtr param,
|
||||||
* Return 0 on success, -1 after an error message on failure. */
|
int type,
|
||||||
int
|
va_list ap)
|
||||||
virTypedParameterAssign(virTypedParameterPtr param, const char *name,
|
|
||||||
int type, ...)
|
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
va_start(ap, type);
|
|
||||||
|
|
||||||
if (virStrcpyStatic(param->field, name) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
|
|
||||||
name);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
param->type = type;
|
param->type = type;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case VIR_TYPED_PARAM_INT:
|
case VIR_TYPED_PARAM_INT:
|
||||||
@ -246,17 +234,40 @@ virTypedParameterAssign(virTypedParameterPtr param, const char *name,
|
|||||||
case VIR_TYPED_PARAM_STRING:
|
case VIR_TYPED_PARAM_STRING:
|
||||||
param->value.s = va_arg(ap, char *);
|
param->value.s = va_arg(ap, char *);
|
||||||
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
|
if (!param->value.s && VIR_STRDUP(param->value.s, "") < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unexpected type %d for field %s"), type, name);
|
_("unexpected type %d for field %s"), type,
|
||||||
goto cleanup;
|
NULLSTR(param->field));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Assign name, type, and the appropriately typed arg to param; in the
|
||||||
|
* case of a string, the caller is assumed to have malloc'd a string,
|
||||||
|
* or can pass NULL to have this function malloc an empty string.
|
||||||
|
* Return 0 on success, -1 after an error message on failure. */
|
||||||
|
int
|
||||||
|
virTypedParameterAssign(virTypedParameterPtr param, const char *name,
|
||||||
|
int type, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (virStrcpyStatic(param->field, name) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%s' too long"),
|
||||||
|
name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, type);
|
||||||
|
ret = virTypedParameterAssignValueVArgs(param, type, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user