aboutsummaryrefslogtreecommitdiffstats
path: root/src/locate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/locate.c')
-rw-r--r--src/locate.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/locate.c b/src/locate.c
index 2833a5f8b..838378797 100644
--- a/src/locate.c
+++ b/src/locate.c
@@ -76,45 +76,45 @@ locate_item_new(const char *type_string, const char *needle)
}
void
-locate_item_list_free(int count, struct locate_item *array)
+locate_item_list_free(struct locate_item_list *list)
{
- int i;
-
- for (i = 0; i < count; i++)
- free(array[i].needle);
+ for (unsigned i = 0; i < list->length; ++i)
+ g_free(list->items[i].needle);
- free(array);
+ g_free(list);
}
-int
-locate_item_list_parse(char *argv[], int argc, struct locate_item **arrayRet)
+struct locate_item_list *
+locate_item_list_new(unsigned length)
{
- int i, j;
- struct locate_item *item;
+ struct locate_item_list *list;
- if (argc == 0)
- return 0;
+ list = g_malloc0(sizeof(*list) - sizeof(list->items[0]) +
+ length * sizeof(list->items[0]));
+ list->length = length;
- if (argc % 2 != 0)
- return -1;
+ return list;
+}
- *arrayRet = g_new(struct locate_item, argc / 2);
+struct locate_item_list *
+locate_item_list_parse(char *argv[], int argc)
+{
+ struct locate_item_list *list;
- for (i = 0, item = *arrayRet; i < argc / 2; i++, item++) {
- if (!locate_item_init(item, argv[i * 2], argv[i * 2 + 1]))
- goto fail;
- }
+ if (argc % 2 != 0)
+ return NULL;
- return argc / 2;
+ list = locate_item_list_new(argc / 2);
-fail:
- for (j = 0; j < i; j++) {
- free((*arrayRet)[j].needle);
+ for (unsigned i = 0; i < list->length; ++i) {
+ if (!locate_item_init(&list->items[i], argv[i * 2],
+ argv[i * 2 + 1])) {
+ locate_item_list_free(list);
+ return NULL;
+ }
}
- free(*arrayRet);
- *arrayRet = NULL;
- return -1;
+ return list;
}
void