dict @ 6ed576974dec969ad2745a451a6f680a3cdbcfc4

 1#include "list.h"
 2#include <stdlib.h>
 3
 4LIST* list_add(LIST* list, void* item)
 5{
 6
 7    if (list == NULL) {
 8        list = (LIST*)malloc(sizeof(LIST));
 9        list->size = 0;
10        list->list = (void**)malloc(sizeof(0));
11
12    }
13
14    list->size ++;
15    void** new_list = (void**)reallocarray(list->list, list->size, sizeof(void*));
16
17    new_list[list->size-1] = item;
18    list->list = new_list;
19
20    return list;
21
22}
23
24LIST* list_remove(LIST* list, unsigned int pos)
25{
26    for(unsigned int i = pos; i < list->size - 1; i++)
27        list->list[i] = list->list[i + 1];
28
29    list->size--;
30
31    void** new_list = reallocarray(list->list, list->size, sizeof(void*));
32    list->list = new_list;
33
34    return list;
35}
36
37void list_free(LIST* list)
38{
39    free(list->list);
40    free(list);
41}
42
43void *list_get(LIST *list, unsigned int index)
44{
45    if (list == NULL)
46        return NULL;
47
48    if (index < list->size)
49        return list->list[index];
50
51    return NULL;
52}