1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

sort-util: use comparison_fn_t instead of __compar_fn_t

Let's avoid using the internal type of glibc, and rather use the one
they officially export.

https://www.gnu.org/software/libc/manual/html_node/Comparison-Functions.html
This commit is contained in:
Lennart Poettering 2021-10-11 13:21:36 +02:00
parent f8cc16fd53
commit f0c4f94453

View File

@ -20,7 +20,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
* that only if nmemb > 0.
*/
static inline void* bsearch_safe(const void *key, const void *base,
size_t nmemb, size_t size, __compar_fn_t compar) {
size_t nmemb, size_t size, comparison_fn_t compar) {
if (nmemb <= 0)
return NULL;
@ -32,14 +32,14 @@ static inline void* bsearch_safe(const void *key, const void *base,
({ \
const typeof(b[0]) *_k = k; \
int (*_func_)(const typeof(b[0])*, const typeof(b[0])*) = func; \
bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_fn_t) _func_); \
bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_fn_t) _func_); \
})
/**
* Normal qsort requires base to be nonnull. Here were require
* that only if nmemb > 0.
*/
static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_fn_t compar) {
static inline void _qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
if (nmemb <= 1)
return;
@ -52,7 +52,7 @@ static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_f
#define typesafe_qsort(p, n, func) \
({ \
int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \
_qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \
_qsort_safe((p), (n), sizeof((p)[0]), (comparison_fn_t) _func_); \
})
static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) {