diff options
author | Max Kellermann <max@duempel.org> | 2009-01-24 15:56:30 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-24 15:56:30 +0100 |
commit | ba7c9962663d2e80a6320ca097c06a0849218d27 (patch) | |
tree | 797807ad8df6a95b967945299e2160465e0df6f9 /src/locate.c | |
parent | e1001491240f5925d5f75673552e297c3244e107 (diff) | |
download | mpd-ba7c9962663d2e80a6320ca097c06a0849218d27.tar.gz mpd-ba7c9962663d2e80a6320ca097c06a0849218d27.tar.xz mpd-ba7c9962663d2e80a6320ca097c06a0849218d27.zip |
locate: added struct locate_item_list
Instead of passing two parameters around (number of items, array of
items), combine both in a variable size struct.
Diffstat (limited to 'src/locate.c')
-rw-r--r-- | src/locate.c | 52 |
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 |