aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac124
-rw-r--r--m4/search_h.m466
-rw-r--r--m4/tsearch.m464
-rw-r--r--src/lib/Makefile.am2
-rw-r--r--src/microhttpd/Makefile.am2
-rw-r--r--src/microhttpd/daemon.c6
6 files changed, 122 insertions, 142 deletions
diff --git a/configure.ac b/configure.ac
index 0787464b..639c15ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -525,14 +525,124 @@ AC_CHECK_HEADERS([sys/msg.h sys/mman.h signal.h], [], [], [AC_INCLUDES_DEFAULT])
525 525
526AC_CHECK_HEADER([[search.h]], 526AC_CHECK_HEADER([[search.h]],
527 [ 527 [
528 gl_FUNC_TSEARCH 528 MHD_CHECK_LINK_RUN([[for proper tsearch(), tfind() and tdelete()]],[[mhd_cv_sys_tsearch_usable]],
529 AS_IF([[test "x$HAVE_TSEARCH" = "x1" && test "x$REPLACE_TSEARCH" != "x1"]], 529 [
530 [AC_DEFINE([[HAVE_SEARCH_H]], [[1]], 530 AS_CASE([$host_os],
531 [Define to 1 if you have the <search.h> header file and your system have properly functioning tsearch(), tfind() and tdelete() functions])]) 531 [openbsd*],
532 ], 532 [[ # Some OpenBSD versions have wrong return value for tdelete()
533 [], [AC_INCLUDES_DEFAULT]) 533 mhd_cv_sys_tsearch_usable='assuming no'
534 ]],
535 [netbsd*],
536 [[ # NetBSD had leaked root node for years
537 mhd_cv_sys_tsearch_usable='assuming no'
538 ]],
539 [[mhd_cv_sys_tsearch_usable='assuming yes']]
540 )
541 ],
542 [
543 AC_LANG_SOURCE(
544 [[
545#ifdef HAVE_STDDEF_H
546#include <stddef.h>
547#endif /* HAVE_STDDEF_H */
548#ifdef HAVE_STDLIB_H
549#include <stdlib.h>
550#endif /* HAVE_STDLIB_H */
551
552#include <stdio.h>
553#include <search.h>
534 554
535AM_CONDITIONAL([MHD_HAVE_TSEARCH], [[test "x$ac_cv_header_search_h" = xyes && test "x$HAVE_TSEARCH" = "x1" && test "x$REPLACE_TSEARCH" != "x1"]]) 555static int cmp_func(const void *p1, const void *p2)
556{
557 return (*((const int *)p1)) - (*((const int *)p2));
558}
559
560int main(void)
561{
562 int ret = 0;
563 void *root_ptr = NULL;
564 int element1 = 1;
565 int **element_ptr_ptr1;
566 int **element_ptr_ptr2;
567
568 element_ptr_ptr1 =
569 (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func);
570 if (NULL == element_ptr_ptr1)
571 {
572 fprintf (stderr, "NULL pointer has been returned when tsearch() called for the first time.\n");
573 return ++ret;
574 }
575 if (*element_ptr_ptr1 != &element1)
576 {
577 fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the first time.\n");
578 return ++ret;
579 }
580 if (NULL == root_ptr)
581 {
582 fprintf (stderr, "Root pointer has not been set by tsearch().\n");
583 return ++ret;
584 }
585
586 element_ptr_ptr2 =
587 (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func);
588 if (NULL == element_ptr_ptr2)
589 {
590 fprintf (stderr, "NULL pointer has been returned when tsearch() called for the second time.\n");
591 return ++ret;
592 }
593 if (*element_ptr_ptr2 != &element1)
594 {
595 fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the second time.\n");
596 ++ret;
597 }
598 if (element_ptr_ptr2 != element_ptr_ptr1)
599 {
600 fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n");
601 ++ret;
602 }
603
604 element_ptr_ptr2 =
605 (int **) tfind ((void*) &element1, &root_ptr, &cmp_func);
606 if (NULL == element_ptr_ptr2)
607 {
608 fprintf (stderr, "NULL pointer has been returned by tfind().\n");
609 ++ret;
610 }
611 if (*element_ptr_ptr2 != &element1)
612 {
613 fprintf (stderr, "Wrong pointer has been returned when by tfind().\n");
614 ++ret;
615 }
616 if (element_ptr_ptr2 != element_ptr_ptr1)
617 {
618 fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n");
619 ++ret;
620 }
621
622 element_ptr_ptr1 =
623 (int **) tdelete ((void*) &element1, &root_ptr, &cmp_func);
624 if (NULL == element_ptr_ptr1)
625 {
626 fprintf (stderr, "NULL pointer has been returned by tdelete().\n");
627 ++ret;
628 }
629 if (NULL != root_ptr)
630 {
631 fprintf (stderr, "Root pointer has not been set to NULL by tdelete().\n");
632 ++ret;
633 }
634
635 return ret;
636}
637 ]]
638 )
639 ],
640 [AC_DEFINE([[MHD_USE_SYS_TSEARCH]], [[1]], [Define to 1 if you have properly working tsearch(), tfind() and tdelete() functions.])]
641 )
642 ],
643 [], [AC_INCLUDES_DEFAULT]
644)
645AM_CONDITIONAL([MHD_USE_SYS_TSEARCH], [[test "x$mhd_cv_sys_tsearch_usable" = "xyes" || test "x$mhd_cv_sys_tsearch_usable" = "xassuming yes"]])
536 646
537# Optional headers used for tests 647# Optional headers used for tests
538AC_CHECK_HEADERS([sys/sysctl.h netinet/ip_icmp.h netinet/icmp_var.h], [], [], 648AC_CHECK_HEADERS([sys/sysctl.h netinet/ip_icmp.h netinet/icmp_var.h], [], [],
diff --git a/m4/search_h.m4 b/m4/search_h.m4
deleted file mode 100644
index 9fafc716..00000000
--- a/m4/search_h.m4
+++ /dev/null
@@ -1,66 +0,0 @@
1# search_h.m4 serial 12
2dnl Copyright (C) 2007-2021 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_SEARCH_H],
8[
9 AC_REQUIRE([gl_SEARCH_H_DEFAULTS])
10 gl_CHECK_NEXT_HEADERS([search.h])
11 if test $ac_cv_header_search_h = yes; then
12 HAVE_SEARCH_H=1
13 else
14 HAVE_SEARCH_H=0
15 fi
16 AC_SUBST([HAVE_SEARCH_H])
17
18 if test $HAVE_SEARCH_H = 1; then
19 AC_CACHE_CHECK([for type VISIT], [gl_cv_type_VISIT],
20 [AC_COMPILE_IFELSE(
21 [AC_LANG_PROGRAM(
22 [[#if HAVE_SEARCH_H
23 #include <search.h>
24 #endif
25 ]],
26 [[static VISIT x; x = postorder;]])],
27 [gl_cv_type_VISIT=yes],
28 [gl_cv_type_VISIT=no])])
29 else
30 gl_cv_type_VISIT=no
31 fi
32 if test $gl_cv_type_VISIT = yes; then
33 HAVE_TYPE_VISIT=1
34 else
35 HAVE_TYPE_VISIT=0
36 fi
37 AC_SUBST([HAVE_TYPE_VISIT])
38
39 dnl Check for declarations of anything we want to poison if the
40 dnl corresponding gnulib module is not in use.
41 gl_WARN_ON_USE_PREPARE([[#include <search.h>
42 ]], [tdelete tfind tsearch twalk])
43
44 AC_REQUIRE([AC_C_RESTRICT])
45])
46
47AC_DEFUN([gl_SEARCH_MODULE_INDICATOR],
48[
49 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
50 AC_REQUIRE([gl_SEARCH_H_DEFAULTS])
51 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
52 dnl Define it also as a C macro, for the benefit of the unit tests.
53 gl_MODULE_INDICATOR_FOR_TESTS([$1])
54])
55
56AC_DEFUN([gl_SEARCH_H_DEFAULTS],
57[
58 GNULIB_TSEARCH=0; AC_SUBST([GNULIB_TSEARCH])
59 dnl Support Microsoft deprecated alias function names by default.
60 GNULIB_MDA_LFIND=1; AC_SUBST([GNULIB_MDA_LFIND])
61 GNULIB_MDA_LSEARCH=1; AC_SUBST([GNULIB_MDA_LSEARCH])
62 dnl Assume proper GNU behavior unless another module says otherwise.
63 HAVE_TSEARCH=1; AC_SUBST([HAVE_TSEARCH])
64 HAVE_TWALK=1; AC_SUBST([HAVE_TWALK])
65 REPLACE_TSEARCH=0; AC_SUBST([REPLACE_TSEARCH])
66])
diff --git a/m4/tsearch.m4 b/m4/tsearch.m4
deleted file mode 100644
index 9f8782e4..00000000
--- a/m4/tsearch.m4
+++ /dev/null
@@ -1,64 +0,0 @@
1# tsearch.m4 serial 8
2dnl Copyright (C) 2006-2021 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_TSEARCH],
8[
9 AC_REQUIRE([gl_SEARCH_H_DEFAULTS])
10 AC_CHECK_FUNCS([tsearch twalk])
11 if test $ac_cv_func_tsearch = yes; then
12 dnl On OpenBSD 4.0, the return value of tdelete() is incorrect.
13 AC_REQUIRE([AC_PROG_CC])
14 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 AC_CACHE_CHECK([whether tdelete works], [gl_cv_func_tdelete_works],
16 [
17 AC_RUN_IFELSE([AC_LANG_SOURCE([[
18#include <stddef.h>
19#include <search.h>
20static int
21cmp_fn (const void *a, const void *b)
22{
23 return *(const int *) a - *(const int *) b;
24}
25int
26main ()
27{
28 int result = 0;
29 int x = 0;
30 void *root = NULL;
31 if (!(tfind (&x, &root, cmp_fn) == NULL))
32 result |= 1;
33 tsearch (&x, &root, cmp_fn);
34 if (!(tfind (&x, &root, cmp_fn) != NULL))
35 result |= 2;
36 if (!(tdelete (&x, &root, cmp_fn) != NULL))
37 result |= 4;
38 return result;
39}]])], [gl_cv_func_tdelete_works=yes], [gl_cv_func_tdelete_works=no],
40 [case "$host_os" in
41 openbsd*) gl_cv_func_tdelete_works="guessing no" ;;
42 # Guess yes on native Windows.
43 mingw*) gl_cv_func_tdelete_works="guessing yes" ;;
44 *) gl_cv_func_tdelete_works="guessing yes" ;;
45 esac
46 ])
47 ])
48 case "$gl_cv_func_tdelete_works" in
49 *no)
50 REPLACE_TSEARCH=1
51 ;;
52 esac
53 else
54 HAVE_TSEARCH=0
55 fi
56 if test $ac_cv_func_twalk != yes; then
57 HAVE_TWALK=0
58 fi
59])
60
61# Prerequisites of lib/tsearch.c.
62AC_DEFUN([gl_PREREQ_TSEARCH], [
63 :
64])
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index a0f71779..33bfd034 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -156,7 +156,7 @@ if USE_COVERAGE
156 AM_CFLAGS += --coverage 156 AM_CFLAGS += --coverage
157endif 157endif
158 158
159if !MHD_HAVE_TSEARCH 159if !MHD_USE_SYS_TSEARCH
160libmicrohttpd2_la_SOURCES += \ 160libmicrohttpd2_la_SOURCES += \
161 tsearch.c tsearch.h 161 tsearch.c tsearch.h
162endif 162endif
diff --git a/src/microhttpd/Makefile.am b/src/microhttpd/Makefile.am
index 8e6e623a..36ad802f 100644
--- a/src/microhttpd/Makefile.am
+++ b/src/microhttpd/Makefile.am
@@ -153,7 +153,7 @@ if USE_COVERAGE
153 AM_CFLAGS += --coverage 153 AM_CFLAGS += --coverage
154endif 154endif
155 155
156if !MHD_HAVE_TSEARCH 156if !MHD_USE_SYS_TSEARCH
157libmicrohttpd_la_SOURCES += \ 157libmicrohttpd_la_SOURCES += \
158 tsearch.c tsearch.h 158 tsearch.c tsearch.h
159endif 159endif
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index c9c0d51c..5e9be378 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -47,11 +47,11 @@
47#include "mhd_align.h" 47#include "mhd_align.h"
48#include "mhd_str.h" 48#include "mhd_str.h"
49 49
50#ifdef HAVE_SEARCH_H 50#ifdef MHD_USE_SYS_TSEARCH
51#include <search.h> 51#include <search.h>
52#else 52#else /* ! MHD_USE_SYS_TSEARCH */
53#include "tsearch.h" 53#include "tsearch.h"
54#endif 54#endif /* ! MHD_USE_SYS_TSEARCH */
55 55
56#ifdef HTTPS_SUPPORT 56#ifdef HTTPS_SUPPORT
57#include "connection_https.h" 57#include "connection_https.h"