1 #ifndef SORT_H 2 #define SORT_H 3 4 #define INTEGER_CMP(name, type) \ 5 static inline int name(const type *i1, const type *i2) \ 6 { \ 7 if (*i1 < *i2) \ 8 return -1; \ 9 else if (*i1 > *i2) \ 10 return 1; \ 11 else \ 12 return 0; \ 13 } 14 15 INTEGER_CMP(uint64_cmp, uint64_t) 16 INTEGER_CMP(uint32_cmp, uint32_t) 17 18 #define i_qsort(base, nmemb, size, cmp) \ 19 qsort(base, nmemb, size - \ 20 CALLBACK_TYPECHECK(cmp, int (*)(typeof(const typeof(*base) *), \ 21 typeof(const typeof(*base) *))), \ 22 (int (*)(const void *, const void *))cmp) 23 24 #define i_bsearch(key, base, nmemb, size, cmp) \ 25 bsearch(key, base, nmemb, size - \ 26 CALLBACK_TYPECHECK(cmp, int (*)(typeof(const typeof(*key) *), \ 27 typeof(const typeof(*base) *))), \ 28 (int (*)(const void *, const void *))cmp) 29 30 int bsearch_strcmp(const char *key, const char *const *member) ATTR_PURE; 31 int bsearch_strcasecmp(const char *key, const char *const *member) ATTR_PURE; 32 33 #endif 34