diff options
author | Filipe Brandenburger <filbranden@google.com> | 2018-08-03 01:43:37 +0200 |
---|---|---|
committer | Filipe Brandenburger <filbranden@google.com> | 2018-08-07 04:26:35 +0200 |
commit | a0edd02e43b06ec877bedb6ccf622e6748ccdf64 (patch) | |
tree | fc536ed669c7c485a33b8c7293aac1d34f481a4b /src/resolve | |
parent | network: Use CMP() macro for comparison. (diff) | |
download | systemd-a0edd02e43b06ec877bedb6ccf622e6748ccdf64.tar.xz systemd-a0edd02e43b06ec877bedb6ccf622e6748ccdf64.zip |
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/resolve')
-rw-r--r-- | src/resolve/resolved-dns-cache.c | 6 | ||||
-rw-r--r-- | src/resolve/resolved-dns-packet.c | 8 | ||||
-rw-r--r-- | src/resolve/resolved-dns-rr.c | 14 | ||||
-rw-r--r-- | src/resolve/resolved-dns-server.c | 14 |
4 files changed, 17 insertions, 25 deletions
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index 403d23d4fb..95e9e072c1 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -228,11 +228,7 @@ void dns_cache_prune(DnsCache *c) { static int dns_cache_item_prioq_compare_func(const void *a, const void *b) { const DnsCacheItem *x = a, *y = b; - if (x->until < y->until) - return -1; - if (x->until > y->until) - return 1; - return 0; + return CMP(x->until, y->until); } static int dns_cache_init(DnsCache *c) { diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 097942ee0a..2cc606f363 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -2339,11 +2339,11 @@ static void dns_packet_hash_func(const void *p, struct siphash *state) { static int dns_packet_compare_func(const void *a, const void *b) { const DnsPacket *x = a, *y = b; + int r; - if (x->size < y->size) - return -1; - if (x->size > y->size) - return 1; + r = CMP(x->size, y->size); + if (r != 0) + return r; return memcmp(DNS_PACKET_DATA((DnsPacket*) x), DNS_PACKET_DATA((DnsPacket*) y), x->size); } diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c index cfd0ed214d..05a4915101 100644 --- a/src/resolve/resolved-dns-rr.c +++ b/src/resolve/resolved-dns-rr.c @@ -300,15 +300,13 @@ static int dns_resource_key_compare_func(const void *a, const void *b) { if (ret != 0) return ret; - if (x->type < y->type) - return -1; - if (x->type > y->type) - return 1; + ret = CMP(x->type, y->type); + if (ret != 0) + return ret; - if (x->class < y->class) - return -1; - if (x->class > y->class) - return 1; + ret = CMP(x->class, y->class); + if (ret != 0) + return ret; return 0; } diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c index eff3dbb275..24164362c4 100644 --- a/src/resolve/resolved-dns-server.c +++ b/src/resolve/resolved-dns-server.c @@ -624,19 +624,17 @@ static int dns_server_compare_func(const void *a, const void *b) { const DnsServer *x = a, *y = b; int r; - if (x->family < y->family) - return -1; - if (x->family > y->family) - return 1; + r = CMP(x->family, y->family); + if (r != 0) + return r; r = memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family)); if (r != 0) return r; - if (x->ifindex < y->ifindex) - return -1; - if (x->ifindex > y->ifindex) - return 1; + r = CMP(x->ifindex, y->ifindex); + if (r != 0) + return r; return 0; } |