tsearch.m4 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # tsearch.m4 serial 8
  2. dnl Copyright (C) 2006-2021 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 twalk])
  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. # Guess yes on native Windows.
  42. mingw*) gl_cv_func_tdelete_works="guessing yes" ;;
  43. *) gl_cv_func_tdelete_works="guessing yes" ;;
  44. esac
  45. ])
  46. ])
  47. case "$gl_cv_func_tdelete_works" in
  48. *no)
  49. REPLACE_TSEARCH=1
  50. ;;
  51. esac
  52. else
  53. HAVE_TSEARCH=0
  54. fi
  55. if test $ac_cv_func_twalk != yes; then
  56. HAVE_TWALK=0
  57. fi
  58. ])
  59. # Prerequisites of lib/tsearch.c.
  60. AC_DEFUN([gl_PREREQ_TSEARCH], [
  61. :
  62. ])