dict @ 59f03c5663d07f87993d682e7fd07b453fc19a11

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