[vlc-devel] [PATCH V2 5/8] freebsd: implement vlc_qsort with FREEBSD or POSIX qsort_r

Thomas Guillem thomas at gllm.fr
Tue Jan 22 11:13:22 CET 2019


---
 src/Makefile.am     |  5 ++++
 src/freebsd/utils.c | 62 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 src/freebsd/utils.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 7ab5703254..566e190d52 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -489,6 +489,11 @@ endif
 endif
 endif
 
+if HAVE_FREEBSD
+libvlccore_la_SOURCES += \
+	freebsd/utils.c
+endif
+
 if ENABLE_SOUT
 libvlccore_la_SOURCES += \
 	stream_output/sap.c stream_output/sdp.c \
diff --git a/src/freebsd/utils.c b/src/freebsd/utils.c
new file mode 100644
index 0000000000..dbcc2c9bde
--- /dev/null
+++ b/src/freebsd/utils.c
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * utils.c: FreeBSD 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>
+
+#if defined (__MACH__) || __FreeBSD__ < 13
+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 FreeBSD <= 12 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);
+}
+
+#else
+
+/* Follow the POSIX prototype */
+void vlc_qsort(void *base, size_t nmemb, size_t size,
+               int (*compar)(const void *, const void *, void *),
+               void *arg)
+{
+    qsort_r(base, nmemb, size, compar, arg);
+}
+#endif
-- 
2.20.1



More information about the vlc-devel mailing list