src/string_list.c

changeset 44
9574a181ec26
parent 36
a7ff583e153f
child 48
0d2c13c24fd0
equal deleted inserted replaced
43:104e75d18ede 44:9574a181ec26
38 38
39 return stringList; 39 return stringList;
40 } 40 }
41 41
42 void destroy_string_list_t(string_list_t* list) { 42 void destroy_string_list_t(string_list_t* list) {
43 if (list->items != NULL) { 43 if (list) {
44 free(list->items); 44 if (list->items) {
45 } 45 free(list->items);
46 free(list); 46 }
47 } 47 free(list);
48
49 void add_string(string_list_t* list, char* item) {
50 char** reallocated_list =
51 realloc(list->items, sizeof(char*) * (list->count + 1));
52 if (reallocated_list != NULL) {
53 list->items = reallocated_list;
54 list->items[list->count] = item;
55 list->count++;
56 } 48 }
57 } 49 }
58 50
51 /* Adds an item to the list, if a NULL-list is specified, the item will
52 * be freed. This way a NULL-list can be used as garbage bin.
53 */
54 void add_string(string_list_t* list, char* item) {
55 if (list) {
56 char** reallocated_list =
57 realloc(list->items, sizeof(char*) * (list->count + 1));
58 if (reallocated_list != NULL) {
59 list->items = reallocated_list;
60 list->items[list->count] = item;
61 list->count++;
62 }
63 } else {
64 free(item);
65 }
66 }
67

mercurial