source: libabac/abac_list.c @ 53e540d

mei_rt2mei_rt2_fix_1meiyap-rt1meiyap1rt2 yap_rt0
Last change on this file since 53e540d was 53e540d, checked in by Mei <mei@…>, 13 years ago

1) adding appendL to do the credential list appending

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[379a53f]1#include <stdlib.h>
2
[6d5623e]3#include "abac_list.h"
[3c251d0]4#include "abac_util.h"
[379a53f]5
[6d5623e]6abac_list_t *abac_list_new(void) {
[3c251d0]7    abac_list_t *ret = abac_xmalloc(sizeof(abac_list_t));
[379a53f]8    ret->elts = NULL;
[90d20f0]9    ret->size = 0;
[379a53f]10    return ret;
11}
12
[6d5623e]13void abac_list_add(abac_list_t *list, void *elt) {
[3c251d0]14    abac_list_element_t *new_element = abac_xmalloc(sizeof(abac_list_element_t));
[379a53f]15
16    new_element->ptr = elt;
17    DL_APPEND(list->elts, new_element);
[90d20f0]18    ++list->size;
[379a53f]19}
[d8990b3]20
[6d5623e]21int abac_list_remove(abac_list_t *list, void *elt) {
22    abac_list_element_t *cur;
[d526b7a]23
24    // iterate the list, remove the item if we find it
25    DL_FOREACH(list->elts, cur) {
26        if (cur->ptr == elt) {
27            DL_DELETE(list->elts, cur);
[be963dc]28            free(cur);
[90d20f0]29            --list->size;
[d526b7a]30            return 1;
31        }
32    }
33
34    // reutrn false if we don't
35    return 0;
36}
37
[6d5623e]38int abac_list_size(abac_list_t *list) {
[53e540d]39    if (list)
40        return list->size;
41    return 0;
[90d20f0]42}
43
[6d5623e]44void abac_list_free(abac_list_t *list) {
45    abac_list_element_t *elt, *tmp;
[d8990b3]46
[53e540d]47    if (list) {
48        // free everthing in the list
49        DL_FOREACH_SAFE(list->elts, elt, tmp) {
50            DL_DELETE(list->elts, elt);
51            free(elt);
52        }
[d8990b3]53
[53e540d]54        // free the list
55        free(list);
56    }
[d8990b3]57}
Note: See TracBrowser for help on using the repository browser.