diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index aed40977b3..e4168a06b9 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1760,6 +1760,7 @@ vir_g_strdup_vprintf; # util/viralloc.h +virAppendElement; virDeleteElementsN; virExpandN; virInsertElementsN; diff --git a/src/util/viralloc.c b/src/util/viralloc.c index c1211a5f23..17ce5f3dbe 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -260,6 +260,36 @@ virInsertElementsN(void *ptrptr, } +/** + * virAppendElement: + * @ptrptr: pointer to hold address of allocated memory + * @size: the size of one element in bytes + * @countptr: variable tracking number of elements currently allocated + * @typematchDummy: helper variable to consume results of compile time checks + * @newelem: pointer to a new element to append to @ptrptr + * (the original will be zeroed out if clearOriginal is true) + * @clearOriginal: false if the new item in the array should be copied + * from the original, and the original left intact. + * true if the original should be 0'd out on success. + * @inPlace: false if we should expand the allocated memory before + * moving, true if we should assume someone else *has + * already* done that. + * + * Re-allocate @ptrptr to fit an extra element and place @newelem at the end. + */ +void +virAppendElement(void *ptrptr, + size_t size, + size_t *countptr, + size_t typematchDummy G_GNUC_UNUSED, + void *newelem, + bool clearOriginal, + bool inPlace) +{ + virInsertElementInternal(ptrptr, size, *countptr, countptr, newelem, clearOriginal, inPlace); +} + + /** * virDeleteElementsN: * @ptrptr: pointer to hold address of allocated memory diff --git a/src/util/viralloc.h b/src/util/viralloc.h index b637bc2ca4..7669b12e89 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -46,6 +46,14 @@ int virInsertElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, size_t typematchDummy, void *newelem, bool clearOriginal, bool inPlace) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); +void virAppendElement(void *ptrptr, + size_t size, + size_t *countptr, + size_t typematchDummy, + void *newelem, + bool clearOriginal, + bool inPlace) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); int virDeleteElementsN(void *ptrptr, size_t size, size_t at, size_t *countptr, size_t toremove, bool inPlace) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);