diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:36:47 +0000 |
commit | 0441d265f2bb9da249c7abf333f0f771fadb4ab5 (patch) | |
tree | 3f3789daa2f6db22da6e55e92bee0062a7d613fe /src/lib/sort.h | |
parent | Initial commit. (diff) | |
download | dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.tar.xz dovecot-0441d265f2bb9da249c7abf333f0f771fadb4ab5.zip |
Adding upstream version 1:2.3.21+dfsg1.upstream/1%2.3.21+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/sort.h')
-rw-r--r-- | src/lib/sort.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/sort.h b/src/lib/sort.h new file mode 100644 index 0000000..94cab81 --- /dev/null +++ b/src/lib/sort.h @@ -0,0 +1,33 @@ +#ifndef SORT_H +#define SORT_H + +#define INTEGER_CMP(name, type) \ + static inline int name(const type *i1, const type *i2) \ + { \ + if (*i1 < *i2) \ + return -1; \ + else if (*i1 > *i2) \ + return 1; \ + else \ + return 0; \ + } + +INTEGER_CMP(uint64_cmp, uint64_t) +INTEGER_CMP(uint32_cmp, uint32_t) + +#define i_qsort(base, nmemb, size, cmp) \ + qsort(base, nmemb, size - \ + CALLBACK_TYPECHECK(cmp, int (*)(typeof(const typeof(*base) *), \ + typeof(const typeof(*base) *))), \ + (int (*)(const void *, const void *))cmp) + +#define i_bsearch(key, base, nmemb, size, cmp) \ + bsearch(key, base, nmemb, size - \ + CALLBACK_TYPECHECK(cmp, int (*)(typeof(const typeof(*key) *), \ + typeof(const typeof(*base) *))), \ + (int (*)(const void *, const void *))cmp) + +int bsearch_strcmp(const char *key, const char *const *member) ATTR_PURE; +int bsearch_strcasecmp(const char *key, const char *const *member) ATTR_PURE; + +#endif |