summaryrefslogtreecommitdiff
path: root/com32/lib/syslinux/setup_data.c
blob: a36c5b61a120a37dcd8663dbda20e8771bcd95ec (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
47
#include <stdlib.h>
#include <syslinux/linux.h>
#include <syslinux/loadfile.h>

struct setup_data *setup_data_init(void)
{
    struct setup_data *setup_data;

    setup_data = zalloc(sizeof(*setup_data));
    if (!setup_data)
	return NULL;

    setup_data->prev = setup_data->next = setup_data;
    return setup_data;
}

int setup_data_add(struct setup_data *head, uint32_t type,
		   const void *data, size_t data_len)
{
	struct setup_data *setup_data;

	setup_data = zalloc(sizeof(*setup_data));
	if (!setup_data)
	    return -1;

	setup_data->data     = data;
	setup_data->hdr.len  = data_len;
	setup_data->hdr.type = type;
	setup_data->prev     = head->prev;
	setup_data->next     = head;
	head->prev->next     = setup_data;
	head->prev           = setup_data;

	return 0;
}

int setup_data_load(struct setup_data *head, uint32_t type,
		    const char *filename)
{
	void *data;
	size_t len;

	if (loadfile(filename, &data, &len))
		return -1;

	return setup_data_add(head, type, data, len);
}