summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/systemd/systemd/0011-don-t-use-glibc-specific-qsort_r.patch
blob: 7cfe829e85e2911887276b1c744ddbb2c07beff0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
From 2eb45f5a0a8bfb8bdca084587ad28e5001f3cc4b Mon Sep 17 00:00:00 2001
From: Emil Renner Berthing <systemd@esmil.dk>
Date: Thu, 18 Sep 2014 15:24:56 +0200
Subject: [PATCH 11/12] don't use glibc-specific qsort_r

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
Upstream-Status: Pending

 src/hwdb/hwdb.c         | 18 +++++++++++-------
 src/udev/udevadm-hwdb.c | 16 ++++++++++------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
index 793398ca6..669b00818 100644
--- a/src/hwdb/hwdb.c
+++ b/src/hwdb/hwdb.c
@@ -151,13 +151,12 @@ static void trie_free(struct trie *trie) {
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(struct trie*, trie_free);
 
-static int trie_values_cmp(const void *v1, const void *v2, void *arg) {
+static struct trie *trie_node_add_value_trie;
+static int trie_values_cmp(const void *v1, const void *v2) {
         const struct trie_value_entry *val1 = v1;
         const struct trie_value_entry *val2 = v2;
-        struct trie *trie = arg;
-
-        return strcmp(trie->strings->buf + val1->key_off,
-                      trie->strings->buf + val2->key_off);
+        return strcmp(trie_node_add_value_trie->strings->buf + val1->key_off,
+                      trie_node_add_value_trie->strings->buf + val2->key_off);
 }
 
 static int trie_node_add_value(struct trie *trie, struct trie_node *node,
@@ -182,7 +181,10 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
                         .value_off = v,
                 };
 
-                val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
+                trie_node_add_value_trie = trie;
+                val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
+                trie_node_add_value_trie = NULL;
+
                 if (val) {
                         /* At this point we have 2 identical properties on the same match-string.
                          * Since we process files in order, we just replace the previous value.
@@ -207,7 +209,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
         node->values[node->values_count].file_priority = file_priority;
         node->values[node->values_count].line_number = line_number;
         node->values_count++;
-        qsort_r(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
+        trie_node_add_value_trie = trie;
+        qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
+        trie_node_add_value_trie = NULL;
         return 0;
 }
 
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index 69b0b9025..fbd213300 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -128,13 +128,13 @@ static void trie_node_cleanup(struct trie_node *node) {
         free(node);
 }
 
-static int trie_values_cmp(const void *v1, const void *v2, void *arg) {
+static struct trie *trie_node_add_value_trie;
+static int trie_values_cmp(const void *v1, const void *v2) {
         const struct trie_value_entry *val1 = v1;
         const struct trie_value_entry *val2 = v2;
-        struct trie *trie = arg;
 
-        return strcmp(trie->strings->buf + val1->key_off,
-                      trie->strings->buf + val2->key_off);
+        return strcmp(trie_node_add_value_trie->strings->buf + val1->key_off,
+                      trie_node_add_value_trie->strings->buf + val2->key_off);
 }
 
 static int trie_node_add_value(struct trie *trie, struct trie_node *node,
@@ -155,7 +155,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
                         .value_off = v,
                 };
 
-                val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
+                trie_node_add_value_trie = trie;
+                val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
+                trie_node_add_value_trie = NULL;
                 if (val) {
                         /* replace existing earlier key with new value */
                         val->value_off = v;
@@ -172,7 +174,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
         node->values[node->values_count].key_off = k;
         node->values[node->values_count].value_off = v;
         node->values_count++;
-        qsort_r(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
+        trie_node_add_value_trie = trie;
+        qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
+        trie_node_add_value_trie = NULL;
         return 0;
 }
 
-- 
2.14.2