aboutsummaryrefslogtreecommitdiff
path: root/src/file.c
blob: df6c978f6b6dabefa5310fe4b9712b781b8ee5ef (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
39
40
#include "file.h"

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


int magi_file_list_add(struct magi_file_list ** list, struct magi_file * item)
{
    struct magi_file_list * node = malloc(sizeof(*node));
    if (node) {
        node->next = *list;
        node->item = *item;
        *list      = node;
    }
    return node;
}

struct magi_file * magi_file_list_get(struct magi_file_list * list,
                                      const char *            name)
{
    if (!list || !name) {
        return 0;
    } else if (!strcmp(list->item.param_name, name)) {
        return &list->item;
    } else {
        return magi_file_list_get(list->next, name);
    }
}

void magi_file_list_destroy(struct magi_file_list * list)
{
    if (list) {
        magi_file_list_destroy(list->next);
        free(list->next);
        free(list->item.param_name);
        free(list->item.file_name);
        magi_param_list_destroy(list->item.params);
        free(list->item.params);
    }
}