(#2) Add str_list_free utility function

This commit is contained in:
Dylan Lom 2021-01-16 20:37:41 +11:00
parent 4cc793fcda
commit 98208b511b
2 changed files with 6 additions and 1 deletions

5
util.c
View File

@ -117,3 +117,8 @@ struct str_list str_list_new(int count, ...)
return l;
}
void str_list_free(struct str_list* l) {
for (int i = 0; i < l->size; i++) {
free(l->values[i]);
}
}

2
util.h
View File

@ -2,7 +2,6 @@
/*
* TODO: It's probably considered bad practice to define macros in lower-case...
* TODO: str_list_free
*/
#define SHIFT_ARGS() argv++; argc--
@ -27,5 +26,6 @@ struct str_list {
struct str_list* str_list_add(struct str_list* l, char* s);
struct str_list str_list_new(int count, ...);
void str_list_free(struct str_list* l);
#define str_list_init() str_list_new(0)