diff options
author | Doug Goldstein <cardoe@cardoe.com> | 2013-11-18 17:02:49 -0500 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-11-22 14:44:48 +0000 |
commit | 4fa06f7dbbf9ad24a75ac6bac386ab0c7753e1d7 (patch) | |
tree | 8adbdb024a7799c6b4ad1a7a126198cacf0e8101 /libvirt-utils.c | |
parent | 01b7db975b13755de106d19b132c5a64f12dd704 (diff) | |
download | libvirt-python-v8-4fa06f7dbbf9ad24a75ac6bac386ab0c7753e1d7.tar.gz libvirt-python-v8-4fa06f7dbbf9ad24a75ac6bac386ab0c7753e1d7.tar.xz libvirt-python-v8-4fa06f7dbbf9ad24a75ac6bac386ab0c7753e1d7.zip |
Import some virTypedParams* APIs from libvirt
virTypedParamsClear() and virTypedParamsFree() were introduced in
libvirt 1.0.2. In an effort to keep the code clean bring these two
functions to libvirt-python if we're building against a version of
libvirt that's older than 1.0.2
Diffstat (limited to 'libvirt-utils.c')
-rw-r--r-- | libvirt-utils.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/libvirt-utils.c b/libvirt-utils.c index 9c29a1c..d1f6e70 100644 --- a/libvirt-utils.c +++ b/libvirt-utils.c @@ -23,6 +23,7 @@ #include <stddef.h> #include <stdlib.h> #include <unistd.h> +#include <libvirt/libvirt.h> #include "libvirt-utils.h" /** @@ -138,3 +139,48 @@ int virFileClose(int *fdptr) return rc; } + +#if ! LIBVIR_CHECK_VERSION(1, 0, 2) +/** + * virTypedParamsClear: + * @params: the array of the typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters. The memory occupied by @params + * is not free; use virTypedParamsFree if you want it to be freed too. + * + * Returns nothing. + */ +void +virTypedParamsClear(virTypedParameterPtr params, + int nparams) +{ + size_t i; + + if (!params) + return; + + for (i = 0; i < nparams; i++) { + if (params[i].type == VIR_TYPED_PARAM_STRING) + VIR_FREE(params[i].value.s); + } +} + +/** + * virTypedParamsFree: + * @params: the array of the typed parameters + * @nparams: number of parameters in the @params array + * + * Frees all memory used by string parameters and the memory occuiped by + * @params. + * + * Returns nothing. + */ +void +virTypedParamsFree(virTypedParameterPtr params, + int nparams) +{ + virTypedParamsClear(params, nparams); + VIR_FREE(params); +} +#endif /* ! LIBVIR_CHECK_VERSION(1, 0, 2) */ |