diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2018-05-11 21:32:06 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2018-06-06 18:15:34 +0200 |
commit | fe011935cdeda14b61297e72bc30eae46ccd4f55 (patch) | |
tree | ca89a7f40f70a5e5477298d1555d127f94a8b46f /lib/vector.c | |
parent | Merge pull request #2376 from mjstapp/doc_link (diff) | |
download | frr-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.c | 15 |
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; +} |