mei_rt2mei_rt2_fix_1meiyap-rt1rt2
Last change
on this file since 8fa2c49 was
202a7f9,
checked in by Mei <mei@…>, 13 years ago
|
commited modified files for rt1
|
-
Property mode set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | #include <stdlib.h> |
---|
2 | |
---|
3 | #include "abac_list.h" |
---|
4 | #include "abac_util.h" |
---|
5 | |
---|
6 | abac_list_t *abac_list_new(void) { |
---|
7 | abac_list_t *ret = abac_xmalloc(sizeof(abac_list_t)); |
---|
8 | ret->elts = NULL; |
---|
9 | ret->size = 0; |
---|
10 | return ret; |
---|
11 | } |
---|
12 | |
---|
13 | void abac_list_add(abac_list_t *list, void *elt) { |
---|
14 | abac_list_element_t *new_element = abac_xmalloc(sizeof(abac_list_element_t)); |
---|
15 | |
---|
16 | new_element->ptr = elt; |
---|
17 | DL_APPEND(list->elts, new_element); |
---|
18 | ++list->size; |
---|
19 | } |
---|
20 | |
---|
21 | void abac_list_prepend(abac_list_t *list, void *elt) { |
---|
22 | abac_list_element_t *new_element = abac_xmalloc(sizeof(abac_list_element_t)); |
---|
23 | |
---|
24 | new_element->ptr = elt; |
---|
25 | DL_PREPEND(list->elts, new_element); |
---|
26 | ++list->size; |
---|
27 | } |
---|
28 | |
---|
29 | int abac_list_remove(abac_list_t *list, void *elt) { |
---|
30 | abac_list_element_t *cur; |
---|
31 | |
---|
32 | // iterate the list, remove the item if we find it |
---|
33 | DL_FOREACH(list->elts, cur) { |
---|
34 | if (cur->ptr == elt) { |
---|
35 | DL_DELETE(list->elts, cur); |
---|
36 | free(cur); |
---|
37 | --list->size; |
---|
38 | return 1; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | // return false if we don't |
---|
43 | return 0; |
---|
44 | } |
---|
45 | |
---|
46 | int abac_list_size(abac_list_t *list) { |
---|
47 | if (list) |
---|
48 | return list->size; |
---|
49 | return 0; |
---|
50 | } |
---|
51 | |
---|
52 | void abac_list_free(abac_list_t *list) { |
---|
53 | abac_list_element_t *elt, *tmp; |
---|
54 | |
---|
55 | if (list) { |
---|
56 | // free everthing in the list |
---|
57 | DL_FOREACH_SAFE(list->elts, elt, tmp) { |
---|
58 | DL_DELETE(list->elts, elt); |
---|
59 | free(elt); |
---|
60 | } |
---|
61 | |
---|
62 | // free the list |
---|
63 | free(list); |
---|
64 | } |
---|
65 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.