diff options
Diffstat (limited to 'src/shared/util.h')
-rw-r--r-- | src/shared/util.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h index 26af5b30af..09e556d011 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -772,3 +772,15 @@ bool id128_is_valid(const char *s) _pure_; void parse_user_at_host(char *arg, char **user, char **host); int split_pair(const char *s, const char *sep, char **l, char **r); + +/** + * Normal qsort requires base to be nonnull. Here were require + * that only if nmemb > 0. + */ +static inline void qsort_safe(void *base, size_t nmemb, size_t size, + int (*compar)(const void *, const void *)) { + if (nmemb) { + assert(base); + qsort(base, nmemb, size, compar); + } +} |