diff options
author | 2015-11-24 07:37:16 -0500 | |
---|---|---|
committer | 2015-11-24 07:37:16 -0500 | |
commit | c671329681550e0b92aabafd284f9c508511714e (patch) | |
tree | 894c6b75ae0f5ec4477d703d9c4ad8eec1b67cc4 /common/list.c | |
parent | Merge pull request #247 from sce/handle_bindsym_duplicates (diff) | |
parent | fix list sorting (diff) | |
download | sway-c671329681550e0b92aabafd284f9c508511714e.tar.gz sway-c671329681550e0b92aabafd284f9c508511714e.tar.zst sway-c671329681550e0b92aabafd284f9c508511714e.zip |
Merge pull request #248 from taiyu-len/master
fix list sorting
Diffstat (limited to 'common/list.c')
-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) { | |||
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | // pass the pointer of the object we care about to the comparison function | ||
54 | static int list_cmp(const void *l, const void *r, void *_cmp) { | ||
55 | int (*cmp)(const void *, const void *) = _cmp; | ||
56 | return cmp(*(void**)l, *(void**)r); | ||
57 | } | ||
58 | |||
53 | void list_sort(list_t *list, int compare(const void *left, const void *right)) { | 59 | void list_sort(list_t *list, int compare(const void *left, const void *right)) { |
54 | qsort(list->items, list->length, sizeof(void *), compare); | 60 | qsort_r(list->items, list->length, sizeof(void *), list_cmp, compare); |
55 | } | 61 | } |
56 | 62 | ||
57 | int list_seq_find(list_t *list, int compare(const void *item, const void *data), const void *data) { | 63 | int list_seq_find(list_t *list, int compare(const void *item, const void *data), const void *data) { |