diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-18 08:39:24 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-19 08:02:52 +0900 |
commit | 93bab288956f43c70f2b28a88efdc9effd951bb5 (patch) | |
tree | 453abf294f7bf2aba7ccf7ed37ccd669ec231c95 /src/core | |
parent | 6058516a14ada1748313af6783f5b4e7e3006654 (diff) | |
download | systemd-93bab288956f43c70f2b28a88efdc9effd951bb5.tar.gz systemd-93bab288956f43c70f2b28a88efdc9effd951bb5.tar.bz2 systemd-93bab288956f43c70f2b28a88efdc9effd951bb5.zip |
tree-wide: use typesafe_qsort()
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/job.c | 13 | ||||
-rw-r--r-- | src/core/namespace.c | 14 |
2 files changed, 7 insertions, 20 deletions
diff --git a/src/core/job.c b/src/core/job.c index 6c62cdf595..6b17cc1d6f 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -1384,15 +1384,8 @@ void job_add_to_gc_queue(Job *j) { j->in_gc_queue = true; } -static int job_compare(const void *a, const void *b) { - Job *x = *(Job**) a, *y = *(Job**) b; - - if (x->id < y->id) - return -1; - if (x->id > y->id) - return 1; - - return 0; +static int job_compare(Job * const *a, Job * const *b) { + return CMP((*a)->id, (*b)->id); } static size_t sort_job_list(Job **list, size_t n) { @@ -1400,7 +1393,7 @@ static size_t sort_job_list(Job **list, size_t n) { size_t a, b; /* Order by numeric IDs */ - qsort_safe(list, n, sizeof(Job*), job_compare); + typesafe_qsort(list, n, job_compare); /* Filter out duplicates */ for (a = 0, b = 0; a < n; a++) { diff --git a/src/core/namespace.c b/src/core/namespace.c index 1c4e684057..c7cc1c7550 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -397,22 +397,16 @@ static int append_protect_system(MountEntry **p, ProtectSystem protect_system, b } } -static int mount_path_compare(const void *a, const void *b) { - const MountEntry *p = a, *q = b; +static int mount_path_compare(const MountEntry *a, const MountEntry *b) { int d; /* If the paths are not equal, then order prefixes first */ - d = path_compare(mount_entry_path(p), mount_entry_path(q)); + d = path_compare(mount_entry_path(a), mount_entry_path(b)); if (d != 0) return d; /* If the paths are equal, check the mode */ - if (p->mode < q->mode) - return -1; - if (p->mode > q->mode) - return 1; - - return 0; + return CMP((int) a->mode, (int) b->mode); } static int prefix_where_needed(MountEntry *m, size_t n, const char *root_directory) { @@ -1132,7 +1126,7 @@ static void normalize_mounts(const char *root_directory, MountEntry *mounts, siz assert(n_mounts); assert(mounts || *n_mounts == 0); - qsort_safe(mounts, *n_mounts, sizeof(MountEntry), mount_path_compare); + typesafe_qsort(mounts, *n_mounts, mount_path_compare); drop_duplicates(mounts, n_mounts); drop_outside_root(root_directory, mounts, n_mounts); |