diff options
| author | Aleksa Vuckovic <aleksav013@gmail.com> | 2022-08-16 18:03:58 +0200 |
|---|---|---|
| committer | Aleksa Vuckovic <aleksav013@gmail.com> | 2022-08-16 18:03:58 +0200 |
| commit | 501a706643a056863b6ea214882a2be270966f87 (patch) | |
| tree | 7f1ff025e7aa37b936ce15ebfe21783ae312d7f2 /kernel/src/libk/list.c | |
| parent | 5c1c4eb0a4084b666342e6f8eb348eb80be6214b (diff) | |
libk/list.h; reading mmap from multiboot2
Diffstat (limited to 'kernel/src/libk/list.c')
| -rw-r--r-- | kernel/src/libk/list.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/kernel/src/libk/list.c b/kernel/src/libk/list.c new file mode 100644 index 0000000..5f75845 --- /dev/null +++ b/kernel/src/libk/list.c @@ -0,0 +1,37 @@ +#include <libk/list.h> +#include <heap.h> + +void add_to_list_head(list_t** ptr, void* data) +{ + list_t* node = (list_t*)kalloc(sizeof(list_t)); + node->data = data; + + node->next = *ptr; + *ptr = node; +} + +void add_to_list_tail(list_t** ptr, void* data) +{ + list_t* node = (list_t*)kalloc(sizeof(list_t)); + node->data = data; + + if (*ptr == NULL) { + *ptr = node; + } else { + list_t* tmp = *ptr; + while (tmp->next != NULL) + tmp = tmp->next; + tmp->next = node; + } +} + +void free_list(list_t** ptr) +{ + if (*ptr == NULL) + return; + + for (list_t* tmp = (*ptr)->next; tmp != NULL; tmp = tmp->next) { + kfree(*ptr); + *ptr = tmp; + } +} |
