Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/source/stdlib.c

    rf2460a50 rb19e892  
    4747#include "posix/unistd.h"
    4848
    49 #include "libc/qsort.h"
     49#include "libc/sort.h"
    5050#include "libc/str.h"
    5151#include "libc/vfs/vfs.h"
     
    136136
    137137/**
     138 * Private helper function that serves as a compare function for qsort().
     139 *
     140 * @param elem1 First element to compare.
     141 * @param elem2 Second element to compare.
     142 * @param compare Comparison function without userdata parameter.
     143 * @return Relative ordering of the elements.
     144 */
     145static int sort_compare_wrapper(void *elem1, void *elem2, void *userdata)
     146{
     147        int (*compare)(const void *, const void *) = userdata;
     148        int ret = compare(elem1, elem2);
     149       
     150        /* Native qsort internals expect this. */
     151        if (ret < 0) {
     152                return -1;
     153        } else if (ret > 0) {
     154                return 1;
     155        } else {
     156                return 0;
     157        }
     158}
     159
     160/**
    138161 * Array sorting utilizing the quicksort algorithm.
    139162 *
     
    146169    int (*compare)(const void *, const void *))
    147170{
    148         qsort(array, count, size, compare);
     171        /* Implemented in libc with one extra argument. */
     172        qsort(array, count, size, sort_compare_wrapper, compare);
    149173}
    150174
Note: See TracChangeset for help on using the changeset viewer.