From 582bf3feb188eef67bc6ef4916634fa9c5e8826c Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Fri, 25 Oct 2024 19:24:37 +0200 Subject: [PATCH] Config check for qsort_s/qsort_r --- configure | 9 +++++++++ configure.ac | 3 +++ include/clixon_config.h.in | 3 +++ lib/src/clixon_xml_sort.c | 10 +++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 161c0032..7b134cf0 100755 --- a/configure +++ b/configure @@ -7006,6 +7006,15 @@ then : fi +# Check to use freebsd:s qsort_s instead of linux qsort_r +ac_fn_c_check_func "$LINENO" "qsort_s" "ac_cv_func_qsort_s" +if test "x$ac_cv_func_qsort_s" = xyes +then : + printf "%s\n" "#define HAVE_QSORT_S 1" >>confdefs.h + +fi + + test "x$prefix" = xNONE && prefix=$ac_default_prefix diff --git a/configure.ac b/configure.ac index 5a2e4239..c4306515 100644 --- a/configure.ac +++ b/configure.ac @@ -458,6 +458,9 @@ fi # Dummy to disable native language support (nls) to remove warnings in buildroot AC_ARG_ENABLE(nls) +# Check to use freebsd:s qsort_s instead of linux qsort_r +AC_CHECK_FUNCS(qsort_s) + AH_BOTTOM([#include ]) test "x$prefix" = xNONE && prefix=$ac_default_prefix diff --git a/include/clixon_config.h.in b/include/clixon_config.h.in index 3fc0b830..27750f3f 100644 --- a/include/clixon_config.h.in +++ b/include/clixon_config.h.in @@ -102,6 +102,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NGHTTP2_NGHTTP2_H +/* Define to 1 if you have the `qsort_s' function. */ +#undef HAVE_QSORT_S + /* Define to 1 if you have the `setns' function. */ #undef HAVE_SETNS diff --git a/lib/src/clixon_xml_sort.c b/lib/src/clixon_xml_sort.c index c4737a45..301cab7e 100644 --- a/lib/src/clixon_xml_sort.c +++ b/lib/src/clixon_xml_sort.c @@ -41,7 +41,7 @@ #endif #include -#define __USE_GNU /* for qsort_r */ +#define __USE_GNU /* for qsort_r or qsort_s */ #include #include #include @@ -434,7 +434,11 @@ xml_sort_by(cxobj *x, char *indexvar) { xml_enumerate_children(x); /* This is to make sorting "stable", ie not change existing order */ +#ifdef HAVE_QSORT_S + qsort_s(xml_childvec_get(x), xml_child_nr(x), sizeof(cxobj *), xml_cmp_qsort, indexvar); +#else qsort_r(xml_childvec_get(x), xml_child_nr(x), sizeof(cxobj *), xml_cmp_qsort, indexvar); +#endif return 0; } @@ -459,7 +463,11 @@ xml_sort(cxobj *x) return 1; #endif xml_enumerate_children(x); /* This is to make sorting "stable", ie not change existing order */ +#ifdef HAVE_QSORT_S + qsort_s(xml_childvec_get(x), xml_child_nr(x), sizeof(cxobj *), xml_cmp_qsort, NULL); +#else qsort_r(xml_childvec_get(x), xml_child_nr(x), sizeof(cxobj *), xml_cmp_qsort, NULL); +#endif return 0; }