summaryrefslogtreecommitdiff
path: root/kernel/lib/list.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-04-02 12:03:52 +0200
committerAnton Kling <anton@kling.gg>2024-04-02 12:03:52 +0200
commite25a47fcc4db09ab9b845a691297da67243e6049 (patch)
treedfb7c473e001fa93a1a8018c36992a5bc77ae5c3 /kernel/lib/list.c
parent2229fd91f7230ae7068814ae029b733945852eb1 (diff)
Kernel: Use "struct list" to handle file descriptors instead of a fixed sized array
Diffstat (limited to 'kernel/lib/list.c')
-rw-r--r--kernel/lib/list.c21
1 files changed, 21 insertions, 0 deletions
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;