diff options
Diffstat (limited to 'string-list.c')
-rw-r--r-- | string-list.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/string-list.c b/string-list.c index a0cf0cfe88..1f6063f2a2 100644 --- a/string-list.c +++ b/string-list.c @@ -195,16 +195,6 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c list->nr = list->alloc = 0; } - -void print_string_list(const struct string_list *p, const char *text) -{ - int i; - if ( text ) - printf("%s\n", text); - for (i = 0; i < p->nr; i++) - printf("%s:%p\n", p->items[i].string, p->items[i].util); -} - struct string_list_item *string_list_append_nodup(struct string_list *list, char *string) { @@ -224,18 +214,28 @@ struct string_list_item *string_list_append(struct string_list *list, list->strdup_strings ? xstrdup(string) : (char *)string); } +/* + * Encapsulate the compare function pointer because ISO C99 forbids + * casting from void * to a function pointer and vice versa. + */ +struct string_list_sort_ctx +{ + compare_strings_fn cmp; +}; + static int cmp_items(const void *a, const void *b, void *ctx) { - compare_strings_fn cmp = ctx; + struct string_list_sort_ctx *sort_ctx = ctx; const struct string_list_item *one = a; const struct string_list_item *two = b; - return cmp(one->string, two->string); + return sort_ctx->cmp(one->string, two->string); } void string_list_sort(struct string_list *list) { - QSORT_S(list->items, list->nr, cmp_items, - list->cmp ? list->cmp : strcmp); + struct string_list_sort_ctx sort_ctx = {list->cmp ? list->cmp : strcmp}; + + QSORT_S(list->items, list->nr, cmp_items, &sort_ctx); } struct string_list_item *unsorted_string_list_lookup(struct string_list *list, |