From fe011935cdeda14b61297e72bc30eae46ccd4f55 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 11 May 2018 15:32:06 -0400 Subject: lib: add string utilities I see lots of the same code being copy-pasted and slightly tweaked for string processing all over the codebase. Time to start aggregating these pieces into something consistent and correct. Signed-off-by: Quentin Young --- lib/vector.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/vector.c') diff --git a/lib/vector.c b/lib/vector.c index e38ee57fc..75f6c00bd 100644 --- a/lib/vector.c +++ b/lib/vector.c @@ -181,3 +181,18 @@ unsigned int vector_count(vector v) return count; } + +void vector_to_array(vector v, void ***dest, int *argc) +{ + *dest = XCALLOC(MTYPE_TMP, sizeof(void *) * v->active); + memcpy(*dest, v->index, sizeof(void *) * v->active); + *argc = v->active; +} + +vector array_to_vector(void **src, int argc) +{ + vector v = vector_init(VECTOR_MIN_SIZE); + for (int i = 0; i < argc; i++) + vector_set_index(v, i, src[i]); + return v; +} -- cgit v1.2.3