[vlc-devel] [PATCH] compat: work-around busted FreeBSD qsort_r()

RĂ©mi Denis-Courmont remi at remlab.net
Tue Nov 20 17:16:33 CET 2018


This is untested.
---
 configure.ac         | 15 +++++++++++++++
 include/vlc_fixups.h |  4 ++++
 2 files changed, 19 insertions(+)

diff --git a/configure.ac b/configure.ac
index 1f33f5dc88..21fcb45203 100644
--- a/configure.ac
+++ b/configure.ac
@@ -742,6 +742,21 @@ AC_CHECK_LIB([m], [sincos], [
   AC_LIBOBJ([sincos])
 ])
 
+AC_MSG_CHECKING([broken qsort_r prototype])
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <stdlib.h>
+
+_Static_assert(_Generic((qsort_r),
+    void (*)(void *, size_t, size_t, void *,
+             int (*)(void *, const void *, const void *)) : 1, default: 0),
+    "Bad prototype not matched");
+])], [
+  AC_MSG_RESULT([broken])
+  AC_DEFINE([HAVE_BROKEN_QSORT_R], 1, [Defined to 1 if the qsort_r() prototype contradicts the upcoming POSIX standard.])
+  AC_LIBOBJ([qsort_r])
+], [
+  AC_MSG_RESULT([no])
+])
+
 AC_MSG_CHECKING([_Thread_local support])
 AC_COMPILE_IFELSE([AC_LANG_SOURCE([_Thread_local int foo = 0;
                    int main() {}])], [
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 0263286efc..45fec0f6d4 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -224,6 +224,10 @@ long long atoll (const char *);
 lldiv_t lldiv (long long, long long);
 #endif
 
+#ifdef HAVE_BROKEN_QSORT_R
+# define qsort_r posix_qsort_r
+#endif
+
 #ifndef HAVE_QSORT_R
 void (qsort_r)(void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *);
-- 
2.19.1



More information about the vlc-devel mailing list