tree-wide: use typesafe_qsort()

This commit is contained in:
Yu Watanabe
2018-09-19 08:02:52 +09:00
parent 6058516a14
commit 93bab28895
35 changed files with 243 additions and 374 deletions
+3 -10
View File
@@ -760,15 +760,8 @@ enum bus_match_node_type bus_match_node_type_from_string(const char *k, size_t n
return -EINVAL;
}
static int match_component_compare(const void *a, const void *b) {
const struct bus_match_component *x = a, *y = b;
if (x->type < y->type)
return -1;
if (x->type > y->type)
return 1;
return 0;
static int match_component_compare(const struct bus_match_component *a, const struct bus_match_component *b) {
return CMP(a->type, b->type);
}
void bus_match_parse_free(struct bus_match_component *components, unsigned n_components) {
@@ -901,7 +894,7 @@ int bus_match_parse(
}
/* Order the whole thing, so that we always generate the same tree */
qsort_safe(components, n_components, sizeof(struct bus_match_component), match_component_compare);
typesafe_qsort(components, n_components, match_component_compare);
/* Check for duplicates */
for (i = 0; i+1 < n_components; i++)
+7 -5
View File
@@ -249,10 +249,11 @@ int device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator)
return 0;
}
static int device_compare(const void *_a, const void *_b) {
static int device_compare(sd_device * const *_a, sd_device * const *_b) {
sd_device *a = *(sd_device **)_a, *b = *(sd_device **)_b;
const char *devpath_a, *devpath_b, *sound_a;
bool delay_a, delay_b;
int r;
assert_se(sd_device_get_devpath(a, &devpath_a) >= 0);
assert_se(sd_device_get_devpath(b, &devpath_b) >= 0);
@@ -293,8 +294,9 @@ static int device_compare(const void *_a, const void *_b) {
/* md and dm devices are enumerated after all other devices */
delay_a = strstr(devpath_a, "/block/md") || strstr(devpath_a, "/block/dm-");
delay_b = strstr(devpath_b, "/block/md") || strstr(devpath_b, "/block/dm-");
if (delay_a != delay_b)
return delay_a - delay_b;
r = CMP(delay_a, delay_b);
if (r != 0)
return r;
return strcmp(devpath_a, devpath_b);
}
@@ -830,7 +832,7 @@ int device_enumerator_scan_devices(sd_device_enumerator *enumerator) {
r = k;
}
qsort_safe(enumerator->devices, enumerator->n_devices, sizeof(sd_device *), device_compare);
typesafe_qsort(enumerator->devices, enumerator->n_devices, device_compare);
enumerator->scan_uptodate = true;
enumerator->type = DEVICE_ENUMERATION_TYPE_DEVICES;
@@ -914,7 +916,7 @@ int device_enumerator_scan_subsystems(sd_device_enumerator *enumerator) {
}
}
qsort_safe(enumerator->devices, enumerator->n_devices, sizeof(sd_device *), device_compare);
typesafe_qsort(enumerator->devices, enumerator->n_devices, device_compare);
enumerator->scan_uptodate = true;
enumerator->type = DEVICE_ENUMERATION_TYPE_SUBSYSTEMS;
+13 -17
View File
@@ -7,8 +7,8 @@
#include "macro.h"
#include "netlink-util.h"
static int address_compare(const void *_a, const void *_b) {
const struct local_address *a = _a, *b = _b;
static int address_compare(const struct local_address *a, const struct local_address *b) {
int r;
/* Order lowest scope first, IPv4 before IPv6, lowest interface index first */
@@ -17,20 +17,17 @@ static int address_compare(const void *_a, const void *_b) {
if (a->family == AF_INET6 && b->family == AF_INET)
return 1;
if (a->scope < b->scope)
return -1;
if (a->scope > b->scope)
return 1;
r = CMP(a->scope, b->scope);
if (r != 0)
return r;
if (a->metric < b->metric)
return -1;
if (a->metric > b->metric)
return 1;
r = CMP(a->metric, b->metric);
if (r != 0)
return r;
if (a->ifindex < b->ifindex)
return -1;
if (a->ifindex > b->ifindex)
return 1;
r = CMP(a->ifindex, b->ifindex);
if (r != 0)
return r;
return memcmp(&a->address, &b->address, FAMILY_ADDRESS_SIZE(a->family));
}
@@ -137,7 +134,7 @@ int local_addresses(sd_netlink *context, int ifindex, int af, struct local_addre
n_list++;
};
qsort_safe(list, n_list, sizeof(struct local_address), address_compare);
typesafe_qsort(list, n_list, address_compare);
*ret = TAKE_PTR(list);
@@ -248,8 +245,7 @@ int local_gateways(sd_netlink *context, int ifindex, int af, struct local_addres
n_list++;
}
if (n_list > 0)
qsort(list, n_list, sizeof(struct local_address), address_compare);
typesafe_qsort(list, n_list, address_compare);
*ret = TAKE_PTR(list);