The error buffer was not getting filled when Curl_wait_for_resolv() fails.
[platform/upstream/curl.git] / acinclude.m4
1 dnl Check for how to set a socket to non-blocking state. There seems to exist
2 dnl four known different ways, with the one used almost everywhere being POSIX
3 dnl and XPG3, while the other different ways for different systems (old BSD,
4 dnl Windows and Amiga).
5 dnl
6 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
7 dnl O_NONBLOCK define is found but does not work. This condition is attempted
8 dnl to get caught in this script by using an excessive number of #ifdefs...
9 dnl
10 AC_DEFUN(CURL_CHECK_NONBLOCKING_SOCKET,
11 [
12   AC_MSG_CHECKING([non-blocking sockets style])
13
14   AC_TRY_COMPILE([
15 /* headers for O_NONBLOCK test */
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <fcntl.h>
19 ],[
20 /* try to compile O_NONBLOCK */
21
22 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
23 # if defined(__SVR4) || defined(__srv4__)
24 #  define PLATFORM_SOLARIS
25 # else
26 #  define PLATFORM_SUNOS4
27 # endif
28 #endif
29 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
30 # define PLATFORM_AIX_V3
31 #endif
32
33 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3)
34 #error "O_NONBLOCK does not work on this platform"
35 #endif
36   int socket;
37   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
38 ],[
39 dnl the O_NONBLOCK test was fine
40 nonblock="O_NONBLOCK"
41 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
42 ],[
43 dnl the code was bad, try a different program now, test 2
44
45   AC_TRY_COMPILE([
46 /* headers for FIONBIO test */
47 #include <unistd.h>
48 #include <stropts.h>
49 ],[
50 /* FIONBIO source test */
51  int flags = ioctl(socket, FIONBIO, &flags);
52 ],[
53 dnl FIONBIO test was good
54 nonblock="FIONBIO"
55 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
56 ],[
57 dnl FIONBIO test was also bad
58 dnl the code was bad, try a different program now, test 3
59
60   AC_TRY_COMPILE([
61 /* headers for ioctlsocket test (cygwin?) */
62 #include <windows.h>
63 ],[
64 /* ioctlsocket source code */
65  int flags = ioctlsocket(socket, FIONBIO, &flags);
66 ],[
67 dnl ioctlsocket test was good
68 nonblock="ioctlsocket"
69 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
70 ],[
71 dnl ioctlsocket didnt compile!
72
73   AC_TRY_COMPILE([
74 /* headers for IoctlSocket test (Amiga?) */
75 #include <sys/ioctl.h>
76 ],[
77 /* IoctlSocket source code */
78  int flags = IoctlSocket(socket, FIONBIO, (long)1);
79 ],[
80 dnl ioctlsocket test was good
81 nonblock="IoctlSocket"
82 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
83 ],[
84 dnl ioctlsocket didnt compile!
85 nonblock="nada"
86 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
87 ])
88 dnl end of forth test
89
90 ])
91 dnl end of third test
92
93 ])
94 dnl end of second test
95
96 ])
97 dnl end of non-blocking try-compile test
98   AC_MSG_RESULT($nonblock)
99
100   if test "$nonblock" = "nada"; then
101     AC_MSG_WARN([non-block sockets disabled])
102   fi
103 ])
104
105 dnl Check for socklen_t: historically on BSD it is an int, and in
106 dnl POSIX 1g it is a type of its own, but some platforms use different
107 dnl types for the argument to getsockopt, getpeername, etc.  So we
108 dnl have to test to find something that will work.
109 AC_DEFUN([TYPE_SOCKLEN_T],
110 [
111    AC_CHECK_TYPE([socklen_t], ,[
112       AC_MSG_CHECKING([for socklen_t equivalent])
113       AC_CACHE_VAL([curl_cv_socklen_t_equiv],
114       [
115          # Systems have either "struct sockaddr *" or
116          # "void *" as the second argument to getpeername
117          curl_cv_socklen_t_equiv=
118          for arg2 in "struct sockaddr" void; do
119             for t in int size_t unsigned long "unsigned long"; do
120                AC_TRY_COMPILE([
121                   #include <sys/types.h>
122                   #include <sys/socket.h>
123
124                   int getpeername (int, $arg2 *, $t *);
125                ],[
126                   $t len;
127                   getpeername(0,0,&len);
128                ],[
129                   curl_cv_socklen_t_equiv="$t"
130                   break
131                ])
132             done
133          done
134
135          if test "x$curl_cv_socklen_t_equiv" = x; then
136             AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
137          fi
138       ])
139       AC_MSG_RESULT($curl_cv_socklen_t_equiv)
140       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
141                         [type to use in place of socklen_t if not defined])],
142       [#include <sys/types.h>
143 #include <sys/socket.h>])
144 ])
145
146 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
147 dnl and a few other things. If not found, we set it to unsigned int, as even
148 dnl 64-bit implementations use to set it to a 32-bit type.
149 AC_DEFUN([TYPE_IN_ADDR_T],
150 [
151    AC_CHECK_TYPE([in_addr_t], ,[
152       AC_MSG_CHECKING([for in_addr_t equivalent])
153       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
154       [
155          curl_cv_in_addr_t_equiv=
156          for t in "unsigned long" int size_t unsigned long; do
157             AC_TRY_COMPILE([
158                #include <sys/types.h>
159                #include <sys/socket.h>
160                #include <arpa/inet.h>
161             ],[
162                $t data = inet_addr ("1.2.3.4");
163             ],[
164                curl_cv_in_addr_t_equiv="$t"
165                break
166             ])
167          done
168
169          if test "x$curl_cv_in_addr_t_equiv" = x; then
170             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
171          fi
172       ])
173       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
174       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
175                         [type to use in place of in_addr_t if not defined])],
176       [#include <sys/types.h>
177 #include <sys/socket.h>
178 #include <arpa/inet.h>])
179 ])
180
181 dnl ************************************************************
182 dnl check for "localhost", if it doesn't exist, we can't do the
183 dnl gethostbyname_r tests!
184 dnl 
185
186 AC_DEFUN(CURL_CHECK_WORKING_RESOLVER,[
187 AC_MSG_CHECKING([if "localhost" resolves])
188 AC_TRY_RUN([
189 #include <string.h>
190 #include <sys/types.h>
191 #include <netdb.h>
192
193 int
194 main () {
195 struct hostent *h;
196 h = gethostbyname("localhost");
197 exit (h == NULL ? 1 : 0); }],[
198       AC_MSG_RESULT(yes)],[
199       AC_MSG_RESULT(no)
200       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
201
202       ]
203 )
204 ])
205
206 dnl ************************************************************
207 dnl check for working getaddrinfo()
208 dnl
209 AC_DEFUN(CURL_CHECK_WORKING_GETADDRINFO,[
210   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
211   AC_TRY_RUN( [
212 #include <netdb.h>
213 #include <sys/types.h>
214 #include <sys/socket.h>
215
216 void main(void) {
217     struct addrinfo hints, *ai;
218     int error;
219
220     memset(&hints, 0, sizeof(hints));
221     hints.ai_family = AF_UNSPEC;
222     hints.ai_socktype = SOCK_STREAM;
223     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
224     if (error) {
225         exit(1);
226     }
227     else {
228         exit(0);
229     }
230 }
231 ],[
232   ac_cv_working_getaddrinfo="yes"
233 ],[
234   ac_cv_working_getaddrinfo="no"
235 ],[
236   ac_cv_working_getaddrinfo="yes"
237 ])])
238 if test "$ac_cv_working_getaddrinfo" = "yes"; then
239   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
240   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
241
242   IPV6_ENABLED=1
243   AC_SUBST(IPV6_ENABLED)
244 fi
245 ])
246
247
248 AC_DEFUN(CURL_CHECK_LOCALTIME_R,
249 [
250   dnl check for a few thread-safe functions
251   AC_CHECK_FUNCS(localtime_r,[
252     AC_MSG_CHECKING(whether localtime_r is declared)
253     AC_EGREP_CPP(localtime_r,[
254 #include <time.h>],[
255       AC_MSG_RESULT(yes)],[
256       AC_MSG_RESULT(no)
257       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
258       AC_EGREP_CPP(localtime_r,[
259 #define _REENTRANT
260 #include <time.h>],[
261         AC_DEFINE(NEED_REENTRANT)
262         AC_MSG_RESULT(yes)],
263         AC_MSG_RESULT(no))])])
264 ])
265
266 AC_DEFUN(CURL_CHECK_INET_NTOA_R,
267 [
268   dnl determine if function definition for inet_ntoa_r exists.
269   AC_CHECK_FUNCS(inet_ntoa_r,[
270     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
271     AC_EGREP_CPP(inet_ntoa_r,[
272 #include <arpa/inet.h>],[
273       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
274       AC_MSG_RESULT(yes)],[
275       AC_MSG_RESULT(no)
276       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
277       AC_EGREP_CPP(inet_ntoa_r,[
278 #define _REENTRANT
279 #include <arpa/inet.h>],[
280         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
281         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
282         AC_MSG_RESULT(yes)],
283         AC_MSG_RESULT(no))])])
284 ])
285
286 AC_DEFUN(CURL_CHECK_GETHOSTBYADDR_R,
287 [
288   dnl check for number of arguments to gethostbyaddr_r. it might take
289   dnl either 5, 7, or 8 arguments.
290   AC_CHECK_FUNCS(gethostbyaddr_r,[
291     AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
292     AC_TRY_COMPILE([
293 #include <sys/types.h>
294 #include <netdb.h>],[
295 char * address;
296 int length;
297 int type;
298 struct hostent h;
299 struct hostent_data hdata;
300 int rc;
301 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
302       AC_MSG_RESULT(yes)
303       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
304       ac_cv_gethostbyaddr_args=5],[
305       AC_MSG_RESULT(no)
306       AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
307       AC_TRY_COMPILE([
308 #define _REENTRANT
309 #include <sys/types.h>
310 #include <netdb.h>],[
311 char * address;
312 int length;
313 int type;
314 struct hostent h;
315 struct hostent_data hdata;
316 int rc;
317 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
318         AC_MSG_RESULT(yes)
319         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
320         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
321         ac_cv_gethostbyaddr_args=5],[
322         AC_MSG_RESULT(no)
323         AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
324         AC_TRY_COMPILE([
325 #include <sys/types.h>
326 #include <netdb.h>],[
327 char * address;
328 int length;
329 int type;
330 struct hostent h;
331 char buffer[8192];
332 int h_errnop;
333 struct hostent * hp;
334
335 hp = gethostbyaddr_r(address, length, type, &h,
336                      buffer, 8192, &h_errnop);],[
337           AC_MSG_RESULT(yes)
338           AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
339           ac_cv_gethostbyaddr_args=7],[
340           AC_MSG_RESULT(no)
341           AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
342           AC_TRY_COMPILE([
343 #include <sys/types.h>
344 #include <netdb.h>],[
345 char * address;
346 int length;
347 int type;
348 struct hostent h;
349 char buffer[8192];
350 int h_errnop;
351 struct hostent * hp;
352 int rc;
353
354 rc = gethostbyaddr_r(address, length, type, &h,
355                      buffer, 8192, &hp, &h_errnop);],[
356             AC_MSG_RESULT(yes)
357             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
358             ac_cv_gethostbyaddr_args=8],[
359             AC_MSG_RESULT(no)
360             have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
361 ])
362
363 AC_DEFUN(CURL_CHECK_GETHOSTBYNAME_R,
364 [
365   dnl check for number of arguments to gethostbyname_r. it might take
366   dnl either 3, 5, or 6 arguments.
367   AC_CHECK_FUNCS(gethostbyname_r,[
368     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
369     AC_TRY_COMPILE([
370 #include <string.h>
371 #include <sys/types.h>
372 #include <netdb.h>
373 #undef NULL
374 #define NULL (void *)0
375
376 int
377 gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
378 struct hostent_data data;
379 gethostbyname_r(NULL, NULL, NULL);],[
380       AC_MSG_RESULT(yes)
381       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
382       ac_cv_gethostbyname_args=3],[
383       AC_MSG_RESULT(no)
384       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
385       AC_TRY_COMPILE([
386 #define _REENTRANT
387
388 #include <string.h>
389 #include <sys/types.h>
390 #include <netdb.h>
391 #undef NULL
392 #define NULL (void *)0
393
394 int
395 gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
396 struct hostent_data data;
397 gethostbyname_r(NULL, NULL, NULL);],[
398         AC_MSG_RESULT(yes)
399         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
400         AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
401         ac_cv_gethostbyname_args=3],[
402         AC_MSG_RESULT(no)
403         AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
404         AC_TRY_COMPILE([
405 #include <sys/types.h>
406 #include <netdb.h>
407 #undef NULL
408 #define NULL (void *)0
409
410 struct hostent *
411 gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
412 gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
413           AC_MSG_RESULT(yes)
414           AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
415           ac_cv_gethostbyname_args=5],[
416           AC_MSG_RESULT(no)
417           AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
418           AC_TRY_COMPILE([
419 #include <sys/types.h>
420 #include <netdb.h>
421 #undef NULL
422 #define NULL (void *)0
423
424 int
425 gethostbyname_r(const char *, struct hostent *, char *, size_t,
426 struct hostent **, int *);],[
427 gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
428             AC_MSG_RESULT(yes)
429             AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
430             ac_cv_gethostbyname_args=6],[
431             AC_MSG_RESULT(no)
432             have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
433             [ac_cv_gethostbyname_args=0])],
434           [ac_cv_gethostbyname_args=0])],
435         [ac_cv_gethostbyname_args=0])],
436       [ac_cv_gethostbyname_args=0])])
437
438 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
439   if test "$ac_cv_gethostbyname_args" = "0"; then
440     dnl there's a gethostbyname_r() function, but we don't know how
441     dnl many arguments it wants!
442     AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
443   fi
444 fi
445 ])