diff options
author | Ulrich Drepper <drepper@redhat.com> | 2007-11-13 17:21:43 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2007-11-13 17:21:43 +0000 |
commit | e458144c99ddc00769ffa6bd367c21d37e879d83 (patch) | |
tree | 55e549e9ab2672a3ebf613ca698f622c97aece8c /stdlib/qsort.c | |
parent | * posix/tst-rfc3484.c: Adjust for addition of prefixlen field. (diff) | |
download | glibc-e458144c99ddc00769ffa6bd367c21d37e879d83.tar.gz glibc-e458144c99ddc00769ffa6bd367c21d37e879d83.tar.bz2 glibc-e458144c99ddc00769ffa6bd367c21d37e879d83.zip |
* stdlib/stdlib.h: Define __compar_d_fn_t. Declare qsort_r.
* include/stdlib.h: Add hidden_proto for qsort_t and adjust protoype
for _quicksort.
* stdlib/msort.c (qsort): Now a wrapper around qsort_r.
(qsort_r): Renamed from qsort. Take additional parameter and pass it
on as third parameter to compare function and _quicksort.
* stdlib/qsort.c (_quicksort): Take additional parameter and pass on
to the compare function.
* stdlib/Versions [libc] (GLIBC_2.8): Add qsort_r.
* Versions.def: Add GLIBC_2.8 for libc.
Diffstat (limited to 'stdlib/qsort.c')
-rw-r--r-- | stdlib/qsort.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/stdlib/qsort.c b/stdlib/qsort.c index 6a33c52f39..b19e86ece1 100644 --- a/stdlib/qsort.c +++ b/stdlib/qsort.c @@ -88,7 +88,7 @@ typedef struct void _quicksort (void *const pbase, size_t total_elems, size_t size, - __compar_fn_t cmp) + __compar_d_fn_t cmp, void *arg) { register char *base_ptr = (char *) pbase; @@ -120,13 +120,13 @@ _quicksort (void *const pbase, size_t total_elems, size_t size, char *mid = lo + size * ((hi - lo) / size >> 1); - if ((*cmp) ((void *) mid, (void *) lo) < 0) + if ((*cmp) ((void *) mid, (void *) lo, arg) < 0) SWAP (mid, lo, size); - if ((*cmp) ((void *) hi, (void *) mid) < 0) + if ((*cmp) ((void *) hi, (void *) mid, arg) < 0) SWAP (mid, hi, size); else goto jump_over; - if ((*cmp) ((void *) mid, (void *) lo) < 0) + if ((*cmp) ((void *) mid, (void *) lo, arg) < 0) SWAP (mid, lo, size); jump_over:; @@ -138,10 +138,10 @@ _quicksort (void *const pbase, size_t total_elems, size_t size, that this algorithm runs much faster than others. */ do { - while ((*cmp) ((void *) left_ptr, (void *) mid) < 0) + while ((*cmp) ((void *) left_ptr, (void *) mid, arg) < 0) left_ptr += size; - while ((*cmp) ((void *) mid, (void *) right_ptr) < 0) + while ((*cmp) ((void *) mid, (void *) right_ptr, arg) < 0) right_ptr -= size; if (left_ptr < right_ptr) @@ -214,7 +214,7 @@ _quicksort (void *const pbase, size_t total_elems, size_t size, and the operation speeds up insertion sort's inner loop. */ for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size) - if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr) < 0) + if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) tmp_ptr = run_ptr; if (tmp_ptr != base_ptr) @@ -226,7 +226,7 @@ _quicksort (void *const pbase, size_t total_elems, size_t size, while ((run_ptr += size) <= end_ptr) { tmp_ptr = run_ptr - size; - while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr) < 0) + while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, arg) < 0) tmp_ptr -= size; tmp_ptr += size; |