24
24
/* qsort_r is an extension. */
25
25
#if defined(__linux ) || defined(__linux__ ) || defined(linux ) || defined(__gnu_linux__ ) || \
26
26
defined(__CYGWIN__ ) || defined(__MSYS__ )
27
- #if !defined(_GNU_SOURCE ) && !defined(__ANDROID__ ) /* NDK doesn't ship qsort_r(). */
28
- #define _GNU_SOURCE
29
- #endif
27
+ # if !defined(_GNU_SOURCE ) && !defined(__ANDROID__ ) /* NDK doesn't ship qsort_r(). */
28
+ # define _GNU_SOURCE
29
+ # endif
30
30
#endif
31
31
32
32
#include <stdio.h> /* fprintf */
@@ -241,9 +241,10 @@ typedef struct {
241
241
unsigned d ;
242
242
} COVER_ctx_t ;
243
243
244
- #if !defined(_GNU_SOURCE ) && !defined(__APPLE__ ) && !defined(_MSC_VER )
245
- /* C90 only offers qsort() that needs a global context. */
246
- static COVER_ctx_t * g_coverCtx = NULL ;
244
+ #if (!defined(_GNU_SOURCE ) && !defined(__APPLE__ ) && !defined(_MSC_VER )) \
245
+ || (defined(__MUSL__ ) && __MUSL__ < 0x01020300 )
246
+ /* global context needed for non-reentrant sorting functions */
247
+ static COVER_ctx_t * g_coverCtx = NULL ;
247
248
#endif
248
249
249
250
/*-*************************************
@@ -328,7 +329,8 @@ static void stableSort(COVER_ctx_t *ctx) {
328
329
qsort_r (ctx -> suffix , ctx -> suffixSize , sizeof (U32 ),
329
330
ctx ,
330
331
(ctx -> d <= 8 ? & COVER_strict_cmp8 : & COVER_strict_cmp ));
331
- #elif defined(_GNU_SOURCE )
332
+ #elif defined(_GNU_SOURCE ) \
333
+ && !(defined(__MUSL__ ) && __MUSL__ < 0x01020300 ) /* musl only provides qsort_r starting v1.2.3 */
332
334
qsort_r (ctx -> suffix , ctx -> suffixSize , sizeof (U32 ),
333
335
(ctx -> d <= 8 ? & COVER_strict_cmp8 : & COVER_strict_cmp ),
334
336
ctx );
@@ -342,7 +344,7 @@ static void stableSort(COVER_ctx_t *ctx) {
342
344
(ctx -> d <= 8 ? & COVER_strict_cmp8 : & COVER_strict_cmp ));
343
345
#else /* C90 fallback.*/
344
346
g_coverCtx = ctx ;
345
- /* TODO(cavalcanti): implement a reentrant qsort() when is not available. */
347
+ /* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */
346
348
qsort (ctx -> suffix , ctx -> suffixSize , sizeof (U32 ),
347
349
(ctx -> d <= 8 ? & COVER_strict_cmp8 : & COVER_strict_cmp ));
348
350
#endif
0 commit comments