diff options
| author | 2014-01-09 18:49:36 +0100 | |
|---|---|---|
| committer | 2014-01-09 18:49:36 +0100 | |
| commit | 61c399db59cb61118901819e0956e514dd511885 (patch) | |
| tree | 8e319feb6ba1ed9f06ccd7f2bf3a03cfc60410d4 | |
| parent | 549da0b893d1d85b5a553a92aef8a4fecb4a602f (diff) | |
| download | usbmuxd-61c399db59cb61118901819e0956e514dd511885.tar.gz usbmuxd-61c399db59cb61118901819e0956e514dd511885.tar.bz2 | |
utils: add new collection_copy() function
| -rw-r--r-- | src/utils.c | 8 | ||||
| -rw-r--r-- | src/utils.h | 1 |
2 files changed, 9 insertions, 0 deletions
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) | |||
| 124 | return cnt; | 124 | return cnt; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | void collection_copy(struct collection *dest, struct collection *src) | ||
| 128 | { | ||
| 129 | if (!dest || !src) return; | ||
| 130 | dest->capacity = src->capacity; | ||
| 131 | dest->list = malloc(sizeof(void*) * src->capacity); | ||
| 132 | memcpy(dest->list, src->list, sizeof(void*) * src->capacity); | ||
| 133 | } | ||
| 134 | |||
| 127 | #ifndef HAVE_STPCPY | 135 | #ifndef HAVE_STPCPY |
| 128 | /** | 136 | /** |
| 129 | * Copy characters from one string into another | 137 | * 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); | |||
| 54 | void collection_remove(struct collection *col, void *element); | 54 | void collection_remove(struct collection *col, void *element); |
| 55 | int collection_count(struct collection *col); | 55 | int collection_count(struct collection *col); |
| 56 | void collection_free(struct collection *col); | 56 | void collection_free(struct collection *col); |
| 57 | void collection_copy(struct collection *dest, struct collection *src); | ||
| 57 | 58 | ||
| 58 | #define MERGE_(a,b) a ## _ ## b | 59 | #define MERGE_(a,b) a ## _ ## b |
| 59 | #define LABEL_(a,b) MERGE_(a, b) | 60 | #define LABEL_(a,b) MERGE_(a, b) |
