-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringlist.c
More file actions
29 lines (26 loc) · 874 Bytes
/
Copy pathstringlist.c
File metadata and controls
29 lines (26 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "stringlist.h"
void stringlist_init(stringlist_t* string_list) {
string_list->strings = NULL;
string_list->count = 0;
}
bool stringlist_append(stringlist_t* string_list, char* string) {
char** new_listptr = NULL;
if(!string_list->strings) {
new_listptr = (char**)malloc(sizeof(char*));
} else {
new_listptr = (char**)realloc(string_list->strings, (string_list->count+1) * sizeof(char*));
}
if(!new_listptr) {
return false;
}
new_listptr[string_list->count++] = string;
string_list->strings = new_listptr;
return true;
}
void stringlist_destroy(stringlist_t* string_list) {
for(size_t i=0;i<string_list->count;i++) {
free(string_list->strings[i]); string_list->strings[i] = NULL;
}
free(string_list->strings);
stringlist_init(string_list);
}