Archived
1
0
Fork 0

list: added list_copy.

This commit is contained in:
Henrik Hautakoski 2011-02-20 09:02:06 +01:00
parent 35008fa605
commit 658bc8b9ad
3 changed files with 33 additions and 0 deletions

View file

@ -30,6 +30,17 @@ struct list* list_create(void) {
return list;
}
struct list* list_copy(struct list *list) {
if (list && list->nr) {
struct list *copy = xmalloc(sizeof(struct list));
copy->items = xmemdup(list->items, sizeof(list->items) * list->nr);
copy->nr = list->nr;
return copy;
}
return NULL;
}
int list_destroy(struct list *list) {
list_clear_fn(list, NULL);

View file

@ -23,6 +23,8 @@ typedef int (cmp_fn_t)(const void *, const void *b);
struct list* list_create(void);
struct list* list_copy(struct list *list);
int list_destroy(struct list *list);
void list_clear(struct list *list);