diff options
Diffstat (limited to 'src/ref.c')
| -rw-r--r-- | src/ref.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -1,6 +1,9 @@ #include "ref.h" +#include "list.h" #include "util.h" +#include <stdlib.h> + struct ref * ref_alloc(void *data) { @@ -9,7 +12,7 @@ ref_alloc(void *data) ref = malloc(sizeof(struct ref)); if (!ref) ERROR(SYSTEM, "malloc"); - ref->link = LINK_EMPTY; + ref->link = LIST_LINK_INIT; ref->data = data; return ref; @@ -24,19 +27,19 @@ ref_free(void *ref) void refs_free(struct list *list) { - list_free(list, ref_free, LINK_OFFSET(struct ref, link)); + list_free_items(list, ref_free, LIST_OFFSET(struct ref, link)); } int refs_index(struct list *list, void *data) { - struct link *iter; + struct list_link *iter; struct ref *ref; int index; index = 0; for (LIST_ITER(list, iter)) { - ref = UPCAST(iter, struct ref, link); + ref = LIST_UPCAST(iter, struct ref, link); if (ref->data == data) return index; index++; @@ -45,14 +48,14 @@ refs_index(struct list *list, void *data) return -1; } -struct link * +struct list_link * refs_find(struct list *list, void *data) { - struct link *iter; + struct list_link *iter; struct ref *ref; for (LIST_ITER(list, iter)) { - ref = UPCAST(iter, struct ref, link); + ref = LIST_UPCAST(iter, struct ref, link); if (ref->data == data) return iter; } @@ -63,7 +66,7 @@ refs_find(struct list *list, void *data) int refs_incl(struct list *list, void *data) { - struct link *ref; + struct list_link *ref; ref = refs_find(list, data); @@ -73,14 +76,14 @@ refs_incl(struct list *list, void *data) void refs_rm(struct list *list, void *data) { - struct link *ref; + struct list_link *ref; struct ref *dataref; ref = refs_find(list, data); if (!ref) return; - dataref = UPCAST(ref, struct ref, link); - link_pop(ref); + dataref = LIST_UPCAST(ref, struct ref, link); + list_link_pop(ref); free(dataref); } |
