Changes in uspace/lib/posix/source/stdlib.c [f2460a50:b19e892] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/source/stdlib.c
rf2460a50 rb19e892 47 47 #include "posix/unistd.h" 48 48 49 #include "libc/ qsort.h"49 #include "libc/sort.h" 50 50 #include "libc/str.h" 51 51 #include "libc/vfs/vfs.h" … … 136 136 137 137 /** 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 /** 138 161 * Array sorting utilizing the quicksort algorithm. 139 162 * … … 146 169 int (*compare)(const void *, const void *)) 147 170 { 148 qsort(array, count, size, compare); 171 /* Implemented in libc with one extra argument. */ 172 qsort(array, count, size, sort_compare_wrapper, compare); 149 173 } 150 174
Note:
See TracChangeset
for help on using the changeset viewer.