summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-15 03:44:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-15 03:44:34 +0000
commita8994b167e270cfa8e42e7b82c510c8e62af360e (patch)
treef291c11f15184f5d1b47cf655c70cf2841b9c521 /util.c
parent5425099a9f536d52fa61bb78d97e79c48368390a (diff)
downloadruby-a8994b167e270cfa8e42e7b82c510c8e62af360e.tar.gz
util.c: BSD qsort_r
* util.c (ruby_qsort): use BSD-style qsort_r if available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/util.c b/util.c
index aede3df62d..89dec0d19b 100644
--- a/util.c
+++ b/util.c
@@ -191,8 +191,30 @@ ruby_strtoul(const char *str, char **endptr, int base)
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
+#if defined HAVE_BSD_QSORT_R
+typedef int (cmpfunc_t)(const void*, const void*, void*);
+
+struct bsd_qsort_r_args {
+ cmpfunc_t *cmp;
+ void *arg;
+};
-#ifndef HAVE_GNU_QSORT_R
+static int
+cmp_bsd_qsort(void *d, const void *a, const void *b)
+{
+ const struct bsd_qsort_r_args *args = d;
+ return (*args->cmp)(a, b, args->arg);
+}
+
+void
+ruby_qsort(void* base, const size_t nel, const size_t size, cmpfunc_t *cmp, void *d)
+{
+ struct bsd_qsort_r_args args;
+ args.cmp = cmp;
+ args.arg = d;
+ qsort_r(base, nel, size, &args, cmp_bsd_qsort);
+}
+#elif !defined HAVE_GNU_QSORT_R
/* mm.c */
#define mmtype long