diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/calendarspec.c | 27 | ||||
-rw-r--r-- | src/basic/conf-files.c | 12 | ||||
-rw-r--r-- | src/basic/process-util.c | 6 | ||||
-rw-r--r-- | src/basic/process-util.h | 2 | ||||
-rw-r--r-- | src/basic/strv.c | 6 |
5 files changed, 19 insertions, 34 deletions
diff --git a/src/basic/calendarspec.c b/src/basic/calendarspec.c index 8cb645aeac..dafc09e8f8 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -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; - - if ((*a)->start < (*b)->start) - return -1; - if ((*a)->start > (*b)->start) - return 1; +static int component_compare(CalendarComponent * const *a, CalendarComponent * const *b) { + int r; - if ((*a)->stop < (*b)->stop) - return -1; - if ((*a)->stop > (*b)->stop) - return 1; + r = CMP((*a)->start, (*b)->start); + if (r != 0) + return r; - if ((*a)->repeat < (*b)->repeat) - return -1; - if ((*a)->repeat > (*b)->repeat) - return 1; + r = CMP((*a)->stop, (*b)->stop); + if (r != 0) + return r; - 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]; diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index d6ef0e941e..d03366077d 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -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; diff --git a/src/basic/process-util.c b/src/basic/process-util.c index d6ee8b62b8..c887f9708b 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -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) { diff --git a/src/basic/process-util.h b/src/basic/process-util.h index a5bb072b25..7ef45dc92b 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -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; diff --git a/src/basic/strv.c b/src/basic/strv.c index abf3fc4c7b..f7741d1878 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -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; } |