tree-wide: use typesafe_qsort()
This commit is contained in:
@@ -202,10 +202,8 @@ int boot_loader_read_conf(const char *path, BootConfig *config) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int boot_entry_compare(const void *a, const void *b) {
|
||||
const BootEntry *aa = a, *bb = b;
|
||||
|
||||
return str_verscmp(aa->filename, bb->filename);
|
||||
static int boot_entry_compare(const BootEntry *a, const BootEntry *b) {
|
||||
return str_verscmp(a->filename, b->filename);
|
||||
}
|
||||
|
||||
int boot_entries_find(const char *dir, BootEntry **ret_entries, size_t *ret_n_entries) {
|
||||
@@ -234,7 +232,7 @@ int boot_entries_find(const char *dir, BootEntry **ret_entries, size_t *ret_n_en
|
||||
n++;
|
||||
}
|
||||
|
||||
qsort_safe(array, n, sizeof(BootEntry), boot_entry_compare);
|
||||
typesafe_qsort(array, n, boot_entry_compare);
|
||||
|
||||
*ret_entries = array;
|
||||
*ret_n_entries = n;
|
||||
|
||||
@@ -2206,13 +2206,8 @@ static void remove_cgroup(Hashmap *cgroups, struct CGroupInfo *cg) {
|
||||
free(cg);
|
||||
}
|
||||
|
||||
static int cgroup_info_compare_func(const void *a, const void *b) {
|
||||
const struct CGroupInfo *x = *(const struct CGroupInfo* const*) a, *y = *(const struct CGroupInfo* const*) b;
|
||||
|
||||
assert(x);
|
||||
assert(y);
|
||||
|
||||
return strcmp(x->cgroup_path, y->cgroup_path);
|
||||
static int cgroup_info_compare_func(struct CGroupInfo * const *a, struct CGroupInfo * const *b) {
|
||||
return strcmp((*a)->cgroup_path, (*b)->cgroup_path);
|
||||
}
|
||||
|
||||
static int dump_processes(
|
||||
@@ -2249,7 +2244,7 @@ static int dump_processes(
|
||||
pids[n++] = PTR_TO_PID(pidp);
|
||||
|
||||
assert(n == hashmap_size(cg->pids));
|
||||
qsort_safe(pids, n, sizeof(pid_t), pid_compare_func);
|
||||
typesafe_qsort(pids, n, pid_compare_func);
|
||||
|
||||
width = DECIMAL_STR_WIDTH(pids[n-1]);
|
||||
|
||||
@@ -2291,7 +2286,7 @@ static int dump_processes(
|
||||
LIST_FOREACH(siblings, child, cg->children)
|
||||
children[n++] = child;
|
||||
assert(n == cg->n_children);
|
||||
qsort_safe(children, n, sizeof(struct CGroupInfo*), cgroup_info_compare_func);
|
||||
typesafe_qsort(children, n, cgroup_info_compare_func);
|
||||
|
||||
if (n_columns != 0)
|
||||
n_columns = MAX(LESS_BY(n_columns, 2U), 20U);
|
||||
@@ -2378,7 +2373,7 @@ static int dump_extra_processes(
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
qsort_safe(pids, n, sizeof(pid_t), pid_compare_func);
|
||||
typesafe_qsort(pids, n, pid_compare_func);
|
||||
width = DECIMAL_STR_WIDTH(pids[n-1]);
|
||||
|
||||
for (k = 0; k < n; k++) {
|
||||
|
||||
@@ -38,7 +38,7 @@ static void show_pid_array(
|
||||
if (n_pids == 0)
|
||||
return;
|
||||
|
||||
qsort(pids, n_pids, sizeof(pid_t), pid_compare_func);
|
||||
typesafe_qsort(pids, n_pids, pid_compare_func);
|
||||
|
||||
/* Filter duplicates */
|
||||
for (j = 0, i = 1; i < n_pids; i++) {
|
||||
|
||||
@@ -563,10 +563,8 @@ static int boot_id_hex(const char s[4]) {
|
||||
return id;
|
||||
}
|
||||
|
||||
static int cmp_uint16(const void *_a, const void *_b) {
|
||||
const uint16_t *a = _a, *b = _b;
|
||||
|
||||
return (int)*a - (int)*b;
|
||||
static int cmp_uint16(const uint16_t *a, const uint16_t *b) {
|
||||
return CMP(*a, *b);
|
||||
}
|
||||
|
||||
int efi_get_boot_options(uint16_t **options) {
|
||||
@@ -604,7 +602,7 @@ int efi_get_boot_options(uint16_t **options) {
|
||||
list[count++] = id;
|
||||
}
|
||||
|
||||
qsort_safe(list, count, sizeof(uint16_t), cmp_uint16);
|
||||
typesafe_qsort(list, count, cmp_uint16);
|
||||
|
||||
*options = TAKE_PTR(list);
|
||||
|
||||
|
||||
+8
-13
@@ -8,6 +8,7 @@
|
||||
#include "macro.h"
|
||||
#include "uid-range.h"
|
||||
#include "user-util.h"
|
||||
#include "util.h"
|
||||
|
||||
static bool uid_range_intersect(UidRange *range, uid_t start, uid_t nr) {
|
||||
assert(range);
|
||||
@@ -45,20 +46,14 @@ static void uid_range_coalesce(UidRange **p, unsigned *n) {
|
||||
}
|
||||
}
|
||||
|
||||
static int uid_range_compare(const void *a, const void *b) {
|
||||
const UidRange *x = a, *y = b;
|
||||
static int uid_range_compare(const UidRange *a, const UidRange *b) {
|
||||
int r;
|
||||
|
||||
if (x->start < y->start)
|
||||
return -1;
|
||||
if (x->start > y->start)
|
||||
return 1;
|
||||
r = CMP(a->start, b->start);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (x->nr < y->nr)
|
||||
return -1;
|
||||
if (x->nr > y->nr)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return CMP(a->nr, b->nr);
|
||||
}
|
||||
|
||||
int uid_range_add(UidRange **p, unsigned *n, uid_t start, uid_t nr) {
|
||||
@@ -102,7 +97,7 @@ int uid_range_add(UidRange **p, unsigned *n, uid_t start, uid_t nr) {
|
||||
x->nr = nr;
|
||||
}
|
||||
|
||||
qsort(*p, *n, sizeof(UidRange), uid_range_compare);
|
||||
typesafe_qsort(*p, *n, uid_range_compare);
|
||||
uid_range_coalesce(p, n);
|
||||
|
||||
return *n;
|
||||
|
||||
Reference in New Issue
Block a user