dict @ 0a2e62f57734f820cd20e151d1150342408552ed

 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    for (unsigned int x = 0; x < list->size; x++)
40        free(list->list[x]);
41
42    free(list->list);
43    free(list);
44}
45
46void *list_get(LIST *list, unsigned int index)
47{
48    if (list == NULL)
49        return NULL;
50
51    if (index < list->size)
52        return list->list[index];
53
54    return NULL;
55}