aboutsummaryrefslogtreecommitdiff
path: root/src/file.c
blob: 10e5b07a9c93c0af328b51663fd2cfe05b34c0d2 (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
41
42
43
44
45
46
#include "file.h"

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


void magi_files_add(struct magi_files     **files,
                    const struct magi_file *newitem)
{
    struct magi_files *node = malloc(sizeof(*node));
    if (node) {
        node->next = *files;
        node->item = *newitem;
        *files     = node;
    }
}

const struct magi_file *magi_files_get(const struct magi_files *files,
                                       const char              *name)
{
    if (!files || !name) {
        return 0;
    } else if (!strcmp(files->item.field, name)) {
        return &files->item;
    } else {
        return magi_files_get(files->next, name);
    }
}

void magi_files_free(struct magi_files *files)
{
    if (files) {
        magi_files_free(files->next);
        free(files->next);
        free(files->item.field);
        free(files->item.filename);
        magi_params_free(files->item.params);
        free(files->item.params);
    }
}


char *magi_file_param(struct magi_file *file, const char *name)
{
    return file ? magi_params_get(file->params, name) : 0;
}