summaryrefslogtreecommitdiffstats
path: root/lib/vector.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2018-05-11 21:32:06 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2018-06-06 18:15:34 +0200
commitfe011935cdeda14b61297e72bc30eae46ccd4f55 (patch)
treeca89a7f40f70a5e5477298d1555d127f94a8b46f /lib/vector.c
parentMerge pull request #2376 from mjstapp/doc_link (diff)
downloadfrr-fe011935cdeda14b61297e72bc30eae46ccd4f55.tar.xz
frr-fe011935cdeda14b61297e72bc30eae46ccd4f55.zip
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 <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/vector.c')
-rw-r--r--lib/vector.c15
1 files changed, 15 insertions, 0 deletions
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;
+}