aboutsummaryrefslogtreecommitdiff
path: root/src/lib/list.c
blob: db7c5a625a097f63c6eca7862b3627915b21f1ae (plain) (blame)
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
// Copyright (c) 2023, Marvin Borner <dev@marvinborner.de>
// SPDX-License-Identifier: MIT

#include <stdlib.h>

#include <log.h>
#include <lib/list.h>

static struct list *list_new(void)
{
	struct list *list = malloc(sizeof(*list));
	if (!list)
		fatal("out of memory!\n");
	return list;
}

struct list *list_add(struct list *list, void *data)
{
	struct list *new = list_new();
	new->data = data;
	new->next = list;
	return new;
}

void list_free(struct list *list)
{
	while (list) {
		struct list *next = list->next;
		free(list);
		list = next;
	}
}