package / ocaml-base-compiler.4.10.0 / build-aux / ax_func_which_gethostbyname_r.m4
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
64 #serial 8
65
66 AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYNAME_R], [
67
68 AC_LANG_PUSH([C])
69 AC_MSG_CHECKING([how many arguments gethostbyname_r() takes])
70
71 AC_CACHE_VAL([ac_cv_func_which_gethostbyname_r], [
72
73 ################################################################
74
75 ac_cv_func_which_gethostbyname_r=unknown
76
77 #
78 # ONE ARGUMENT (sanity check)
79 #
80
81 # This should fail, as there is no variant of gethostbyname_r() that takes
82 # a single argument. If it actually compiles, then we can assume that
83 # netdb.h is not declaring the function, and the compiler is thereby
84 # assuming an implicit prototype. In which case, we're out of luck.
85 #
86 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
87 [
88 char *name = "www.gnu.org";
89 (void)gethostbyname_r(name) /* ; */
90 ])],
91 [ac_cv_func_which_gethostbyname_r=no])
92
93 #
94 # SIX ARGUMENTS
95 # (e.g. Linux)
96 #
97
98 if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
99
100 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
101 [
102 char *name = "www.gnu.org";
103 struct hostent ret, *retp;
104 char buf@<:@1024@:>@;
105 int buflen = 1024;
106 int my_h_errno;
107 (void)gethostbyname_r(name, &ret, buf, buflen, &retp, &my_h_errno) /* ; */
108 ])],
109 [ac_cv_func_which_gethostbyname_r=six])
110
111 fi
112
113 #
114 # FIVE ARGUMENTS
115 # (e.g. Solaris)
116 #
117
118 if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
119
120 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
121 [
122 char *name = "www.gnu.org";
123 struct hostent ret;
124 char buf@<:@1024@:>@;
125 int buflen = 1024;
126 int my_h_errno;
127 (void)gethostbyname_r(name, &ret, buf, buflen, &my_h_errno) /* ; */
128 ])],
129 [ac_cv_func_which_gethostbyname_r=five])
130
131 fi
132
133 #
134 # THREE ARGUMENTS
135 # (e.g. AIX, HP-UX, Tru64)
136 #
137
138 if test "$ac_cv_func_which_gethostbyname_r" = "unknown"; then
139
140 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
141 [
142 char *name = "www.gnu.org";
143 struct hostent ret;
144 struct hostent_data data;
145 (void)gethostbyname_r(name, &ret, &data) /* ; */
146 ])],
147 [ac_cv_func_which_gethostbyname_r=three])
148
149 fi
150
151 ################################################################
152
153 ]) dnl end AC_CACHE_VAL
154
155 case "$ac_cv_func_which_gethostbyname_r" in
156 three|five|six)
157 AC_DEFINE([HAVE_GETHOSTBYNAME_R], [1],
158 [Define to 1 if you have some form of gethostbyname_r().])
159 ;;
160 esac
161
162 case "$ac_cv_func_which_gethostbyname_r" in
163 three)
164 AC_MSG_RESULT([three])
165 AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_3], [1],
166 [Define to 1 if you have the three-argument form of gethostbyname_r().])
167 ;;
168
169 five)
170 AC_MSG_RESULT([five])
171 AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_5], [1],
172 [Define to 1 if you have the five-argument form of gethostbyname_r().])
173 ;;
174
175 six)
176 AC_MSG_RESULT([six])
177 AC_DEFINE([HAVE_FUNC_GETHOSTBYNAME_R_6], [1],
178 [Define to 1 if you have the six-argument form of gethostbyname_r().])
179 ;;
180
181 no)
182 AC_MSG_RESULT([cannot find function declaration in netdb.h])
183 ;;
184
185 unknown)
186 AC_MSG_RESULT([can't tell])
187 ;;
188
189 *)
190 AC_MSG_ERROR([internal error])
191 ;;
192 esac
193
194 AC_LANG_POP
195
196 ]) dnl end AC_DEFUN
197
198 # Added for OCaml, should be submitted to the autoconf archive
199
200 AC_DEFUN([AX_FUNC_WHICH_GETHOSTBYADDR_R], [
201
202 AC_LANG_PUSH([C])
203 AC_MSG_CHECKING([how many arguments gethostbyaddr_r() takes])
204
205 AC_CACHE_VAL([ac_cv_func_which_gethostbyaddr_r], [
206
207 ################################################################
208
209 ac_cv_func_which_gethostbyaddr_r=unknown
210
211 #
212 # ONE ARGUMENT (sanity check)
213 #
214
215 # This should fail, as there is no variant of gethostbyaddr_r() that takes
216 # a single argument. If it actually compiles, then we can assume that
217 # netdb.h is not declaring the function, and the compiler is thereby
218 # assuming an implicit prototype. In which case, we're out of luck.
219 #
220 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
221 [
222 char *addr = "192.168.1.1";
223 (void)gethostbyaddr_r(addr) /* ; */
224 ])],
225 [ac_cv_func_which_gethostbyaddr_r=no])
226
227 #
228 # EIGHT ARGUMENTS
229 # (e.g. Linux)
230 #
231
232 if test "$ac_cv_func_which_gethostbyaddr_r" = "unknown"; then
233
234 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
235 [
236 char *addr = "192.168.1.1";
237 struct hostent ret, *retp;
238 char buf@<:@1024@:>@;
239 int buflen = 1024;
240 int my_h_errno;
241 (void)gethostbyaddr_r(
242 addr, 10, 10, retp, buf, buflen, &retp, &my_h_errno) /* ; */
243 ])],
244 [ac_cv_func_which_gethostbyaddr_r=eight])
245
246 fi
247
248 #
249 # SEVEN ARGUMENTS
250 # (e.g. Solaris)
251 #
252
253 if test "$ac_cv_func_which_gethostbyaddr_r" = "unknown"; then
254
255 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <netdb.h>],
256 [
257 char *addr = "192.168.1.1";
258 struct hostent ret;
259 char buf@<:@1024@:>@;
260 int buflen = 1024;
261 int my_h_errno;
262 (void)gethostbyaddr_r(
263 addr, 10, 10, buf, buflen, &my_h_errno, 0) /* ; */
264 ])],
265 [ac_cv_func_which_gethostbyaddr_r=seven])
266
267 fi
268
269 ################################################################
270
271 ]) dnl end AC_CACHE_VAL
272
273 case "$ac_cv_func_which_gethostbyaddr_r" in
274 seven|eight)
275 AC_DEFINE([HAVE_GETHOSTBYADDR_R], [1],
276 [Define to 1 if you have some form of gethostbyaddr_r().])
277 ;;
278 esac
279
280 case "$ac_cv_func_which_gethostbyaddr_r" in
281 eight)
282 AC_MSG_RESULT([eight])
283 AC_DEFINE([HAVE_FUNC_GETHOSTBYADDR_R_8], [1],
284 [Define to 1 if you have the eight-argument form of gethostbyaddr_r().])
285 ;;
286
287 seven)
288 AC_MSG_RESULT([seven])
289 AC_DEFINE([HAVE_FUNC_GETHOSTBYADDR_R_7], [1],
290 [Define to 1 if you have the seven-argument form of gethostbyaddr_r().])
291 ;;
292
293 no)
294 AC_MSG_RESULT([cannot find function declaration in netdb.h])
295 ;;
296
297 unknown)
298 AC_MSG_RESULT([can't tell])
299 ;;
300
301 *)
302 AC_MSG_ERROR([internal error])
303 ;;
304 esac
305
306 AC_LANG_POP
307
308 ]) dnl end AC_DEFUN
309