Nico Baggus added more error codes to the VMS stuff.
[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)
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)
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)
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)
83 ],[
84 dnl ioctlsocket didnt compile!
85 nonblock="nada"
86 AC_DEFINE(HAVE_DISABLED_NONBLOCKING)
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          # Systems have either "struct sockaddr *" or
156          # "void *" as the second argument to getpeername
157          curl_cv_in_addr_t_equiv=
158          for t in int size_t unsigned long "unsigned long"; do
159             AC_TRY_COMPILE([
160                #include <sys/types.h>
161                #include <sys/socket.h>
162                #include <arpa/inet.h>
163             ],[
164                $t data = inet_addr ("1.2.3.4");
165             ],[
166                curl_cv_in_addr_t_equiv="$t"
167                break
168             ])
169          done
170
171          if test "x$curl_cv_in_addr_t_equiv" = x; then
172             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
173          fi
174       ])
175       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
176       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
177                         [type to use in place of in_addr_t if not defined])],
178       [#include <sys/types.h>
179 #include <sys/socket.h>
180 #include <arpa/inet.h>])
181 ])
182
183 dnl ************************************************************
184 dnl check for "localhost", if it doesn't exist, we can't do the
185 dnl gethostbyname_r tests!
186 dnl 
187
188 AC_DEFUN(CURL_CHECK_WORKING_RESOLVER,[
189 AC_MSG_CHECKING([if "localhost" resolves])
190 AC_TRY_RUN([
191 #include <string.h>
192 #include <sys/types.h>
193 #include <netdb.h>
194
195 int
196 main () {
197 struct hostent *h;
198 h = gethostbyname("localhost");
199 exit (h == NULL ? 1 : 0); }],[
200       AC_MSG_RESULT(yes)],[
201       AC_MSG_RESULT(no)
202       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
203
204       ]
205 )
206 ])
207
208 dnl ************************************************************
209 dnl check for working getaddrinfo()
210 dnl
211 AC_DEFUN(CURL_CHECK_WORKING_GETADDRINFO,[
212   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
213   AC_TRY_RUN( [
214 #include <netdb.h>
215 #include <sys/types.h>
216 #include <sys/socket.h>
217
218 void main(void) {
219     struct addrinfo hints, *ai;
220     int error;
221
222     memset(&hints, 0, sizeof(hints));
223     hints.ai_family = AF_UNSPEC;
224     hints.ai_socktype = SOCK_STREAM;
225     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
226     if (error) {
227         exit(1);
228     }
229     else {
230         exit(0);
231     }
232 }
233 ],[
234   ac_cv_working_getaddrinfo="yes"
235 ],[
236   ac_cv_working_getaddrinfo="no"
237 ],[
238   ac_cv_working_getaddrinfo="yes"
239 ])])
240 if test "$ac_cv_working_getaddrinfo" = "yes"; then
241   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
242   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
243
244   IPV6_ENABLED=1
245   AC_SUBST(IPV6_ENABLED)
246 fi
247 ])
248
249
250 AC_DEFUN(CURL_CHECK_LOCALTIME_R,
251 [
252   dnl check for a few thread-safe functions
253   AC_CHECK_FUNCS(localtime_r,[
254     AC_MSG_CHECKING(whether localtime_r is declared)
255     AC_EGREP_CPP(localtime_r,[
256 #include <time.h>],[
257       AC_MSG_RESULT(yes)],[
258       AC_MSG_RESULT(no)
259       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
260       AC_EGREP_CPP(localtime_r,[
261 #define _REENTRANT
262 #include <time.h>],[
263         AC_DEFINE(NEED_REENTRANT)
264         AC_MSG_RESULT(yes)],
265         AC_MSG_RESULT(no))])])
266 ])
267
268 AC_DEFUN(CURL_CHECK_INET_NTOA_R,
269 [
270   dnl determine if function definition for inet_ntoa_r exists.
271   AC_CHECK_FUNCS(inet_ntoa_r,[
272     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
273     AC_EGREP_CPP(inet_ntoa_r,[
274 #include <arpa/inet.h>],[
275       AC_DEFINE(HAVE_INET_NTOA_R_DECL)
276       AC_MSG_RESULT(yes)],[
277       AC_MSG_RESULT(no)
278       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
279       AC_EGREP_CPP(inet_ntoa_r,[
280 #define _REENTRANT
281 #include <arpa/inet.h>],[
282         AC_DEFINE(HAVE_INET_NTOA_R_DECL)
283         AC_DEFINE(NEED_REENTRANT)
284         AC_MSG_RESULT(yes)],
285         AC_MSG_RESULT(no))])])
286 ])
287
288 AC_DEFUN(CURL_CHECK_GETHOSTBYADDR_R,
289 [
290   dnl check for number of arguments to gethostbyaddr_r. it might take
291   dnl either 5, 7, or 8 arguments.
292   AC_CHECK_FUNCS(gethostbyaddr_r,[
293     AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
294     AC_TRY_COMPILE([
295 #include <sys/types.h>
296 #include <netdb.h>],[
297 char * address;
298 int length;
299 int type;
300 struct hostent h;
301 struct hostent_data hdata;
302 int rc;
303 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
304       AC_MSG_RESULT(yes)
305       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5)
306       ac_cv_gethostbyaddr_args=5],[
307       AC_MSG_RESULT(no)
308       AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
309       AC_TRY_COMPILE([
310 #define _REENTRANT
311 #include <sys/types.h>
312 #include <netdb.h>],[
313 char * address;
314 int length;
315 int type;
316 struct hostent h;
317 struct hostent_data hdata;
318 int rc;
319 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
320         AC_MSG_RESULT(yes)
321         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5)
322         AC_DEFINE(NEED_REENTRANT)
323         ac_cv_gethostbyaddr_args=5],[
324         AC_MSG_RESULT(no)
325         AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
326         AC_TRY_COMPILE([
327 #include <sys/types.h>
328 #include <netdb.h>],[
329 char * address;
330 int length;
331 int type;
332 struct hostent h;
333 char buffer[8192];
334 int h_errnop;
335 struct hostent * hp;
336
337 hp = gethostbyaddr_r(address, length, type, &h,
338                      buffer, 8192, &h_errnop);],[
339           AC_MSG_RESULT(yes)
340           AC_DEFINE(HAVE_GETHOSTBYADDR_R_7)
341           ac_cv_gethostbyaddr_args=7],[
342           AC_MSG_RESULT(no)
343           AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
344           AC_TRY_COMPILE([
345 #include <sys/types.h>
346 #include <netdb.h>],[
347 char * address;
348 int length;
349 int type;
350 struct hostent h;
351 char buffer[8192];
352 int h_errnop;
353 struct hostent * hp;
354 int rc;
355
356 rc = gethostbyaddr_r(address, length, type, &h,
357                      buffer, 8192, &hp, &h_errnop);],[
358             AC_MSG_RESULT(yes)
359             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8)
360             ac_cv_gethostbyaddr_args=8],[
361             AC_MSG_RESULT(no)
362             have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
363 ])
364
365 AC_DEFUN(CURL_CHECK_GETHOSTBYNAME_R,
366 [
367   dnl check for number of arguments to gethostbyname_r. it might take
368   dnl either 3, 5, or 6 arguments.
369   AC_CHECK_FUNCS(gethostbyname_r,[
370     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
371     AC_TRY_COMPILE([
372 #include <string.h>
373 #include <sys/types.h>
374 #include <netdb.h>
375 #undef NULL
376 #define NULL (void *)0
377
378 int
379 gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
380 struct hostent_data data;
381 gethostbyname_r(NULL, NULL, NULL);],[
382       AC_MSG_RESULT(yes)
383       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3)
384       ac_cv_gethostbyname_args=3],[
385       AC_MSG_RESULT(no)
386       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
387       AC_TRY_COMPILE([
388 #define _REENTRANT
389
390 #include <string.h>
391 #include <sys/types.h>
392 #include <netdb.h>
393 #undef NULL
394 #define NULL (void *)0
395
396 int
397 gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
398 struct hostent_data data;
399 gethostbyname_r(NULL, NULL, NULL);],[
400         AC_MSG_RESULT(yes)
401         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3)
402         AC_DEFINE(NEED_REENTRANT)
403         ac_cv_gethostbyname_args=3],[
404         AC_MSG_RESULT(no)
405         AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
406         AC_TRY_COMPILE([
407 #include <sys/types.h>
408 #include <netdb.h>
409 #undef NULL
410 #define NULL (void *)0
411
412 struct hostent *
413 gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
414 gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
415           AC_MSG_RESULT(yes)
416           AC_DEFINE(HAVE_GETHOSTBYNAME_R_5)
417           ac_cv_gethostbyname_args=5],[
418           AC_MSG_RESULT(no)
419           AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
420           AC_TRY_COMPILE([
421 #include <sys/types.h>
422 #include <netdb.h>
423 #undef NULL
424 #define NULL (void *)0
425
426 int
427 gethostbyname_r(const char *, struct hostent *, char *, size_t,
428 struct hostent **, int *);],[
429 gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
430             AC_MSG_RESULT(yes)
431             AC_DEFINE(HAVE_GETHOSTBYNAME_R_6)
432             ac_cv_gethostbyname_args=6],[
433             AC_MSG_RESULT(no)
434             have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
435             [ac_cv_gethostbyname_args=0])],
436           [ac_cv_gethostbyname_args=0])],
437         [ac_cv_gethostbyname_args=0])],
438       [ac_cv_gethostbyname_args=0])])
439
440 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
441   if test "$ac_cv_gethostbyname_args" = "0"; then
442     dnl there's a gethostbyname_r() function, but we don't know how
443     dnl many arguments it wants!
444     AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
445   fi
446 fi
447 ])