From 61c399db59cb61118901819e0956e514dd511885 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 9 Jan 2014 18:49:36 +0100 Subject: utils: add new collection_copy() function --- src/utils.c | 8 ++++++++ src/utils.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/utils.c b/src/utils.c index 5296332..9fa4d80 100644 --- a/src/utils.c +++ b/src/utils.c @@ -124,6 +124,14 @@ int collection_count(struct collection *col) return cnt; } +void collection_copy(struct collection *dest, struct collection *src) +{ + if (!dest || !src) return; + dest->capacity = src->capacity; + dest->list = malloc(sizeof(void*) * src->capacity); + memcpy(dest->list, src->list, sizeof(void*) * src->capacity); +} + #ifndef HAVE_STPCPY /** * Copy characters from one string into another diff --git a/src/utils.h b/src/utils.h index 730fbad..67477b5 100644 --- a/src/utils.h +++ b/src/utils.h @@ -54,6 +54,7 @@ void collection_add(struct collection *col, void *element); void collection_remove(struct collection *col, void *element); int collection_count(struct collection *col); void collection_free(struct collection *col); +void collection_copy(struct collection *dest, struct collection *src); #define MERGE_(a,b) a ## _ ## b #define LABEL_(a,b) MERGE_(a, b) -- cgit v1.1-32-gdbae