Changeset f2460a50 in mainline for uspace/lib/posix/source/stdlib.c


Ignore:
Timestamp:
2017-05-30T06:16:25Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c726209
Parents:
719a208
Message:

qsort() compliant with C standard.

File:
1 edited

Legend:

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

    r719a208 rf2460a50  
    4747#include "posix/unistd.h"
    4848
    49 #include "libc/sort.h"
     49#include "libc/qsort.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  */
    145 static 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 /**
    161138 * Array sorting utilizing the quicksort algorithm.
    162139 *
     
    169146    int (*compare)(const void *, const void *))
    170147{
    171         /* Implemented in libc with one extra argument. */
    172         qsort(array, count, size, sort_compare_wrapper, compare);
     148        qsort(array, count, size, compare);
    173149}
    174150
Note: See TracChangeset for help on using the changeset viewer.