22#ifndef LELY_UTIL_CMP_H_
23#define LELY_UTIL_CMP_H_
34#ifndef LELY_UTIL_CMP_INLINE
35#define LELY_UTIL_CMP_INLINE static inline
50typedef int cmp_t(
const void *p1,
const void *p2);
52#define LELY_UTIL_DEFINE_TYPE(name, type) \
53 LELY_UTIL_CMP_INLINE int name##_cmp(const void *p1, const void *p2);
54#include <lely/util/def/type.def>
55LELY_UTIL_DEFINE_TYPE(ptr, )
56LELY_UTIL_DEFINE_TYPE(str, )
57LELY_UTIL_DEFINE_TYPE(str_case, )
58#undef LELY_UTIL_DEFINE_TYPE
60#define LELY_UTIL_DEFINE_TYPE(name, type) \
61 inline int name##_cmp(const void *p1, const void *p2) \
71 type v1 = *(const type *)p1; \
72 type v2 = *(const type *)p2; \
73 return (v2 < v1) - (v1 < v2); \
75#include <lely/util/def/type.def>
76#undef LELY_UTIL_DEFINE_TYPE
78LELY_UTIL_CMP_INLINE
int
79ptr_cmp(
const void *p1,
const void *p2)
81 uintptr_t v1 = (uintptr_t)p1;
82 uintptr_t v2 = (uintptr_t)p2;
83 return (v2 < v1) - (v1 < v2);
86LELY_UTIL_CMP_INLINE
int
87str_cmp(
const void *p1,
const void *p2)
97 return strcmp((
const char *)p1, (
const char *)p2);
100LELY_UTIL_CMP_INLINE
int
101str_case_cmp(
const void *p1,
const void *p2)
111 return strcasecmp((
const char *)p1, (
const char *)p2);
int cmp_t(const void *p1, const void *p2)
The type of a generic comparison function.
This is the public header file of the utilities library.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
This header file is part of the C11 and POSIX compatibility library; it includes <string....
This header file is part of the C11 and POSIX compatibility library; it includes <strings....
This header file is part of the C11 and POSIX compatibility library; it includes <uchar....