Skip to content

Commit adea407

Browse files
committed
util: add qsort_r_safe(), similar to qsort_safe()
1 parent 3f536d5 commit adea407

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/basic/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ static inline void qsort_safe(void *base, size_t nmemb, size_t size, comparison_
111111
qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \
112112
})
113113

114+
static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, int (*compar)(const void*, const void*, void*), void *userdata) {
115+
if (nmemb <= 1)
116+
return;
117+
118+
assert(base);
119+
qsort_r(base, nmemb, size, compar, userdata);
120+
}
121+
114122
/**
115123
* Normal memcpy requires src to be nonnull. We do nothing if n is 0.
116124
*/

0 commit comments

Comments
 (0)