[libkeke_array.c] Use qsort_s on Windows
qsort_r is not completely standardized, so we must accomodate for different platforms. The qsort_s function is available on Windows and we can use macros to transparently change behavior when required.
This commit is contained in:
+12
-3
@@ -185,7 +185,16 @@ void *keke_array_find_start(KekeArray *array, void *start, size_t size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int compar(const void *a, const void *b, void *size_v) {
|
||||
/* Windows uses qsort_s rather than qsort_r and wants a BSD-style comparison function.
|
||||
* This will transparently switch the comparison function based on platform. */
|
||||
#if _WIN32
|
||||
#define qsort_r qsort_s
|
||||
#define compar(a, b, size_v) _compar(size_v, a, b)
|
||||
int _compar(void *size_v, const void *a, const void *b) {
|
||||
#else
|
||||
#define compar(a, b, size_v) _compar(a, b, size_v)
|
||||
int _compar(const void *a, const void *b, void *size_v) {
|
||||
#endif
|
||||
size_t size = *(size_t *) size_v;
|
||||
#if defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
return memcmp(a, b, size);
|
||||
@@ -219,11 +228,11 @@ int compar(const void *a, const void *b, void *size_v) {
|
||||
}
|
||||
|
||||
void keke_array_qsort(KekeArray *array) {
|
||||
qsort_r(array->content, array->len, array->type_size, compar, &array->type_size);
|
||||
qsort_r(array->content, array->len, array->type_size, _compar, &array->type_size);
|
||||
}
|
||||
|
||||
void keke_array_qsort_header(KekeArray *array, size_t start_header_size) {
|
||||
qsort_r(array->content, array->len, array->type_size, compar, &start_header_size);
|
||||
qsort_r(array->content, array->len, array->type_size, _compar, &start_header_size);
|
||||
}
|
||||
|
||||
typedef int (*Rng_fun)(int);
|
||||
|
||||
Reference in New Issue
Block a user