static int worker_cmp(void const *one, void const *two)
{
- fr_network_worker_t const *a = one;
- fr_network_worker_t const *b = two;
+ fr_network_worker_t const *a = one, *b = two;
- if (a->cpu_time < b->cpu_time) return -1;
- if (a->cpu_time > b->cpu_time) return +1;
-
- return 0;
+ return (a->cpu_time < b->cpu_time) - (a->cpu_time > b->cpu_time);
}
static int reply_cmp(void const *one, void const *two)
{
- fr_channel_data_t const *a = one;
- fr_channel_data_t const *b = two;
-
- if (a->priority < b->priority) return -1;
- if (a->priority > b->priority) return +1;
+ fr_channel_data_t const *a = one, *b = two;
+ int ret;
- if (a->m.when < b->m.when) return -1;
- if (a->m.when > b->m.when) return +1;
+ ret = (a->priority > b->priority) - (a->priority < b->priority);
+ if (ret != 0) return ret;
- return 0;
+ return (a->m.when > b->m.when) - (a->m.when < b->m.when);
}
static int socket_cmp(void const *one, void const *two)
{
- fr_network_socket_t const *a = one;
- fr_network_socket_t const *b = two;
-
- if (a->listen < b->listen) return -1;
- if (a->listen > b->listen) return +1;
+ fr_network_socket_t const *a = one, *b = two;
- return 0;
+ return (a->listen > b->listen) - (a->listen < b->listen);
}
static int entry_cmp(void const *one, void const *two)
{
- fr_tracking_entry_t const *a = one;
- fr_tracking_entry_t const *b = two;
+ fr_tracking_entry_t const *a = one, *b = two;
/*
* Check Code and Identifier.
*
* But NOT the Request Authenticator.
*/
- if (a->data[0] < b->data[0]) return -1;
- if (a->data[0] > b->data[0]) return +1;
-
- if (a->data[1] < b->data[1]) return -1;
- if (a->data[1] > b->data[1]) return +1;
+ if (a->data[0] != b->data[0]) return a->data[0] - b->data[0];
+ if (a->data[1] != b->data[1]) return a->data[1] - b->data[1];
return memcmp(a->src_dst, b->src_dst, a->src_dst_size);
}
*/
static int worker_message_cmp(void const *one, void const *two)
{
- fr_channel_data_t const *a = one;
- fr_channel_data_t const *b = two;
+ fr_channel_data_t const *a = one, *b = two;
+ int ret;
- if (a->priority < b->priority) return -1;
- if (a->priority > b->priority) return +1;
+ ret = (a->priority > b->priority) - (a->priority < b->priority);
+ if (ret != 0) return ret;
- if (a->m.when < b->m.when) return -1;
- if (a->m.when > b->m.when) return +1;
-
- return 0;
+ return (a->m.when > b->m.when) - (a->m.when < b->m.when);
}
/**
*/
static int worker_request_cmp(void const *one, void const *two)
{
- REQUEST const *a = one;
- REQUEST const *b = two;
+ REQUEST const *a = one, *b = two;
+ int ret;
- if (a->async->priority < b->async->priority) return -1;
- if (a->async->priority > b->async->priority) return +1;
+ ret = (a->async->priority > b->async->priority) - (a->async->priority < b->async->priority);
+ if (ret != 0) return ret;
- if (a->async->recv_time < b->async->recv_time) return -1;
- if (a->async->recv_time > b->async->recv_time) return +1;
-
- return 0;
+ return (a->async->recv_time > b->async->recv_time) - (a->async->recv_time < b->async->recv_time);
}
/** Destroy a worker.
*/
static int dict_attr_name_cmp(void const *one, void const *two)
{
- fr_dict_attr_t const *a = one;
- fr_dict_attr_t const *b = two;
+ fr_dict_attr_t const *a = one, *b = two;
return strcasecmp(a->name, b->name);
}
*/
static int dict_attr_combo_cmp(void const *one, void const *two)
{
- fr_dict_attr_t const *a = one;
- fr_dict_attr_t const *b = two;
+ fr_dict_attr_t const *a = one, *b = two;
+ int ret;
- if (a->parent < b->parent) return -1;
- if (a->parent > b->parent) return +1;
+ ret = (a->parent < b->parent) - (a->parent > b->parent);
+ if (ret != 0) return ret;
- if (a->type < b->type) return -1;
- if (a->type > b->type) return +1;
+ ret = (a->type < b->type) - (a->type > b->type);
+ if (ret != 0) return ret;
- return a->attr - b->attr;
+ return (a->attr > b->attr) - (a->attr < b->attr);
}
/** Wrap name hash function for fr_dict_vendor_t
static int fr_event_timer_cmp(void const *a, void const *b)
{
int ret;
- fr_event_timer_t const *ev_a = a;
- fr_event_timer_t const *ev_b = b;
+ fr_event_timer_t const *ev_a = a, *ev_b = b;
return (ret = ((ev_a->when.tv_sec < ev_b->when.tv_sec) - (ev_a->when.tv_sec > ev_b->when.tv_sec))) ?
ret :
*/
static int fr_event_fd_cmp(void const *a, void const *b)
{
- fr_event_fd_t const *ev_a = a;
- fr_event_fd_t const *ev_b = b;
+ fr_event_fd_t const *ev_a = a, *ev_b = b;
return (ev_a->fd < ev_b->fd) - (ev_a->fd > ev_b->fd);
}
*/
static int heap_cmp(void const *one, void const *two)
{
- heap_thing const *a;
- heap_thing const *b;
-
- a = (heap_thing const *) one;
- b = (heap_thing const *) two;
+ heap_thing const *a = one, *b = two;
return a->data - b->data;
-
}
#define ARRAY_SIZE (1024)
*/
int fr_ipaddr_cmp(fr_ipaddr_t const *a, fr_ipaddr_t const *b)
{
- if (a->af < b->af) return -1;
- if (a->af > b->af) return +1;
-
- if (a->prefix < b->prefix) return -1;
- if (a->prefix > b->prefix) return +1;
+ if (a->af != b->af) return a->af - b->af;
+ if (a->prefix != b->prefix) return a->prefix - b->prefix;
switch (a->af) {
case AF_INET:
#ifdef HAVE_STRUCT_SOCKADDR_IN6
case AF_INET6:
- if (a->scope_id < b->scope_id) return -1;
- if (a->scope_id > b->scope_id) return +1;
-
- return memcmp(&a->addr.v6,
- &b->addr.v6,
- sizeof(a->addr.v6));
+ if (a->scope_id != b->scope_id) return a->scope_id - b->scope_id;
+ return memcmp(&a->addr.v6, &b->addr.v6, sizeof(a->addr.v6));
#endif
default:
*/
int fr_timeval_cmp(struct timeval const *a, struct timeval const *b)
{
- if (a->tv_sec > b->tv_sec) return +1;
- if (a->tv_sec < b->tv_sec) return -1;
+ int ret;
- if (a->tv_usec > b->tv_usec) return +1;
- if (a->tv_usec < b->tv_usec) return -1;
+ ret = (a->tv_sec > b->tv_sec) - (a->tv_sec < b->tv_sec);
+ if (ret != 0) return ret;
- return 0;
+ return (a->tv_usec > b->tv_usec) - (a->tv_usec < b->tv_usec);
}
/** Create timeval from a string
*/
int8_t fr_pointer_cmp(void const *a, void const *b)
{
- if (a < b) return -1;
- if (a == b) return 0;
-
- return 1;
+ return (a > b) - (a < b);
}
/** Quick sort an array of pointers using a comparator
int result = 0;
size_t i;
- for (i = 0; i < length; i++) {
- result |= a[i] ^ b[i];
- }
+ for (i = 0; i < length; i++) result |= a[i] ^ b[i];
return result; /* 0 is OK, !0 is !OK, just like memcmp */
}
cmp = fr_pointer_cmp(my_a->da, my_b->da);
if (cmp != 0) return cmp;
- if (my_a->tag < my_b->tag) return -1;
-
- if (my_a->tag > my_b->tag) return 1;
-
- return 0;
+ return (my_a->tag > my_b->tag) - (my_a->tag < my_b->tag);
}
/** Order attributes by their attribute number, and tag
{
vp_cursor_t a_cursor, b_cursor;
VALUE_PAIR *a_p, *b_p;
- int ret;
for (a_p = fr_pair_cursor_init(&a_cursor, &a), b_p = fr_pair_cursor_init(&b_cursor, &b);
a_p && b_p;
a_p = fr_pair_cursor_next(&a_cursor), b_p = fr_pair_cursor_next(&b_cursor)) {
+ int ret;
+
/* Same VP, no point doing expensive checks */
- if (a_p == b_p) {
- continue;
- }
+ if (a_p == b_p) continue;
- if (a_p->da < b_p->da) {
- return -1;
- }
- if (a_p->da > b_p->da) {
- return 1;
- }
+ ret = (a_p->da < b_p->da) - (a_p->da > b_p->da);
+ if (ret != 0) return ret;
- if (a_p->tag < b_p->tag) {
- return -1;
- }
- if (a_p->tag > b_p->tag) {
- return 1;
- }
+ ret = (a_p->tag < b_p->tag) - (a_p->tag > b_p->tag);
+ if (ret != 0) return ret;
ret = fr_value_box_cmp(&a_p->data, &b_p->data);
if (ret != 0) {
*/
static int _filename_cmp(void const *a, void const *b)
{
- cf_file_t const *one = a;
- cf_file_t const *two = b;
+ cf_file_t const *one = a, *two = b;
+ int ret;
- if (one->buf.st_dev < two->buf.st_dev) return -1;
- if (one->buf.st_dev > two->buf.st_dev) return +1;
+ ret = (one->buf.st_dev < two->buf.st_dev) - (one->buf.st_dev > two->buf.st_dev);
+ if (ret != 0) return ret;
- if (one->buf.st_ino < two->buf.st_ino) return -1;
- if (one->buf.st_ino > two->buf.st_ino) return +1;
-
- return 0;
+ return (one->buf.st_ino < two->buf.st_ino) - (one->buf.st_ino > two->buf.st_ino);
}
static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
*/
static int client_num_cmp(void const *one, void const *two)
{
- RADCLIENT const *a = one;
- RADCLIENT const *b = two;
+ RADCLIENT const *a = one, *b = two;
return (a->number - b->number);
}
fr_value_box_t *rhs = NULL;
fr_dict_attr_t const *cast = NULL;
- fr_type_t cast_type = FR_TYPE_INVALID;
+ fr_type_t cast_type = FR_TYPE_INVALID;
fr_value_box_t lhs_cast, rhs_cast;
void *lhs_cast_buff = NULL, *rhs_cast_buff = NULL;
static int dl_symbol_init_cmp(void const *one, void const *two)
{
- dl_symbol_init_t const *a = one;
- dl_symbol_init_t const *b = two;
+ dl_symbol_init_t const *a = one, *b = two;
+ int ret;
rad_assert(a && b);
- if ((void *)a->func > (void *)b->func) return +1;
- if ((void *)a->func < (void *)b->func) return -1;
+ ret = ((void *)a->func > (void *)b->func) - ((void *)a->func < (void *)b->func);
+ if (ret != 0) return ret;
- if (a->symbol && !b->symbol) return +1;
- if (!a->symbol && b->symbol) return -1;
- if (a->symbol && b->symbol) return strcmp(a->symbol, b->symbol);
+ ret = (a->symbol && !b->symbol) - (!a->symbol && b->symbol);
+ if (ret != 0) return ret;
- return 0;
+ if (!a->symbol && !b->symbol) return 0;
+
+ return strcmp(a->symbol, b->symbol);
}
static int dl_symbol_free_cmp(void const *one, void const *two)
{
- dl_symbol_free_t const *a = one;
- dl_symbol_free_t const *b = two;
+ dl_symbol_free_t const *a = one, *b = two;
+ int ret;
rad_assert(a && b);
- if ((void *)a->func > (void *)b->func) return +1;
- if ((void *)a->func < (void *)b->func) return -1;
+ ret = ((void *)a->func > (void *)b->func) - ((void *)a->func < (void *)b->func);
+ if (ret != 0) return ret;
- if (a->symbol && !b->symbol) return +1;
- if (!a->symbol && b->symbol) return -1;
- if (a->symbol && b->symbol) return strcmp(a->symbol, b->symbol);
+ ret = (a->symbol && !b->symbol) - (!a->symbol && b->symbol);
+ if (ret != 0) return ret;
- return 0;
+ if (!a->symbol && !b->symbol) return 0;
+
+ return strcmp(a->symbol, b->symbol);
}
static int dl_inst_cmp(void const *one, void const *two)
{
- dl_instance_t const *a = one;
- dl_instance_t const *b = two;
-
- if (a->data > b->data) return +1;
- if (a->data < b->data) return -1;
+ dl_instance_t const *a = one, *b = two;
- return 0;
+ return (a->data > b->data) - (a->data < b->data);
}
/** Compare the name of two dl_t
*/
static int listener_cmp(void const *one, void const *two)
{
- if (one < two) return -1;
- if (one > two) return +1;
- return 0;
+ return (one < two) - (one > two);
}
static int listener_unlink(UNUSED void *ctx, UNUSED void *data)
*/
static int map_proc_cmp(void const *one, void const *two)
{
- map_proc_t const *a = one;
- map_proc_t const *b = two;
+ map_proc_t const *a = one, *b = two;
if (a->length != b->length) return a->length - b->length;
{
module_thread_instance_t const *my_a = a, *my_b = b;
- if (my_a->inst > my_b->inst) return +1;
- if (my_a->inst < my_b->inst) return -1;
-
- return 0;
+ return (my_a->inst > my_b->inst) - (my_a->inst < my_b->inst);
}
typedef struct {
*/
static int last_reserved_cmp(void const *one, void const *two)
{
- fr_pool_connection_t const *a = one;
- fr_pool_connection_t const *b = two;
+ fr_pool_connection_t const *a = one, *b = two;
+ int ret;
- if (a->last_reserved.tv_sec < b->last_reserved.tv_sec) return -1;
- if (a->last_reserved.tv_sec > b->last_reserved.tv_sec) return +1;
+ ret = (a->last_reserved.tv_sec < b->last_reserved.tv_sec) - (a->last_reserved.tv_sec > b->last_reserved.tv_sec);
+ if (ret != 0) return ret;
- if (a->last_reserved.tv_usec < b->last_reserved.tv_usec) return -1;
- if (a->last_reserved.tv_usec > b->last_reserved.tv_usec) return +1;
-
- return 0;
+ return (a->last_reserved.tv_usec < b->last_reserved.tv_usec) -
+ (a->last_reserved.tv_usec > b->last_reserved.tv_usec);
}
/** Order connections by released longest ago
*/
static int last_released_cmp(void const *one, void const *two)
{
- fr_pool_connection_t const *a = one;
- fr_pool_connection_t const *b = two;
+ fr_pool_connection_t const *a = one, *b = two;
+ int ret;
- if (b->last_released.tv_sec < a->last_released.tv_sec) return -1;
- if (b->last_released.tv_sec > a->last_released.tv_sec) return +1;
+ ret = (b->last_released.tv_sec < a->last_released.tv_sec) -
+ (b->last_released.tv_sec > a->last_released.tv_sec);
+ if (ret != 0) return ret;
- if (b->last_released.tv_usec < a->last_released.tv_usec) return -1;
- if (b->last_released.tv_usec > a->last_released.tv_usec) return +1;
-
- return 0;
+ return (b->last_released.tv_usec < a->last_released.tv_usec) -
+ (b->last_released.tv_usec > a->last_released.tv_usec);
}
/** Removes a connection from the connection list
*/
static int filename_cmp(void const *one, void const *two)
{
+ rc_file_pair_t const *a = one, *b = two;
int cmp;
- rc_file_pair_t const *a = one;
- rc_file_pair_t const *b = two;
-
cmp = strcmp(a->packets, b->packets);
if (cmp != 0) return cmp;
*/
static int state_entry_cmp(void const *one, void const *two)
{
- fr_state_entry_t const *a = one;
- fr_state_entry_t const *b = two;
+ fr_state_entry_t const *a = one, *b = two;
return memcmp(a->state, b->state, sizeof(a->state));
}
*/
static int default_cmp(void const *one, void const *two)
{
- REQUEST const *a = one;
- REQUEST const *b = two;
+ REQUEST const *a = one, *b = two;
+ int ret;
- if (a->priority < b->priority) return -1;
- if (a->priority > b->priority) return +1;
+ ret = (a->priority < b->priority) - (a->priority > b->priority);
+ if (ret != 0) return ret;
return timestamp_cmp(one, two);
}
*/
static int state_cmp(void const *one, void const *two)
{
- REQUEST const *a = one;
- REQUEST const *b = two;
+ REQUEST const *a = one, *b = two;
+ int ret;
/*
* Rounds which are further along go higher in the heap.
*/
- if (a->packet->rounds > b->packet->rounds) return -1;
- if (a->packet->rounds < b->packet->rounds) return +1;
+ ret = (a->packet->rounds > b->packet->rounds) - (a->packet->rounds < b->packet->rounds);
+ if (ret != 0) return ret;
return default_cmp(one, two);
}
{
trigger_last_fired_t const *lf_a = a, *lf_b = b;
- if (lf_a->ci < lf_b->ci) return -1;
- if (lf_a->ci == lf_b->ci) return 0;
-
- return 1;
+ return (lf_a->ci < lf_b->ci) - (lf_a->ci > lf_b->ci);
}
/** Set the global trigger section trigger_exec will search in, and register xlats
*/
static int xlat_cmp(void const *one, void const *two)
{
- xlat_t const *a = one;
- xlat_t const *b = two;
+ xlat_t const *a = one, *b = two;
+ int ret;
- if (a->length != b->length) return a->length - b->length;
+ ret = (a->length > b->length) - (a->length < b->length);
+ if (ret != 0) return ret;
return memcmp(a->name, b->name, a->length);
}
static int bfd_session_cmp(const void *one, const void *two)
{
- const bfd_state_t *a = one;
- const bfd_state_t *b = two;
+ const bfd_state_t *a = one, *b = two;
return fr_ipaddr_cmp(&a->remote_ipaddr, &b->remote_ipaddr);
}
*/
static int _sync_cmp(void const *one, void const *two)
{
- sync_state_t const *a = one;
- sync_state_t const *b = two;
+ sync_state_t const *a = one, *b = two;
return a->msgid - b->msgid;
}
*/
static int cache_entry_cmp(void const *one, void const *two)
{
- rlm_cache_entry_t const *a = one;
- rlm_cache_entry_t const *b = two;
+ rlm_cache_entry_t const *a = one, *b = two;
+ int ret;
- if (a->key_len < b->key_len) return -1;
- if (a->key_len > b->key_len) return +1;
+ ret = (a->key_len > b->key_len) - (a->key_len < b->key_len);
+ if (ret != 0) return ret;
return memcmp(a->key, b->key, a->key_len);
}
*/
static int cache_heap_cmp(void const *one, void const *two)
{
- rlm_cache_entry_t const *a = one;
- rlm_cache_entry_t const *b = two;
-
- if (a->expires < b->expires) return -1;
- if (a->expires > b->expires) return +1;
+ rlm_cache_entry_t const *a = one, *b = two;
- return 0;
+ return (a->expires > b->expires) - (a->expires < b->expires);
}
/** Walk over the cache rbtree
static int detail_cmp(void const *a, void const *b)
{
- fr_dict_attr_t const *one = a;
- fr_dict_attr_t const *two = b;
-
- return one - two;
+ return (a < b) - (a > b);
}
/*
static int pairlist_cmp(void const *a, void const *b)
{
- return strcmp(((PAIR_LIST const *)a)->name,
- ((PAIR_LIST const *)b)->name);
+ return strcmp(((PAIR_LIST const *)a)->name, ((PAIR_LIST const *)b)->name);
}
static int getusersfile(TALLOC_CTX *ctx, char const *filename, rbtree_t **ptree)
{
python_thread_state_t const *a_p = a, *b_p = b;
- if (a_p->inst < b_p->inst) return -1;
- if (a_p->inst > b_p->inst) return +1;
- return 0;
+ return (a_p->inst < b_p->inst) - (a_p->inst > b_p->inst);
}
/** Thread safe call to a python function
*/
static int _cluster_node_cmp(void const *a, void const *b)
{
+ cluster_node_t const *my_a = a, *my_b = b;
int ret;
- cluster_node_t const *my_a = a;
- cluster_node_t const *my_b = b;
-
ret = fr_ipaddr_cmp(&my_a->addr.ipaddr, &my_b->addr.ipaddr);
if (ret != 0) return ret;
- if (my_a->addr.port < my_b->addr.port) return -1;
- if (my_a->addr.port > my_b->addr.port) return +1;
-
- return 0;
+ return my_a->addr.port - my_b->addr.port;
}
/** Reconnect callback to apply new pool config
{
size_t len_a;
size_t len_b;
-
int ret;
len_a = talloc_array_length((uint8_t const *)a);
len_b = talloc_array_length((uint8_t const *)b);
- if (len_a > len_b) return 1;
- if (len_a < len_b) return -1;
+ ret = (len_a > len_b) - (len_a < len_b);
+ if (ret != 0) return ret;
ret = memcmp(a, b, len_a);
- if (ret > 0) return 1;
- if (ret < 0) return -1;
-
- return 0;
+ return (ret > 0) - (ret < 0);
}
/** Return the pools available across the cluster
int8_t fr_dhcpv4_attr_cmp(void const *a, void const *b)
{
- VALUE_PAIR const *my_a = a;
- VALUE_PAIR const *my_b = b;
+ VALUE_PAIR const *my_a = a, *my_b = b;
fr_dict_attr_t const *a_82, *b_82;
VERIFY_VP(my_a);