aboutsummaryrefslogtreecommitdiff
path: root/src/param.c
blob: e9f43f89dec4fa319de8810d195f764530f9031e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "param.h"

#include <stdlib.h>
#include <string.h>


int magi_param_list_add(struct magi_param_list ** list,
                        struct magi_param *       item)
{
    struct magi_param_list * node = malloc(sizeof(*node));
    if (node) {
        node->next = *list;
        node->item = *item;
        *list      = node;
    }
    return !!node;
}

char * magi_param_list_get(struct magi_param_list * list, const char * name)
{
    if (!list || !name) {
        return 0;
    } else if (!strcmp(list->item.name, name)) {
        return list->item.data;
    } else {
        return magi_param_list_get(list->next, name);
    }
}

void magi_param_list_destroy(struct magi_param_list * list)
{
    if (list) {
        magi_param_list_destroy(list->next);
        free(list->next);
        free(list->item.name);
        free(list->item.data);
    }
}