summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-28 19:27:23 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-28 19:27:23 -0500
commit0e57122ecfd554131fd6ad54fcbb556733bf6c88 (patch)
treea25bf21ab7a5d28629f09cb042ce836439905ceb
parentac3563dce6c0cceef83f4e838365178da4602507 (diff)
qsort_with_context on systems without qsort_r/s
-rw-r--r--main.c5
-rw-r--r--util.c11
2 files changed, 15 insertions, 1 deletions
diff --git a/main.c b/main.c
index 176f972..8248ac3 100644
--- a/main.c
+++ b/main.c
@@ -179,6 +179,11 @@ int main(int argc, char **argv) {
}
#endif
}
+ #if TED_FORCE_SEARCH_CWD
+ // override whether or not we are in the executable's directory
+ // (for testing on Unix systems without /proc)
+ ted->search_cwd = true;
+ #endif
Settings *settings = &ted->settings;
diff --git a/util.c b/util.c
index b68efd3..d805830 100644
--- a/util.c
+++ b/util.c
@@ -191,6 +191,12 @@ static int str_qsort_case_insensitive_cmp(const void *av, const void *bv) {
return strcmp_case_insensitive(*a, *b);
}
+static void *qsort_ctx_data;
+static int (*qsort_ctx_cmp)(const void *, const void *, void *data);
+static int qsort_with_context_cmp(const void *a, const void *b) {
+ return qsort_ctx_cmp(a, b, qsort_ctx_data);
+}
+
// qsort but with a user void*
static void qsort_with_context(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg) {
#if _WIN32
@@ -199,6 +205,9 @@ static void qsort_with_context(void *base, size_t nmemb, size_t size, int (*comp
// GNU doesn't have qsort_s ):
qsort_r(base, nmemb, size, compar, arg);
#else
-#error "No qsort_r/qsort_s. You can try filling in this function if you know what you're doing."
+ // just use global variables. hopefully we don't try to run this in something multithreaded!
+ qsort_ctx_data = arg;
+ qsort_ctx_cmp = compar;
+ qsort(base, nmemb, size, qsort_with_context_cmp);
#endif
}