aboutsummaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2024-02-12 13:34:56 +0100
committerGabriel A. Giovanini <g.giovanini@gridx.de>2024-02-14 12:29:25 +0100
commitfc26d6542276e17f3206a00b996162397d875e93 (patch)
tree755683100beb190eb8c5983d77fdbdc041f20647 /list.c
downloaddict-fc26d6542276e17f3206a00b996162397d875e93.tar.gz
dict-fc26d6542276e17f3206a00b996162397d875e93.tar.bz2
dict-fc26d6542276e17f3206a00b996162397d875e93.zip
feat: Initial commit
Add initial code form dealing with sqlite.
Diffstat (limited to 'list.c')
-rw-r--r--list.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/list.c b/list.c
new file mode 100644
index 0000000..a40dd57
--- /dev/null
+++ b/list.c
@@ -0,0 +1,44 @@
+#include "list.h"
+#include <stdlib.h>
+
+LIST* list_add(LIST* list, void* item)
+{
+
+ if (list == NULL)
+ {
+ list = (LIST*)malloc(sizeof(LIST));
+ list->size = 0;
+ list->list = (void**)malloc(sizeof(0));
+
+ }
+
+ list->size ++;
+ void** new_list = (void**)reallocarray(list->list, list->size, sizeof(void*));
+
+ new_list[list->size-1] = item;
+ list->list = new_list;
+
+ return list;
+
+}
+
+LIST* list_remove(LIST* list, unsigned int pos)
+{
+ for(unsigned int i = pos; i < list->size - 1; i++)
+ list->list[i] = list->list[i + 1];
+
+ list->size--;
+
+ void** new_list = reallocarray(list->list, list->size, sizeof(void*));
+ list->list = new_list;
+
+ return list;
+}
+
+void list_free(LIST* list) {
+ for (unsigned int x = 0; x < list->size; x++)
+ free(list->list[x]);
+
+ free(list->list);
+ free(list);
+}