1010 freely.
1111*/
1212
13+ #ifdef TEST_STDLIB_QSORT
14+ #define _GNU_SOURCE
15+ #include <stdlib.h>
16+ #endif
17+
1318#include <SDL3/SDL.h>
1419#include <SDL3/SDL_main.h>
1520#include <SDL3/SDL_test.h>
@@ -75,8 +80,17 @@ compare_version(const void *_a, const void *_b)
7580 return (int )a -> micro - (int )b -> micro ;
7681}
7782
83+ #ifdef TEST_STDLIB_QSORT
84+ #define SDL_qsort qsort
85+ #define SDL_qsort_r qsort_r
86+ #endif
87+
7888static int SDLCALL
89+ #ifdef TEST_STDLIB_QSORT
90+ generic_compare_r (const void * a , const void * b , void * userdata )
91+ #else
7992generic_compare_r (void * userdata , const void * a , const void * b )
93+ #endif
8094{
8195 if (userdata != & a_global_var ) {
8296 SDLTest_AssertCheck (userdata == & a_global_var , "User data of callback must be identical to global data" );
@@ -153,6 +167,12 @@ generic_compare_r(void *userdata, const void *a, const void *b)
153167 CHECK_ARRAY_ELEMS, IS_LE, "SDL_qsort"); \
154168 } while (0);
155169
170+ #if defined(SDL_PLATFORM_WINDOWS ) && defined(TEST_STDLIB_QSORT )
171+ #define TEST_QSORT_ARRAY_QSORT_R (TYPE , ARRAY , SIZE , COMPARE_CBFN , CHECK_ARRAY_ELEMS , IS_LE ) \
172+ do { \
173+ SDLTest_AssertPass(STR(TYPE) "qsort_r is not available on current platform"); \
174+ } while (0)
175+ #else
156176#define TEST_QSORT_ARRAY_QSORT_R (TYPE , ARRAY , SIZE , COMPARE_CBFN , CHECK_ARRAY_ELEMS , IS_LE ) \
157177 do { \
158178 SDLTest_AssertPass(STR(TYPE) "Testing SDL_qsort_r of array with size %u", (unsigned)(SIZE)); \
@@ -161,6 +181,7 @@ generic_compare_r(void *userdata, const void *a, const void *b)
161181 SDL_qsort_r(sorted, (SIZE), sizeof(TYPE), generic_compare_r, &a_global_var), \
162182 CHECK_ARRAY_ELEMS, IS_LE, "SDL_qsort_r"); \
163183 } while (0);
184+ #endif
164185
165186#define TEST_QSORT_ARRAY (TYPE , ARRAY , SIZE , COMPARE_CBFN , CHECK_ARRAY_ELEMS , IS_LE ) \
166187 do { \
0 commit comments