[vlc-devel] [PATCH 4/7] darwin: implement vlc_qsort with FREEBSD qsort_r

Thomas Guillem thomas at gllm.fr
Mon Jan 21 17:43:04 CET 2019


---
 src/Makefile.am    |  3 ++-
 src/darwin/utils.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletion(-)
 create mode 100644 src/darwin/utils.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 7ab5703254..143774d2e6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -454,7 +454,8 @@ libvlccore_la_SOURCES += \
 	darwin/dirs.c \
 	darwin/error.c \
 	darwin/specific.c \
-	darwin/thread.c
+	darwin/thread.c \
+	darwin/utils.c
 
 libvlccore_objc_la_SOURCES = \
 	darwin/netconf.m
diff --git a/src/darwin/utils.c b/src/darwin/utils.c
new file mode 100644
index 0000000000..76fbcf52f7
--- /dev/null
+++ b/src/darwin/utils.c
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * utils.c: Darwin utils back-end
+ ******************************************************************************
+ * Copyright © 2019 VLC authors and VideoLAN
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <vlc_common.h>
+#include <vlc_utils.h>
+
+struct compat_arg
+{
+    int (*compar)(const void *, const void *, void *);
+    void *arg;
+};
+
+static int compar_compat(void *arg, const void *a, const void *b)
+{
+    struct compat_arg *compat_arg = arg;
+    return compat_arg->compar(a, b, compat_arg->arg);
+}
+
+/* Follow the BSD prototype */
+void vlc_qsort(void *base, size_t nmemb, size_t size,
+               int (*compar)(const void *, const void *, void *),
+               void *arg)
+{
+    struct compat_arg compat_arg = {
+        .compar = compar,
+        .arg = arg
+    };
+    qsort_r(base, nmemb, size, &compat_arg, compar_compat);
+}
-- 
2.20.1



More information about the vlc-devel mailing list