diff options
author | taiyu <taiyu.len@gmail.com> | 2015-11-24 00:30:02 -0800 |
---|---|---|
committer | taiyu <taiyu.len@gmail.com> | 2015-11-24 00:30:02 -0800 |
commit | 9d50f88ceffc44f5ce0b83cc060bbae649ce898b (patch) | |
tree | 894c6b75ae0f5ec4477d703d9c4ad8eec1b67cc4 /common | |
parent | cb11364552213e3dbfce8f8b0e90ce562b4e4c1f (diff) |
fix list sorting
Diffstat (limited to 'common')
-rw-r--r-- | common/list.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/common/list.c b/common/list.c index 310296d8..d6f6f2ea 100644 --- a/common/list.c +++ b/common/list.c @@ -50,8 +50,14 @@ void list_cat(list_t *list, list_t *source) { } } +// pass the pointer of the object we care about to the comparison function +static int list_cmp(const void *l, const void *r, void *_cmp) { + int (*cmp)(const void *, const void *) = _cmp; + return cmp(*(void**)l, *(void**)r); +} + void list_sort(list_t *list, int compare(const void *left, const void *right)) { - qsort(list->items, list->length, sizeof(void *), compare); + qsort_r(list->items, list->length, sizeof(void *), list_cmp, compare); } int list_seq_find(list_t *list, int compare(const void *item, const void *data), const void *data) { |