source: libabac/abac_stack.c @ 202a7f9

mei_rt2mei_rt2_fix_1meiyap-rt1rt2
Last change on this file since 202a7f9 was 202a7f9, checked in by Mei <mei@…>, 12 years ago

commited modified files for rt1

  • Property mode set to 100644
File size: 1.1 KB
Line 
1#include <stdlib.h>
2
3#include "abac_stack.h"
4#include "abac_util.h"
5
6abac_stack_t *abac_stack_new(void) {
7    abac_stack_t *ret = abac_xmalloc(sizeof(abac_stack_t));
8    ret->elts = NULL;
9    ret->size = 0;
10    return ret;
11}
12
13void abac_stack_push(abac_stack_t *stack, void *elt) {
14    abac_stack_element_t *new_element = abac_xmalloc(sizeof(abac_stack_element_t));
15
16    new_element->ptr = elt;
17    DL_APPEND(stack->elts, new_element);
18    ++stack->size;
19}
20
21void *abac_stack_pop(abac_stack_t *stack) {
22    abac_stack_element_t *cur;
23    void *ret;
24
25    if(stack->size>0) {
26        cur=stack->elts;
27        ret=cur->ptr;
28        DL_DELETE(stack->elts, cur);
29        free(cur);
30        --stack->size;
31        return ret;
32    }
33    // reutrn false if we don't
34    return NULL;
35}
36
37int abac_stack_size(abac_stack_t *stack) {
38    return stack->size;
39}
40
41void abac_stack_free(abac_stack_t *stack) {
42    abac_stack_element_t *elt, *tmp;
43
44    // free everthing in the stack
45    DL_FOREACH_SAFE(stack->elts, elt, tmp) {
46        DL_DELETE(stack->elts, elt);
47        free(elt);
48    }
49
50    // free the list
51    free(stack);
52}
Note: See TracBrowser for help on using the repository browser.