Merge pull request 'Fix building on Windows' (#1) from windows_compat into meta
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
+15
-3
@@ -1,6 +1,9 @@
|
|||||||
#ifndef LIBKEKE_ARRAY
|
#ifndef LIBKEKE_ARRAY
|
||||||
#define LIBKEKE_ARRAY
|
#define LIBKEKE_ARRAY
|
||||||
|
|
||||||
|
// Required for qsort_r on Linux
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -185,7 +188,16 @@ void *keke_array_find_start(KekeArray *array, void *start, size_t size) {
|
|||||||
return NULL;
|
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;
|
size_t size = *(size_t *) size_v;
|
||||||
#if defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
#if defined(__BYTE_ORDER__)&&(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||||
return memcmp(a, b, size);
|
return memcmp(a, b, size);
|
||||||
@@ -219,11 +231,11 @@ int compar(const void *a, const void *b, void *size_v) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void keke_array_qsort(KekeArray *array) {
|
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) {
|
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);
|
typedef int (*Rng_fun)(int);
|
||||||
|
|||||||
Reference in New Issue
Block a user