tsearch.m4 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # tsearch.m4 serial 6
  2. dnl Copyright (C) 2006-2017 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_DEFUN([gl_FUNC_TSEARCH],
  7. [
  8. AC_REQUIRE([gl_SEARCH_H_DEFAULTS])
  9. AC_CHECK_FUNCS([tsearch])
  10. if test $ac_cv_func_tsearch = yes; then
  11. dnl On OpenBSD 4.0, the return value of tdelete() is incorrect.
  12. AC_REQUIRE([AC_PROG_CC])
  13. AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
  14. AC_CACHE_CHECK([whether tdelete works], [gl_cv_func_tdelete_works],
  15. [
  16. AC_RUN_IFELSE([AC_LANG_SOURCE([[
  17. #include <stddef.h>
  18. #include <search.h>
  19. static int
  20. cmp_fn (const void *a, const void *b)
  21. {
  22. return *(const int *) a - *(const int *) b;
  23. }
  24. int
  25. main ()
  26. {
  27. int result = 0;
  28. int x = 0;
  29. void *root = NULL;
  30. if (!(tfind (&x, &root, cmp_fn) == NULL))
  31. result |= 1;
  32. tsearch (&x, &root, cmp_fn);
  33. if (!(tfind (&x, &root, cmp_fn) != NULL))
  34. result |= 2;
  35. if (!(tdelete (&x, &root, cmp_fn) != NULL))
  36. result |= 4;
  37. return result;
  38. }]])], [gl_cv_func_tdelete_works=yes], [gl_cv_func_tdelete_works=no],
  39. [case "$host_os" in
  40. openbsd*) gl_cv_func_tdelete_works="guessing no";;
  41. *) gl_cv_func_tdelete_works="guessing yes";;
  42. esac
  43. ])
  44. ])
  45. case "$gl_cv_func_tdelete_works" in
  46. *no)
  47. REPLACE_TSEARCH=1
  48. ;;
  49. esac
  50. else
  51. HAVE_TSEARCH=0
  52. fi
  53. ])
  54. # Prerequisites of lib/tsearch.c.
  55. AC_DEFUN([gl_PREREQ_TSEARCH], [
  56. :
  57. ])