Last active
June 24, 2021 11:50
-
-
Save flatcap/be725546479648df4f76fd12aafb5c34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
// void qsort (void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); | |
// void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg); | |
typedef int (*qsort_compar_t) (const void *a, const void *b); | |
typedef int (*qsort_r_compar_t)(const void *a, const void *b, void *arg); | |
static qsort_r_compar_t global_compar = NULL; | |
static void *global_data = NULL; | |
static int relay_compar(const void *a, const void *b) | |
{ | |
return global_compar(a, b, global_data); | |
} | |
void mutt_qsort_r(void *base, size_t nmemb, size_t size, qsort_r_compar_t compar, void *arg) | |
{ | |
assert((global_compar == NULL) && (global_data == NULL)); | |
global_compar = compar; | |
global_data = arg; | |
qsort(base, nmemb, size, relay_compar); | |
global_compar = NULL; | |
global_data = NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment