From e25a47fcc4db09ab9b845a691297da67243e6049 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Tue, 2 Apr 2024 12:03:52 +0200 Subject: Kernel: Use "struct list" to handle file descriptors instead of a fixed sized array --- kernel/lib/list.c | 21 +++++++++++++++++++++ kernel/lib/list.h | 2 ++ 2 files changed, 23 insertions(+) (limited to 'kernel/lib') diff --git a/kernel/lib/list.c b/kernel/lib/list.c index d189c86..c663230 100644 --- a/kernel/lib/list.c +++ b/kernel/lib/list.c @@ -17,6 +17,18 @@ void list_reset(struct list *list) { list->tail_index = -1; } +int list_clone(struct list *in, struct list *out) { + list_init(out); + for (int i = 0;; i++) { + void *output; + if (!list_get(in, i, &output)) { + break; + } + list_add(out, output, NULL); + } + return 1; +} + int list_add(struct list *list, void *entry, int *index) { if (list->tail_index + 1 >= list->capacity) { list->capacity += 25; @@ -30,6 +42,15 @@ int list_add(struct list *list, void *entry, int *index) { return 1; } +int list_set(struct list *list, int index, void *entry) { + if (index > list->tail_index) { + assert(0); + return 0; + } + list->entries[index] = entry; + return 1; +} + int list_get(const struct list *list, int index, void **out) { if (index > list->tail_index) { return 0; diff --git a/kernel/lib/list.h b/kernel/lib/list.h index b7085cd..b1f0127 100644 --- a/kernel/lib/list.h +++ b/kernel/lib/list.h @@ -9,6 +9,8 @@ struct list { int list_init(struct list *list); void list_reset(struct list *list); void list_free(struct list *list); +int list_clone(struct list *in, struct list *out); int list_add(struct list *list, void *entry, int *index); +int list_set(struct list *list, int index, void *entry); int list_get(const struct list *list, int index, void **out); #endif -- cgit v1.2.3