libroot/stdlib: Add qsort_r.

It's in POSIX-2024. Remove the libgnu implementation and just import
the changes from latest FreeBSD (dc36d6f9bb1753f3) instead.

While at it, put the non-standard sort functions behind
_DEFAULT_SOURCE.
This commit is contained in:
Augustin Cavalier
2025-03-13 19:30:39 -04:00
parent 194f7cff83
commit 95eee47cdc
7 changed files with 95 additions and 261 deletions
+8 -2
View File
@@ -120,19 +120,25 @@ extern void lcong48(unsigned short int param[7]);
/* search and sort functions */
typedef int (*_compare_function)(const void *, const void *);
typedef int (*_compare_function_qsort_r)(const void*, const void*, void*);
extern void *bsearch(const void *key, const void *base, size_t numElements,
size_t sizeOfElement, _compare_function);
extern void qsort(void *base, size_t numElements, size_t sizeOfElement,
_compare_function);
extern void qsort_r(void* base, size_t numElements, size_t sizeOfElement,
_compare_function_qsort_r, void* cookie);
#ifdef _DEFAULT_SOURCE
extern int heapsort(void *base, size_t numElements, size_t sizeOfElement,
_compare_function);
extern int mergesort(void *base, size_t numElements, size_t sizeOfElement,
_compare_function);
extern void qsort(void *base, size_t numElements, size_t sizeOfElement,
_compare_function);
extern int radixsort(u_char const **base, int numElements,
u_char const *table, u_int endByte);
extern int sradixsort(u_char const **base, int numElements,
u_char const *table, u_int endByte);
#endif
/* misc math functions */
extern int abs(int number);