blob: a5f74421ac4b975dc5d4e81383bb06ca89997933 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From d343757d629402c70ca8e5eaa551deaf175c96f3 Mon Sep 17 00:00:00 2001
2From: Emil Renner Berthing <systemd@esmil.dk>
3Date: Thu, 18 Sep 2014 15:24:56 +0200
4Subject: [PATCH 22/31] don't use glibc-specific qsort_r
5
6Upstream-Status: Pending
7
8Signed-off-by: Khem Raj <raj.khem@gmail.com>
9---
10 src/hwdb/hwdb.c | 18 +++++++++++-------
11 src/udev/udevadm-hwdb.c | 16 ++++++++++------
12 2 files changed, 21 insertions(+), 13 deletions(-)
13
14diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c
15index 4540260f9..81aca7a9b 100644
16--- a/src/hwdb/hwdb.c
17+++ b/src/hwdb/hwdb.c
18@@ -152,13 +152,12 @@ static void trie_free(struct trie *trie) {
19
20 DEFINE_TRIVIAL_CLEANUP_FUNC(struct trie*, trie_free);
21
22-static int trie_values_cmp(const void *v1, const void *v2, void *arg) {
23+static struct trie *trie_node_add_value_trie;
24+static int trie_values_cmp(const void *v1, const void *v2) {
25 const struct trie_value_entry *val1 = v1;
26 const struct trie_value_entry *val2 = v2;
27- struct trie *trie = arg;
28-
29- return strcmp(trie->strings->buf + val1->key_off,
30- trie->strings->buf + val2->key_off);
31+ return strcmp(trie_node_add_value_trie->strings->buf + val1->key_off,
32+ trie_node_add_value_trie->strings->buf + val2->key_off);
33 }
34
35 static int trie_node_add_value(struct trie *trie, struct trie_node *node,
36@@ -183,7 +182,10 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
37 .value_off = v,
38 };
39
40- val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
41+ trie_node_add_value_trie = trie;
42+ val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
43+ trie_node_add_value_trie = NULL;
44+
45 if (val) {
46 /* At this point we have 2 identical properties on the same match-string.
47 * Since we process files in order, we just replace the previous value.
48@@ -208,7 +210,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
49 node->values[node->values_count].file_priority = file_priority;
50 node->values[node->values_count].line_number = line_number;
51 node->values_count++;
52- qsort_r(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
53+ trie_node_add_value_trie = trie;
54+ qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
55+ trie_node_add_value_trie = NULL;
56 return 0;
57 }
58
59diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
60index ab5dc7ab6..c777e30ab 100644
61--- a/src/udev/udevadm-hwdb.c
62+++ b/src/udev/udevadm-hwdb.c
63@@ -130,13 +130,13 @@ static void trie_node_cleanup(struct trie_node *node) {
64 free(node);
65 }
66
67-static int trie_values_cmp(const void *v1, const void *v2, void *arg) {
68+static struct trie *trie_node_add_value_trie;
69+static int trie_values_cmp(const void *v1, const void *v2) {
70 const struct trie_value_entry *val1 = v1;
71 const struct trie_value_entry *val2 = v2;
72- struct trie *trie = arg;
73
74- return strcmp(trie->strings->buf + val1->key_off,
75- trie->strings->buf + val2->key_off);
76+ return strcmp(trie_node_add_value_trie->strings->buf + val1->key_off,
77+ trie_node_add_value_trie->strings->buf + val2->key_off);
78 }
79
80 static int trie_node_add_value(struct trie *trie, struct trie_node *node,
81@@ -157,7 +157,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
82 .value_off = v,
83 };
84
85- val = xbsearch_r(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
86+ trie_node_add_value_trie = trie;
87+ val = bsearch(&search, node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
88+ trie_node_add_value_trie = NULL;
89 if (val) {
90 /* replace existing earlier key with new value */
91 val->value_off = v;
92@@ -174,7 +176,9 @@ static int trie_node_add_value(struct trie *trie, struct trie_node *node,
93 node->values[node->values_count].key_off = k;
94 node->values[node->values_count].value_off = v;
95 node->values_count++;
96- qsort_r(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp, trie);
97+ trie_node_add_value_trie = trie;
98+ qsort(node->values, node->values_count, sizeof(struct trie_value_entry), trie_values_cmp);
99+ trie_node_add_value_trie = NULL;
100 return 0;
101 }
102
103--
1042.13.0
105