diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-18 01:39:24 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-09-19 01:02:52 +0200 |
commit | 93bab288956f43c70f2b28a88efdc9effd951bb5 (patch) | |
tree | 453abf294f7bf2aba7ccf7ed37ccd669ec231c95 /src/shared/uid-range.c | |
parent | detect-virt: do not try to read all of /proc/cpuinfo (diff) | |
download | systemd-93bab288956f43c70f2b28a88efdc9effd951bb5.tar.xz systemd-93bab288956f43c70f2b28a88efdc9effd951bb5.zip |
tree-wide: use typesafe_qsort()
Diffstat (limited to 'src/shared/uid-range.c')
-rw-r--r-- | src/shared/uid-range.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/shared/uid-range.c b/src/shared/uid-range.c index 434ce6ff4d..5fa7bd277e 100644 --- a/src/shared/uid-range.c +++ b/src/shared/uid-range.c @@ -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; - - if (x->start < y->start) - return -1; - if (x->start > y->start) - return 1; +static int uid_range_compare(const UidRange *a, const UidRange *b) { + int r; - if (x->nr < y->nr) - return -1; - if (x->nr > y->nr) - return 1; + r = CMP(a->start, b->start); + if (r != 0) + return r; - 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; |