src/string_list.c

changeset 94
9637e3efb8e7
parent 82
44b3332dfe03
equal deleted inserted replaced
93:cd3013126129 94:9637e3efb8e7
26 26
27 #include "string_list.h" 27 #include "string_list.h"
28 28
29 #include <assert.h> 29 #include <assert.h>
30 30
31 static void do_not_free(void* item) {
32 }
33
31 string_list_t* new_string_list_t() { 34 string_list_t* new_string_list_t() {
32 string_list_t* stringList = malloc(sizeof(string_list_t)); 35 string_list_t* stringList = malloc(sizeof(string_list_t));
33 stringList->count = 0; 36 stringList->count = 0;
34 stringList->capacity = 32; 37 stringList->capacity = 32;
35 stringList->items = calloc(sizeof(char*), stringList->capacity); 38 stringList->items = calloc(sizeof(char*), stringList->capacity);
39 stringList->free_item = do_not_free;
36 40
37 return stringList; 41 return stringList;
38 } 42 }
39 43
40 void destroy_string_list_t(string_list_t* list) { 44 void destroy_string_list_t(string_list_t* list) {
41 if (list) { 45 if (list) {
42 if (list->items) { 46 if (list->items) {
47 for (size_t i = 0 ; i < list->count ; i++) {
48 list->free_item(list->items[i]);
49 }
43 free(list->items); 50 free(list->items);
44 } 51 }
45 free(list); 52 free(list);
46 } 53 }
47 } 54 }

mercurial