1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

tree-wide: CMP()ify all the things

Let's employ coccinelle to fix everything up automatically for us.
This commit is contained in:
Lennart Poettering 2018-10-16 15:57:40 +02:00
parent f7eed93f15
commit 6dd91b3682
8 changed files with 40 additions and 67 deletions

28
coccinelle/cmp.cocci Normal file
View File

@ -0,0 +1,28 @@
@@
expression x, y;
@@
- if (x < y)
- return -1;
- if (x > y)
- return 1;
- return 0;
+ return CMP(x, y);
@@
expression x, y;
@@
- if (x < y)
- return -1;
- else if (x > y)
- return 1;
- return 0;
+ return CMP(x, y);
@@
expression x, y;
@@
- if (x < y)
- return -1;
- else if (x > y)
- return 1;
- else
- return 0;
+ return CMP(x, y);

View File

@ -418,12 +418,7 @@ static int btrfs_ioctl_search_args_compare(const struct btrfs_ioctl_search_args
if (args->key.min_type > args->key.max_type)
return 1;
if (args->key.min_offset < args->key.max_offset)
return -1;
if (args->key.min_offset > args->key.max_offset)
return 1;
return 0;
return CMP(args->key.min_offset, args->key.max_offset);
}
#define FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) \

View File

@ -688,32 +688,16 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
return 0;
case TABLE_TIMESTAMP:
if (a->timestamp < b->timestamp)
return -1;
if (a->timestamp > b->timestamp)
return 1;
return 0;
return CMP(a->timestamp, b->timestamp);
case TABLE_TIMESPAN:
if (a->timespan < b->timespan)
return -1;
if (a->timespan > b->timespan)
return 1;
return 0;
return CMP(a->timespan, b->timespan);
case TABLE_SIZE:
if (a->size < b->size)
return -1;
if (a->size > b->size)
return 1;
return 0;
return CMP(a->size, b->size);
case TABLE_UINT32:
if (a->uint32 < b->uint32)
return -1;
if (a->uint32 > b->uint32)
return 1;
return 0;
return CMP(a->uint32, b->uint32);
default:
;
@ -721,12 +705,7 @@ static int cell_data_compare(TableData *a, size_t index_a, TableData *b, size_t
}
/* Generic fallback using the orginal order in which the cells where added. */
if (index_a < index_b)
return -1;
if (index_a > index_b)
return 1;
return 0;
return CMP(index_a, index_b);
}
static int table_data_compare(const size_t *a, const size_t *b, Table *t) {

View File

@ -398,12 +398,7 @@ int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m) {
if (r != 0)
return r;
if (n < m)
return -1;
else if (n > m)
return 1;
else
return 0;
return CMP(n, m);
}
bool chars_intersect(const char *a, const char *b) {

View File

@ -496,11 +496,7 @@ static int peer_address_compare_func(const void *a, const void *b) {
case AF_INET6:
return memcmp(&x->peer.in6.sin6_addr, &y->peer.in6.sin6_addr, sizeof(x->peer.in6.sin6_addr));
case AF_VSOCK:
if (x->peer.vm.svm_cid < y->peer.vm.svm_cid)
return -1;
if (x->peer.vm.svm_cid > y->peer.vm.svm_cid)
return 1;
return 0;
return CMP(x->peer.vm.svm_cid, y->peer.vm.svm_cid);
}
assert_not_reached("Black sheep in the family!");
}

View File

@ -2661,12 +2661,7 @@ int journal_file_compare_locations(JournalFile *af, JournalFile *bf) {
return 1;
/* Finally, compare by contents */
if (af->current_xor_hash < bf->current_xor_hash)
return -1;
if (af->current_xor_hash > bf->current_xor_hash)
return 1;
return 0;
return CMP(af->current_xor_hash, bf->current_xor_hash);
}
static int bump_array_index(uint64_t *i, direction_t direction, uint64_t n) {

View File

@ -419,12 +419,7 @@ static int exit_prioq_compare(const void *a, const void *b) {
return 1;
/* Lower priority values first */
if (x->priority < y->priority)
return -1;
if (x->priority > y->priority)
return 1;
return 0;
return CMP(x->priority, y->priority);
}
static void free_clock_data(struct clock_data *d) {
@ -1579,12 +1574,7 @@ static int inode_data_compare(const void *a, const void *b) {
if (x->dev > y->dev)
return 1;
if (x->ino < y->ino)
return -1;
if (x->ino > y->ino)
return 1;
return 0;
return CMP(x->ino, y->ino);
}
static void inode_data_hash_func(const void *p, struct siphash *state) {

View File

@ -101,12 +101,7 @@ static int proposed_rrs_cmp(DnsResourceRecord **x, unsigned x_size, DnsResourceR
return r;
}
if (x_size < y_size)
return -1;
if (x_size > y_size)
return 1;
return 0;
return CMP(x_size, y_size);
}
static int mdns_packet_extract_matching_rrs(DnsPacket *p, DnsResourceKey *key, DnsResourceRecord ***ret_rrs) {