提交 72bf14d3 编写于 作者: M Michal Privoznik

util: Introduce virStringListMerge

For two string lists merge one into the other one.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 a26ff63a
......@@ -2769,6 +2769,7 @@ virStringListGetFirstWithPrefix;
virStringListHasString;
virStringListJoin;
virStringListLength;
virStringListMerge;
virStringListRemove;
virStringMatch;
virStringParsePort;
......
......@@ -239,6 +239,42 @@ virStringListRemove(char ***strings,
}
/**
* virStringListMerge:
* @dst: a NULL-terminated array of strings to expand
* @src: a NULL-terminated array of strings
*
* Merges @src into @dst. Upon successful return from this
* function, @dst is resized to $(dst + src) elements and @src is
* freed.
*
* Returns 0 on success, -1 otherwise.
*/
int
virStringListMerge(char ***dst,
char ***src)
{
size_t dst_len, src_len, i;
if (!src || !*src)
return 0;
dst_len = virStringListLength((const char **) *dst);
src_len = virStringListLength((const char **) *src);
if (VIR_REALLOC_N(*dst, dst_len + src_len + 1) < 0)
return -1;
for (i = 0; i <= src_len; i++)
(*dst)[i + dst_len] = (*src)[i];
/* Don't call virStringListFree() as it would free strings in
* @src. */
VIR_FREE(*src);
return 0;
}
/**
* virStringListCopy:
* @dst: where to store the copy of @strings
......
......@@ -46,6 +46,9 @@ char **virStringListAdd(const char **strings,
void virStringListRemove(char ***strings,
const char *item);
int virStringListMerge(char ***dst,
char ***src);
int virStringListCopy(char ***dst,
const char **src);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册