diff options
author | Filipe Brandenburger <filbranden@google.com> | 2018-08-02 16:43:37 -0700 |
---|---|---|
committer | Filipe Brandenburger <filbranden@google.com> | 2018-08-06 19:26:35 -0700 |
commit | a0edd02e43b06ec877bedb6ccf622e6748ccdf64 (patch) | |
tree | fc536ed669c7c485a33b8c7293aac1d34f481a4b /src/basic | |
parent | 26cdf3e50b7c4e3b7c617771eb64087130ff801b (diff) | |
download | systemd-a0edd02e43b06ec877bedb6ccf622e6748ccdf64.tar.gz |
tree-wide: Convert compare_func's to use CMP() macro wherever possible.
Looked for definitions of functions using the *_compare_func() suffix.
Tested:
- Unit tests passed (ninja -C build/ test)
- Installed this build and booted with it.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/hash-funcs.c | 6 | ||||
-rw-r--r-- | src/basic/in-addr-util.c | 6 | ||||
-rw-r--r-- | src/basic/process-util.c | 7 |
3 files changed, 8 insertions, 11 deletions
diff --git a/src/basic/hash-funcs.c b/src/basic/hash-funcs.c index db48437be7..6f6832d237 100644 --- a/src/basic/hash-funcs.c +++ b/src/basic/hash-funcs.c @@ -71,7 +71,7 @@ void trivial_hash_func(const void *p, struct siphash *state) { } int trivial_compare_func(const void *a, const void *b) { - return a < b ? -1 : (a > b ? 1 : 0); + return CMP(a, b); } const struct hash_ops trivial_hash_ops = { @@ -87,7 +87,7 @@ int uint64_compare_func(const void *_a, const void *_b) { uint64_t a, b; a = *(const uint64_t*) _a; b = *(const uint64_t*) _b; - return a < b ? -1 : (a > b ? 1 : 0); + return CMP(a, b); } const struct hash_ops uint64_hash_ops = { @@ -104,7 +104,7 @@ int devt_compare_func(const void *_a, const void *_b) { dev_t a, b; a = *(const dev_t*) _a; b = *(const dev_t*) _b; - return a < b ? -1 : (a > b ? 1 : 0); + return CMP(a, b); } const struct hash_ops devt_hash_ops = { diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index a21aa149f5..d83658eaa7 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -581,9 +581,11 @@ void in_addr_data_hash_func(const void *p, struct siphash *state) { int in_addr_data_compare_func(const void *a, const void *b) { const struct in_addr_data *x = a, *y = b; + int r; - if (x->family != y->family) - return x->family - y->family; + r = CMP(x->family, y->family); + if (r != 0) + return r; return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family)); } diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 0a5280eb24..d6ee8b62b8 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1108,12 +1108,7 @@ int pid_compare_func(const void *a, const void *b) { const pid_t *p = a, *q = b; /* Suitable for usage in qsort() */ - - if (*p < *q) - return -1; - if (*p > *q) - return 1; - return 0; + return CMP(*p, *q); } int ioprio_parse_priority(const char *s, int *ret) { |