summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-10-11 14:03:00 +0200
committerLennart Poettering <lennart@poettering.net>2021-10-11 14:33:02 +0200
commitd8f16737005eb80b34df98d96f61f0b8542b098f (patch)
treed2e99d5168bc7540f471c80e73fe9949418591b2
parent11c8b1f1031d368358286f4bb26abebd73cd2868 (diff)
downloadsystemd-d8f16737005eb80b34df98d96f61f0b8542b098f.tar.gz
sort-util: avoid using glibc's internal __compar_d_fn_t type
-rw-r--r--src/basic/sort-util.c2
-rw-r--r--src/basic/sort-util.h14
2 files changed, 11 insertions, 5 deletions
diff --git a/src/basic/sort-util.c b/src/basic/sort-util.c
index a9c68b7e3e..e0fb9cf4a8 100644
--- a/src/basic/sort-util.c
+++ b/src/basic/sort-util.c
@@ -5,7 +5,7 @@
/* hey glibc, APIs with callbacks without a user pointer are so useless */
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
- __compar_d_fn_t compar, void *arg) {
+ comparison_userdata_fn_t compar, void *arg) {
size_t l, u, idx;
const void *p;
int comparison;
diff --git a/src/basic/sort-util.h b/src/basic/sort-util.h
index daa0305a60..02a6784d99 100644
--- a/src/basic/sort-util.h
+++ b/src/basic/sort-util.h
@@ -5,14 +5,20 @@
#include "macro.h"
+/* This is the same as glibc's internal __compar_d_fn_t type. glibc exports a public comparison_fn_t, for the
+ * external type __compar_fn_t, but doesn't do anything similar for __compar_d_fn_t. Let's hence do that
+ * ourselves, picking a name that is obvious, but likely enough to not clash with glibc's choice of naming if
+ * they should ever add one. */
+typedef int (*comparison_userdata_fn_t)(const void *, const void *, void *);
+
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
- __compar_d_fn_t compar, void *arg);
+ comparison_userdata_fn_t compar, void *arg);
#define typesafe_bsearch_r(k, b, n, func, userdata) \
({ \
const typeof(b[0]) *_k = k; \
int (*_func_)(const typeof(b[0])*, const typeof(b[0])*, typeof(userdata)) = func; \
- xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_d_fn_t) _func_, userdata); \
+ xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
})
/**
@@ -55,7 +61,7 @@ static inline void _qsort_safe(void *base, size_t nmemb, size_t size, comparison
_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) {
+static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, comparison_userdata_fn_t compar, void *userdata) {
if (nmemb <= 1)
return;
@@ -66,7 +72,7 @@ static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_
#define typesafe_qsort_r(p, n, func, userdata) \
({ \
int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \
- qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \
+ qsort_r_safe((p), (n), sizeof((p)[0]), (comparison_userdata_fn_t) _func_, userdata); \
})
int cmp_int(const int *a, const int *b);