ax_func_which_gethostbyname_r.m4 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # ==================================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_func_which_gethostbyname_r.html
  3. # ==================================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_FUNC_WHICH_GETHOSTBYNAME_R
  8. #
  9. # DESCRIPTION
  10. #
  11. # Determines which historical variant of the gethostbyname_r() call
  12. # (taking three, five, or six arguments) is available on the system and
  13. # defines one of the following macros accordingly:
  14. #
  15. # HAVE_FUNC_GETHOSTBYNAME_R_6
  16. # HAVE_FUNC_GETHOSTBYNAME_R_5
  17. # HAVE_FUNC_GETHOSTBYNAME_R_3
  18. #
  19. # as well as
  20. #
  21. # HAVE_GETHOSTBYNAME_R
  22. #
  23. # If used in conjunction with gethostname.c, the API demonstrated in
  24. # test.c can be used regardless of which gethostbyname_r() is available.
  25. # These example files can be found at
  26. # http://www.csn.ul.ie/~caolan/publink/gethostbyname_r
  27. #
  28. # based on David Arnold's autoconf suggestion in the threads faq
  29. #
  30. # Originally named "AC_caolan_FUNC_WHICH_GETHOSTBYNAME_R". Rewritten for
  31. # Autoconf 2.5x, and updated for 2.68 by Daniel Richard G.
  32. #
  33. # LICENSE
  34. #
  35. # Copyright (c) 2008 Caolan McNamara <caolan@skynet.ie>
  36. # Copyright (c) 2008 Daniel Richard G. <skunk@iskunk.org>
  37. #
  38. # This program is free software; you can redistribute it and/or modify it
  39. # under the terms of the GNU General Public License as published by the
  40. # Free Software Foundation; either version 2 of the License, or (at your
  41. # option) any later version.
  42. #
  43. # This program is distributed in the hope that it will be useful, but
  44. # WITHOUT ANY WARRANTY; without even the implied warranty of
  45. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  46. # Public License for more details.
  47. #
  48. # You should have received a copy of the GNU General Public License along
  49. # with this program. If not, see <https://www.gnu.org/licenses/>.
  50. #
  51. # As a special exception, the respective Autoconf Macro's copyright owner
  52. # gives unlimited permission to copy, distribute and modify the configure
  53. # scripts that are the output of Autoconf when processing the Macro. You
  54. # need not follow the terms of the GNU General Public License when using
  55. # or distributing such scripts, even though portions of the text of the
  56. # Macro appear in them. The GNU General Public License (GPL) does govern
  57. # all other use of the material that constitutes the Autoconf Macro.
  58. #
  59. # This special exception to the GPL applies to versions of the Autoconf
  60. # Macro released by the Autoconf Archive. When you make and distribute a
  61. # modified version of the Autoconf Macro, you may extend this special
  62. # exception to the GPL to apply to your modified version as well.
  63. #serial 8
  64. AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [
  65. AC_LANG_PUSH([C])
  66. AC_MSG_CHECKING([how many arguments gethostbyname_r() takes])
  67. AC_CACHE_VAL([ac_cv_func_which_gethostbyname_r], [
  68. ################################################################
  69. ac_cv_func_which_gethostbyname_r=unknown
  70. #
  71. # ONE ARGUMENT (sanity check)
  72. #
  73. # This should fail, as there is no variant of gethostbyname_r() that takes
  74. # a single argument. If it actually compiles, then we can assume that
  75. # netdb.h is not declaring the function, and the compiler is thereby
  76. # assuming an implicit prototype. In which case, we're out of luck.
  77. #
  78. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
  79. [
  80. char *name = "www.gnu.org";
  81. (void)gethostbyname_r(name) /* ; */
  82. ])],
  83. [ac_cv_func_which_gethostbyname_r=no])
  84. #
  85. # SIX ARGUMENTS
  86. # (e.g. Linux)
  87. #
  88. if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
  89. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
  90. [
  91. char *name = "www.gnu.org";
  92. struct hostent ret, *retp;
  93. char buf@<:@1024@:>@;
  94. int buflen = 1024;
  95. int my_h_errno;
  96. (void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno) /* ; */
  97. ])],
  98. [ac_cv_func_which_gethostbyname_r=six])
  99. fi
  100. #
  101. # FIVE ARGUMENTS
  102. # (e.g. Solaris)
  103. #
  104. if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
  105. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
  106. [
  107. char *name = "www.gnu.org";
  108. struct hostent ret;
  109. char buf@<:@1024@:>@;
  110. int buflen = 1024;
  111. int my_h_errno;
  112. (void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno) /* ; */
  113. ])],
  114. [ac_cv_func_which_gethostbyname_r=five])
  115. fi
  116. #
  117. # THREE ARGUMENTS
  118. # (e.g. AIX, HP-UX, Tru64)
  119. #
  120. if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
  121. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
  122. [
  123. char *name = "www.gnu.org";
  124. struct hostent ret;
  125. struct hostent_data data;
  126. (void)gethostbyname_r(name, &ret, &data) /* ; */
  127. ])],
  128. [ac_cv_func_which_gethostbyname_r=three])
  129. fi
  130. ################################################################
  131. ]) dnl end AC_CACHE_VAL
  132. case "$ac_cv_func_which_gethostbyname_r" in
  133. three|five|six)
  134. AC_DEFINE([HAVE_GETHOSTBYNAME_R], [1],
  135. [Define to 1 if you have some form of gethostbyname_r().])
  136. ;;
  137. esac
  138. case "$ac_cv_func_which_gethostbyname_r" in
  139. three)
  140. AC_MSG_RESULT([three])
  141. AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_3], [1],
  142. [Define to 1 if you have the three-argument form of gethostbyname_r().])
  143. ;;
  144. five)
  145. AC_MSG_RESULT([five])
  146. AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_5], [1],
  147. [Define to 1 if you have the five-argument form of gethostbyname_r().])
  148. ;;
  149. six)
  150. AC_MSG_RESULT([six])
  151. AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_6], [1],
  152. [Define to 1 if you have the six-argument form of gethostbyname_r().])
  153. ;;
  154. no)
  155. AC_MSG_RESULT([cannot find function declaration in netdb.h])
  156. ;;
  157. unknown)
  158. AC_MSG_RESULT([can't tell])
  159. ;;
  160. *)
  161. AC_MSG_ERROR([internal error])
  162. ;;
  163. esac
  164. AC_LANG_POP
  165. ]) dnl end AC_DEFUN