Added
Link Here
|
0 |
- |
1 |
diff --git meson.build meson.build |
|
|
2 |
index 4c6c4ffe4ceeb8d770cf53b0cf9dbdba764acdcc..85ca36f565069c3d29dba40b8e574e68de4af7f8 100644 |
3 |
--- meson.build |
4 |
+++ meson.build |
5 |
@@ -1437,7 +1437,6 @@ functions_to_detect = { |
6 |
'flock': '', |
7 |
'strtok_r': '', |
8 |
'getrandom': '', |
9 |
- 'qsort_r': '', |
10 |
'qsort_s': '', |
11 |
} |
12 |
|
13 |
@@ -1447,6 +1446,37 @@ foreach f, prefix: functions_to_detect |
14 |
endif |
15 |
endforeach |
16 |
|
17 |
+if cpp.links(''' |
18 |
+ #define _GNU_SOURCE |
19 |
+ #include <stdlib.h> |
20 |
+ |
21 |
+ static int dcomp(const void *l, const void *r, void *t) { return 0; } |
22 |
+ |
23 |
+ int main(int ac, char **av) { |
24 |
+ int arr[] = { 1 }; |
25 |
+ void *t = NULL; |
26 |
+ qsort_r((void*)&arr[0], 1, 1, dcomp, t); |
27 |
+ return (0); |
28 |
+ }''', |
29 |
+ args : pre_args, |
30 |
+ name : 'GNU qsort_r') |
31 |
+ pre_args += '-DHAVE_GNU_QSORT_R' |
32 |
+elif cpp.links(''' |
33 |
+ #include <stdlib.h> |
34 |
+ |
35 |
+ static int dcomp(void *t, const void *l, const void *r) { return 0; } |
36 |
+ |
37 |
+ int main(int ac, char **av) { |
38 |
+ int arr[] = { 1 }; |
39 |
+ void *t = NULL; |
40 |
+ qsort_r((void*)&arr[0], 1, 1, t, dcomp); |
41 |
+ return (0); |
42 |
+ }''', |
43 |
+ args : pre_args, |
44 |
+ name : 'BSD qsort_r') |
45 |
+ pre_args += '-DHAVE_BSD_QSORT_R' |
46 |
+endif |
47 |
+ |
48 |
if cc.has_header_symbol('time.h', 'struct timespec') |
49 |
pre_args += '-DHAVE_STRUCT_TIMESPEC' |
50 |
endif |
51 |
diff --git src/util/u_qsort.h src/util/u_qsort.h |
52 |
index 34fff94dba4106f09f3f514cf0dea54d2295eda5..454d3839863d10b76fad624f769caa10ead0b4e6 100644 |
53 |
--- src/util/u_qsort.h |
54 |
+++ src/util/u_qsort.h |
55 |
@@ -56,8 +56,10 @@ util_qsort_r(void *base, size_t nmemb, size_t size, |
56 |
int (*compar)(const void *, const void *, void *), |
57 |
void *arg) |
58 |
{ |
59 |
-#if HAVE_QSORT_R |
60 |
-# if DETECT_OS_APPLE || DETECT_OS_BSD |
61 |
+#if HAVE_GNU_QSORT_R |
62 |
+ /* GNU extension added in glibc 2.8 */ |
63 |
+ qsort_r(base, nmemb, size, compar, arg); |
64 |
+#elif HAVE_BSD_QSORT_R |
65 |
/* BSD/macOS qsort_r takes "arg" before the comparison function and it |
66 |
* pass the "arg" before the elements. |
67 |
*/ |
68 |
@@ -66,10 +68,6 @@ util_qsort_r(void *base, size_t nmemb, size_t size, |
69 |
arg |
70 |
}; |
71 |
qsort_r(base, nmemb, size, &data, util_qsort_adapter); |
72 |
-# else |
73 |
- /* GNU extension added in glibc 2.8 */ |
74 |
- qsort_r(base, nmemb, size, compar, arg); |
75 |
-# endif |
76 |
#elif HAVE_QSORT_S |
77 |
# ifdef _WIN32 |
78 |
/* MSVC/MinGW qsort_s takes "arg" after the comparison function and it |