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,8 +241,9 @@ 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. */
244
+ #if defined(ZSTD_USE_C90_QSORT ) \
245
+ || (!defined(_GNU_SOURCE ) && !defined(__APPLE__ ) && !defined(_MSC_VER ))
246
+ /* Use global context for non-reentrant sort functions */
246
247
static COVER_ctx_t * g_coverCtx = NULL ;
247
248
#endif
248
249
@@ -328,7 +329,7 @@ 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 ) && !defined( ZSTD_USE_C90_QSORT )
332
333
qsort_r (ctx -> suffix , ctx -> suffixSize , sizeof (U32 ),
333
334
(ctx -> d <= 8 ? & COVER_strict_cmp8 : & COVER_strict_cmp ),
334
335
ctx );
@@ -342,7 +343,7 @@ static void stableSort(COVER_ctx_t *ctx) {
342
343
(ctx -> d <= 8 ? & COVER_strict_cmp8 : & COVER_strict_cmp ));
343
344
#else /* C90 fallback.*/
344
345
g_coverCtx = ctx ;
345
- /* TODO(cavalcanti): implement a reentrant qsort() when is not available. */
346
+ /* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */
346
347
qsort (ctx -> suffix , ctx -> suffixSize , sizeof (U32 ),
347
348
(ctx -> d <= 8 ? & COVER_strict_cmp8 : & COVER_strict_cmp ));
348
349
#endif
0 commit comments