tree-wide: use typesafe_qsort()
This commit is contained in:
+10
-17
@@ -57,25 +57,18 @@ CalendarSpec* calendar_spec_free(CalendarSpec *c) {
|
||||
return mfree(c);
|
||||
}
|
||||
|
||||
static int component_compare(const void *_a, const void *_b) {
|
||||
CalendarComponent * const *a = _a, * const *b = _b;
|
||||
static int component_compare(CalendarComponent * const *a, CalendarComponent * const *b) {
|
||||
int r;
|
||||
|
||||
if ((*a)->start < (*b)->start)
|
||||
return -1;
|
||||
if ((*a)->start > (*b)->start)
|
||||
return 1;
|
||||
r = CMP((*a)->start, (*b)->start);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if ((*a)->stop < (*b)->stop)
|
||||
return -1;
|
||||
if ((*a)->stop > (*b)->stop)
|
||||
return 1;
|
||||
r = CMP((*a)->stop, (*b)->stop);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if ((*a)->repeat < (*b)->repeat)
|
||||
return -1;
|
||||
if ((*a)->repeat > (*b)->repeat)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return CMP((*a)->repeat, (*b)->repeat);
|
||||
}
|
||||
|
||||
static void normalize_chain(CalendarComponent **c) {
|
||||
@@ -103,7 +96,7 @@ static void normalize_chain(CalendarComponent **c) {
|
||||
for (i = *c; i; i = i->next)
|
||||
*(j++) = i;
|
||||
|
||||
qsort(b, n, sizeof(CalendarComponent*), component_compare);
|
||||
typesafe_qsort(b, n, component_compare);
|
||||
|
||||
b[n-1]->next = NULL;
|
||||
next = b[n-1];
|
||||
|
||||
@@ -134,12 +134,8 @@ static int files_add(
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int base_cmp(const void *a, const void *b) {
|
||||
const char *s1, *s2;
|
||||
|
||||
s1 = *(char * const *)a;
|
||||
s2 = *(char * const *)b;
|
||||
return strcmp(basename(s1), basename(s2));
|
||||
static int base_cmp(char * const *a, char * const *b) {
|
||||
return strcmp(basename(*a), basename(*b));
|
||||
}
|
||||
|
||||
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, unsigned flags, char **dirs) {
|
||||
@@ -176,7 +172,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const
|
||||
if (!files)
|
||||
return -ENOMEM;
|
||||
|
||||
qsort_safe(files, hashmap_size(fh), sizeof(char *), base_cmp);
|
||||
typesafe_qsort(files, hashmap_size(fh), base_cmp);
|
||||
*strv = files;
|
||||
|
||||
return 0;
|
||||
@@ -200,7 +196,7 @@ int conf_files_insert(char ***strv, const char *root, char **dirs, const char *p
|
||||
for (i = 0; i < strv_length(*strv); i++) {
|
||||
int c;
|
||||
|
||||
c = base_cmp(*strv + i, &path);
|
||||
c = base_cmp((char* const*) *strv + i, (char* const*) &path);
|
||||
if (c == 0) {
|
||||
char **dir;
|
||||
|
||||
|
||||
@@ -1104,11 +1104,9 @@ void valgrind_summary_hack(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
int pid_compare_func(const void *a, const void *b) {
|
||||
const pid_t *p = a, *q = b;
|
||||
|
||||
int pid_compare_func(const pid_t *a, const pid_t *b) {
|
||||
/* Suitable for usage in qsort() */
|
||||
return CMP(*p, *q);
|
||||
return CMP(*a, *b);
|
||||
}
|
||||
|
||||
int ioprio_parse_priority(const char *s, int *ret) {
|
||||
|
||||
@@ -108,7 +108,7 @@ static inline void* PID_TO_PTR(pid_t pid) {
|
||||
|
||||
void valgrind_summary_hack(void);
|
||||
|
||||
int pid_compare_func(const void *a, const void *b);
|
||||
int pid_compare_func(const pid_t *a, const pid_t *b);
|
||||
|
||||
static inline bool nice_is_valid(int n) {
|
||||
return n >= PRIO_MIN && n < PRIO_MAX;
|
||||
|
||||
+2
-4
@@ -711,14 +711,12 @@ bool strv_overlap(char **a, char **b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static int str_compare(const void *_a, const void *_b) {
|
||||
const char **a = (const char**) _a, **b = (const char**) _b;
|
||||
|
||||
static int str_compare(char * const *a, char * const *b) {
|
||||
return strcmp(*a, *b);
|
||||
}
|
||||
|
||||
char **strv_sort(char **l) {
|
||||
qsort_safe(l, strv_length(l), sizeof(char*), str_compare);
|
||||
typesafe_qsort(l, strv_length(l), str_compare);
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user