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.
}
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 = {
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 = {
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 = {
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));
}
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) {
static int peer_address_compare_func(const void *a, const void *b) {
const SocketPeer *x = a, *y = b;
+ int r;
- if (x->peer.sa.sa_family < y->peer.sa.sa_family)
- return -1;
- if (x->peer.sa.sa_family > y->peer.sa.sa_family)
- return 1;
+ r = CMP(x->peer.sa.sa_family, y->peer.sa.sa_family);
+ if (r != 0)
+ return r;
switch(x->peer.sa.sa_family) {
case AF_INET:
static int catalog_compare_func(const void *a, const void *b) {
const CatalogItem *i = a, *j = b;
unsigned k;
+ int r;
for (k = 0; k < ELEMENTSOF(j->id.bytes); k++) {
- if (i->id.bytes[k] < j->id.bytes[k])
- return -1;
- if (i->id.bytes[k] > j->id.bytes[k])
- return 1;
+ r = CMP(i->id.bytes[k], j->id.bytes[k]);
+ if (r != 0)
+ return r;
}
return strcmp(i->language, j->language);
if (r != 0)
return r;
- if (x->chassis_id_size < y->chassis_id_size)
- return -1;
-
- if (x->chassis_id_size > y->chassis_id_size)
- return 1;
+ r = CMP(x->chassis_id_size, y->chassis_id_size);
+ if (r != 0)
+ return r;
r = memcmp(x->port_id, y->port_id, MIN(x->port_id_size, y->port_id_size));
if (r != 0)
return r;
- if (x->port_id_size < y->port_id_size)
- return -1;
- if (x->port_id_size > y->port_id_size)
- return 1;
-
- return 0;
+ return CMP(x->port_id_size, y->port_id_size);
}
const struct hash_ops lldp_neighbor_id_hash_ops = {
int lldp_neighbor_prioq_compare_func(const void *a, const void *b) {
const sd_lldp_neighbor *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);
}
_public_ sd_lldp_neighbor *sd_lldp_neighbor_ref(sd_lldp_neighbor *n) {
int client_id_compare_func(const void *_a, const void *_b) {
const DHCPClientId *a, *b;
+ int r;
a = _a;
b = _b;
assert(!a->length || a->data);
assert(!b->length || b->data);
- if (a->length != b->length)
- return a->length < b->length ? -1 : 1;
+ r = CMP(a->length, b->length);
+ if (r != 0)
+ return r;
return memcmp(a->data, b->data, a->length);
}
static int address_compare_func(const void *c1, const void *c2) {
const Address *a1 = c1, *a2 = c2;
+ int r;
- if (a1->family < a2->family)
- return -1;
- if (a1->family > a2->family)
- return 1;
+ r = CMP(a1->family, a2->family);
+ if (r != 0)
+ return r;
switch (a1->family) {
/* use the same notion of equality as the kernel does */
case AF_INET:
- if (a1->prefixlen < a2->prefixlen)
- return -1;
- if (a1->prefixlen > a2->prefixlen)
- return 1;
+ r = CMP(a1->prefixlen, a2->prefixlen);
+ if (r != 0)
+ return r;
/* compare the peer prefixes */
if (a1->prefixlen != 0) {
else
b2 = be32toh(a2->in_addr.in.s_addr) >> (32 - a1->prefixlen);
- if (b1 < b2)
- return -1;
- if (b1 > b2)
- return 1;
+ r = CMP(b1, b2);
+ if (r != 0)
+ return r;
}
_fallthrough_;
static int route_compare_func(const void *_a, const void *_b) {
const Route *a = _a, *b = _b;
+ int r;
- if (a->family < b->family)
- return -1;
- if (a->family > b->family)
- return 1;
+ r = CMP(a->family, b->family);
+ if (r != 0)
+ return r;
switch (a->family) {
case AF_INET:
case AF_INET6:
- if (a->dst_prefixlen < b->dst_prefixlen)
- return -1;
- if (a->dst_prefixlen > b->dst_prefixlen)
- return 1;
-
- if (a->tos < b->tos)
- return -1;
- if (a->tos > b->tos)
- return 1;
-
- if (a->priority < b->priority)
- return -1;
- if (a->priority > b->priority)
- return 1;
-
- if (a->table < b->table)
- return -1;
- if (a->table > b->table)
- return 1;
+ r = CMP(a->dst_prefixlen, b->dst_prefixlen);
+ if (r != 0)
+ return r;
+
+ r = CMP(a->tos, b->tos);
+ if (r != 0)
+ return r;
+
+ r = CMP(a->priority, b->priority);
+ if (r != 0)
+ return r;
+
+ r = CMP(a->table, b->table);
+ if (r != 0)
+ return r;
return memcmp(&a->dst, &b->dst, FAMILY_ADDRESS_SIZE(a->family));
default:
const RoutingPolicyRule *a = _a, *b = _b;
int r;
- if (a->family < b->family)
- return -1;
- if (a->family > b->family)
- return 1;
+ r = CMP(a->family, b->family);
+ if (r != 0)
+ return r;
switch (a->family) {
case AF_INET:
case AF_INET6:
- if (a->from_prefixlen < b->from_prefixlen)
- return -1;
- if (a->from_prefixlen > b->from_prefixlen)
- return 1;
+ r = CMP(a->from_prefixlen, b->from_prefixlen);
+ if (r != 0)
+ return r;
- if (a->to_prefixlen < b->to_prefixlen)
- return -1;
- if (a->to_prefixlen > b->to_prefixlen)
- return 1;
+ r = CMP(a->to_prefixlen, b->to_prefixlen);
+ if (r != 0)
+ return r;
- if (a->tos < b->tos)
- return -1;
- if (a->tos > b->tos)
- return 1;
+ r = CMP(a->tos, b->tos);
+ if (r != 0)
+ return r;
- if (a->fwmask < b->fwmark)
- return -1;
- if (a->fwmask > b->fwmark)
- return 1;
+ r = CMP(a->fwmask, b->fwmask);
+ if (r != 0)
+ return r;
- if (a->table < b->table)
- return -1;
- if (a->table > b->table)
- return 1;
+ r = CMP(a->table, b->table);
+ if (r != 0)
+ return r;
r = strcmp_ptr(a->iif, b->iif);
if (!r)
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) {
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);
}
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;
}
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;
}