Config check for qsort_s/qsort_r

This commit is contained in:
Olof hagsand 2024-10-25 19:24:37 +02:00
parent 0b78c9ded0
commit 582bf3feb1
4 changed files with 24 additions and 1 deletions

9
configure vendored
View file

@ -7006,6 +7006,15 @@ then :
fi 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 test "x$prefix" = xNONE && prefix=$ac_default_prefix

View file

@ -458,6 +458,9 @@ fi
# Dummy to disable native language support (nls) to remove warnings in buildroot # Dummy to disable native language support (nls) to remove warnings in buildroot
AC_ARG_ENABLE(nls) AC_ARG_ENABLE(nls)
# Check to use freebsd:s qsort_s instead of linux qsort_r
AC_CHECK_FUNCS(qsort_s)
AH_BOTTOM([#include <clixon_custom.h>]) AH_BOTTOM([#include <clixon_custom.h>])
test "x$prefix" = xNONE && prefix=$ac_default_prefix test "x$prefix" = xNONE && prefix=$ac_default_prefix

View file

@ -102,6 +102,9 @@
/* Define to 1 if you have the <nghttp2/nghttp2.h> header file. */ /* Define to 1 if you have the <nghttp2/nghttp2.h> header file. */
#undef HAVE_NGHTTP2_NGHTTP2_H #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. */ /* Define to 1 if you have the `setns' function. */
#undef HAVE_SETNS #undef HAVE_SETNS

View file

@ -41,7 +41,7 @@
#endif #endif
#include <stdio.h> #include <stdio.h>
#define __USE_GNU /* for qsort_r */ #define __USE_GNU /* for qsort_r or qsort_s */
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
@ -434,7 +434,11 @@ xml_sort_by(cxobj *x,
char *indexvar) char *indexvar)
{ {
xml_enumerate_children(x); /* This is to make sorting "stable", ie not change existing order */ 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); qsort_r(xml_childvec_get(x), xml_child_nr(x), sizeof(cxobj *), xml_cmp_qsort, indexvar);
#endif
return 0; return 0;
} }
@ -459,7 +463,11 @@ xml_sort(cxobj *x)
return 1; return 1;
#endif #endif
xml_enumerate_children(x); /* This is to make sorting "stable", ie not change existing order */ 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); qsort_r(xml_childvec_get(x), xml_child_nr(x), sizeof(cxobj *), xml_cmp_qsort, NULL);
#endif
return 0; return 0;
} }