Avoid the risk of a false positive detection of MSG_NOSIGNAL when cross compiling...
[platform/upstream/curl.git] / acinclude.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
9 #
10 # This software is licensed as described in the file COPYING, which
11 # you should have received as part of this distribution. The terms
12 # are also available at http://curl.haxx.se/docs/copyright.html.
13 #
14 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 # copies of the Software, and permit persons to whom the Software is
16 # furnished to do so, under the terms of the COPYING file.
17 #
18 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 # KIND, either express or implied.
20 #
21 # $Id$
22 ###########################################################################
23
24
25 dnl CURL_CHECK_HEADER_WINDOWS
26 dnl -------------------------------------------------
27 dnl Check for compilable and valid windows.h header 
28
29 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
30   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_h], [
31     AC_COMPILE_IFELSE([
32       AC_LANG_PROGRAM([
33 #undef inline
34 #ifndef WIN32_LEAN_AND_MEAN
35 #define WIN32_LEAN_AND_MEAN
36 #endif
37 #include <windows.h>
38       ],[
39 #ifdef __CYGWIN__
40         HAVE_WINDOWS_H shall not be defined.
41 #else
42         int dummy=2*WINVER;
43 #endif
44       ])
45     ],[
46       ac_cv_header_windows_h="yes"
47     ],[
48       ac_cv_header_windows_h="no"
49     ])
50   ])
51   case "$ac_cv_header_windows_h" in
52     yes)
53       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
54         [Define to 1 if you have the windows.h header file.])
55       AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
56         [Define to avoid automatic inclusion of winsock.h])
57       ;;
58   esac
59 ])
60
61
62 dnl CURL_CHECK_HEADER_WINSOCK
63 dnl -------------------------------------------------
64 dnl Check for compilable and valid winsock.h header 
65
66 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
67   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
68   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
69     AC_COMPILE_IFELSE([
70       AC_LANG_PROGRAM([
71 #undef inline
72 #ifndef WIN32_LEAN_AND_MEAN
73 #define WIN32_LEAN_AND_MEAN
74 #endif
75 #include <windows.h>
76 #include <winsock.h>
77       ],[
78 #ifdef __CYGWIN__
79         HAVE_WINSOCK_H shall not be defined.
80 #else
81         int dummy=WSACleanup();
82 #endif
83       ])
84     ],[
85       ac_cv_header_winsock_h="yes"
86     ],[
87       ac_cv_header_winsock_h="no"
88     ])
89   ])
90   case "$ac_cv_header_winsock_h" in
91     yes)
92       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
93         [Define to 1 if you have the winsock.h header file.])
94       ;;
95   esac
96 ])
97
98
99 dnl CURL_CHECK_HEADER_WINSOCK2
100 dnl -------------------------------------------------
101 dnl Check for compilable and valid winsock2.h header 
102
103 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
104   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
105   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
106     AC_COMPILE_IFELSE([
107       AC_LANG_PROGRAM([
108 #undef inline
109 #ifndef WIN32_LEAN_AND_MEAN
110 #define WIN32_LEAN_AND_MEAN
111 #endif
112 #include <windows.h>
113 #include <winsock2.h>
114       ],[
115 #ifdef __CYGWIN__
116         HAVE_WINSOCK2_H shall not be defined.
117 #else
118         int dummy=2*IPPROTO_ESP;
119 #endif
120       ])
121     ],[
122       ac_cv_header_winsock2_h="yes"
123     ],[
124       ac_cv_header_winsock2_h="no"
125     ])
126   ])
127   case "$ac_cv_header_winsock2_h" in
128     yes)
129       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
130         [Define to 1 if you have the winsock2.h header file.])
131       ;;
132   esac
133 ])
134
135
136 dnl CURL_CHECK_HEADER_WS2TCPIP
137 dnl -------------------------------------------------
138 dnl Check for compilable and valid ws2tcpip.h header
139
140 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
141   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
142   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
143     AC_COMPILE_IFELSE([
144       AC_LANG_PROGRAM([
145 #undef inline
146 #ifndef WIN32_LEAN_AND_MEAN
147 #define WIN32_LEAN_AND_MEAN
148 #endif
149 #include <windows.h>
150 #include <winsock2.h>
151 #include <ws2tcpip.h>
152       ],[
153 #ifdef __CYGWIN__
154         HAVE_WS2TCPIP_H shall not be defined.
155 #else
156         int dummy=2*IP_PKTINFO;
157 #endif
158       ])
159     ],[
160       ac_cv_header_ws2tcpip_h="yes"
161     ],[
162       ac_cv_header_ws2tcpip_h="no"
163     ])
164   ])
165   case "$ac_cv_header_ws2tcpip_h" in
166     yes)
167       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
168         [Define to 1 if you have the ws2tcpip.h header file.])
169       ;;
170   esac
171 ])
172
173
174 dnl CURL_CHECK_HEADER_MALLOC
175 dnl -------------------------------------------------
176 dnl Check for compilable and valid malloc.h header,
177 dnl and check if it is needed even with stdlib.h
178
179 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
180   AC_CACHE_CHECK([for malloc.h], [ac_cv_header_malloc_h], [
181     AC_COMPILE_IFELSE([
182       AC_LANG_PROGRAM([
183 #include <malloc.h>
184       ],[
185         void *p = malloc(10);
186         void *q = calloc(10,10);
187         free(p);
188         free(q);
189       ])
190     ],[
191       ac_cv_header_malloc_h="yes"
192     ],[
193       ac_cv_header_malloc_h="no"
194     ])
195   ])
196   if test "$ac_cv_header_malloc_h" = "yes"; then
197     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
198       [Define to 1 if you have the malloc.h header file.])
199     #
200     AC_COMPILE_IFELSE([
201       AC_LANG_PROGRAM([
202 #include <stdlib.h>
203       ],[
204         void *p = malloc(10);
205         void *q = calloc(10,10);
206         free(p);
207         free(q);
208       ])
209     ],[
210       curl_cv_need_header_malloc_h="no"
211     ],[
212       curl_cv_need_header_malloc_h="yes"
213     ])
214     #
215     case "$curl_cv_need_header_malloc_h" in
216       yes)
217         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
218           [Define to 1 if you need the malloc.h header file even with stdlib.h])
219         ;;
220     esac
221   fi
222 ])
223
224
225 dnl CURL_CHECK_TYPE_SOCKLEN_T
226 dnl -------------------------------------------------
227 dnl Check for existing socklen_t type, and provide
228 dnl an equivalent type if socklen_t not available
229
230 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
231   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
232   AC_CHECK_TYPE([socklen_t], ,[
233     AC_CACHE_CHECK([for socklen_t equivalent], 
234       [curl_cv_socklen_t_equiv], [
235       curl_cv_socklen_t_equiv="unknown"
236       for arg2 in "struct sockaddr" void; do
237         for t in int size_t unsigned long "unsigned long"; do
238           AC_COMPILE_IFELSE([
239             AC_LANG_PROGRAM([
240 #undef inline
241 #ifdef HAVE_WINDOWS_H
242 #ifndef WIN32_LEAN_AND_MEAN
243 #define WIN32_LEAN_AND_MEAN
244 #endif
245 #include <windows.h>
246 #ifdef HAVE_WINSOCK2_H
247 #include <winsock2.h>
248 #else
249 #ifdef HAVE_WINSOCK_H
250 #include <winsock.h>
251 #endif
252 #endif
253 #else
254 #ifdef HAVE_SYS_TYPES_H
255 #include <sys/types.h>
256 #endif
257 #ifdef HAVE_SYS_SOCKET_H
258 #include <sys/socket.h>
259 #endif
260 #endif
261               int getpeername (int, $arg2 *, $t *);
262             ],[
263               $t len=0;
264               getpeername(0,0,&len);
265             ])
266           ],[
267              curl_cv_socklen_t_equiv="$t"
268              break 2
269           ])
270         done
271       done
272     ])
273     case "$curl_cv_socklen_t_equiv" in
274       unknown)
275         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
276         ;;
277       *)
278         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
279           [type to use in place of socklen_t if not defined])
280         ;;
281     esac
282   ],[
283 #undef inline
284 #ifdef HAVE_WINDOWS_H
285 #ifndef WIN32_LEAN_AND_MEAN
286 #define WIN32_LEAN_AND_MEAN
287 #endif
288 #include <windows.h>
289 #ifdef HAVE_WINSOCK2_H
290 #include <winsock2.h>
291 #ifdef HAVE_WS2TCPIP_H
292 #include <ws2tcpip.h>
293 #endif
294 #endif
295 #else
296 #ifdef HAVE_SYS_TYPES_H
297 #include <sys/types.h>
298 #endif
299 #ifdef HAVE_SYS_SOCKET_H
300 #include <sys/socket.h>
301 #endif
302 #endif
303   ])
304 ])
305
306
307 dnl CURL_CHECK_FUNC_GETNAMEINFO
308 dnl -------------------------------------------------
309 dnl Test if the getnameinfo function is available, 
310 dnl and check the types of five of its arguments.
311 dnl If the function succeeds HAVE_GETNAMEINFO will be
312 dnl defined, defining the types of the arguments in
313 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
314 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
315 dnl and also defining the type qualifier of first 
316 dnl argument in GETNAMEINFO_QUAL_ARG1.
317
318 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
319   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
320   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
321   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
322   #
323   AC_MSG_CHECKING([for getnameinfo])
324   AC_LINK_IFELSE([
325       AC_LANG_FUNC_LINK_TRY([getnameinfo])
326     ],[
327       AC_MSG_RESULT([yes])
328       curl_cv_getnameinfo="yes"
329     ],[
330       AC_MSG_RESULT([no])
331       curl_cv_getnameinfo="no"
332   ])
333   #
334   if test "$curl_cv_getnameinfo" != "yes"; then
335     AC_MSG_CHECKING([deeper for getnameinfo])
336     AC_TRY_LINK([
337       ],[
338         getnameinfo();
339       ],[
340         AC_MSG_RESULT([yes])
341         curl_cv_getnameinfo="yes"
342       ],[
343         AC_MSG_RESULT([but still no])
344         curl_cv_getnameinfo="no"
345     ])
346   fi
347   #
348   if test "$curl_cv_getnameinfo" != "yes"; then
349     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
350     AC_TRY_LINK([
351 #undef inline
352 #ifdef HAVE_WINDOWS_H
353 #ifndef WIN32_LEAN_AND_MEAN
354 #define WIN32_LEAN_AND_MEAN
355 #endif
356 #include <windows.h>
357 #ifdef HAVE_WINSOCK2_H
358 #include <winsock2.h>
359 #ifdef HAVE_WS2TCPIP_H
360 #include <ws2tcpip.h>
361 #endif
362 #endif
363 #else
364 #ifdef HAVE_SYS_TYPES_H
365 #include <sys/types.h>
366 #endif
367 #ifdef HAVE_SYS_SOCKET_H
368 #include <sys/socket.h>
369 #endif
370 #ifdef HAVE_NETDB_H
371 #include <netdb.h>
372 #endif
373 #endif
374       ],[
375         getnameinfo(0, 0, 0, 0, 0, 0, 0);
376       ],[ 
377         AC_MSG_RESULT([yes])
378         curl_cv_getnameinfo="yes"
379       ],[
380         AC_MSG_RESULT([but still no])
381         curl_cv_getnameinfo="no"
382     ])
383   fi
384   #
385   if test "$curl_cv_getnameinfo" = "yes"; then
386     AC_CACHE_CHECK([types of arguments for getnameinfo],
387       [curl_cv_func_getnameinfo_args], [
388       curl_cv_func_getnameinfo_args="unknown"
389       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
390         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
391           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
392             for gni_arg7 in 'int' 'unsigned int'; do
393               AC_COMPILE_IFELSE([
394                 AC_LANG_PROGRAM([
395 #undef inline 
396 #ifdef HAVE_WINDOWS_H
397 #ifndef WIN32_LEAN_AND_MEAN
398 #define WIN32_LEAN_AND_MEAN
399 #endif
400 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
401 #undef _WIN32_WINNT
402 #define _WIN32_WINNT 0x0501
403 #endif
404 #include <windows.h>
405 #ifdef HAVE_WINSOCK2_H
406 #include <winsock2.h> 
407 #ifdef HAVE_WS2TCPIP_H
408 #include <ws2tcpip.h>
409 #endif
410 #endif
411 #define GNICALLCONV WSAAPI
412 #else
413 #ifdef HAVE_SYS_TYPES_H
414 #include <sys/types.h>
415 #endif
416 #ifdef HAVE_SYS_SOCKET_H
417 #include <sys/socket.h>
418 #endif
419 #ifdef HAVE_NETDB_H
420 #include <netdb.h>
421 #endif
422 #define GNICALLCONV
423 #endif
424                   extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
425                                          char *, $gni_arg46,
426                                          char *, $gni_arg46,
427                                          $gni_arg7);
428                 ],[
429                   $gni_arg2 salen=0;
430                   $gni_arg46 hostlen=0;
431                   $gni_arg46 servlen=0;
432                   $gni_arg7 flags=0;
433                   int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
434                 ])
435               ],[
436                  curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
437                  break 4
438               ])
439             done
440           done
441         done
442       done
443     ]) # AC_CACHE_CHECK
444     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
445       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
446       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
447     else
448       gni_prev_IFS=$IFS; IFS=','
449       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
450       IFS=$gni_prev_IFS
451       shift
452       #
453       gni_qual_type_arg1=$[1]
454       #
455       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
456         [Define to the type of arg 2 for getnameinfo.])
457       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
458         [Define to the type of args 4 and 6 for getnameinfo.])
459       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
460         [Define to the type of arg 7 for getnameinfo.])
461       #
462       prev_sh_opts=$-
463       #
464       case $prev_sh_opts in
465         *f*)
466           ;;
467         *)
468           set -f
469           ;;
470       esac
471       #
472       case "$gni_qual_type_arg1" in
473         const*)
474           gni_qual_arg1=const
475           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
476         ;;
477         *)
478           gni_qual_arg1=
479           gni_type_arg1=$gni_qual_type_arg1
480         ;;
481       esac
482       #
483       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
484         [Define to the type qualifier of arg 1 for getnameinfo.])
485       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
486         [Define to the type of arg 1 for getnameinfo.])
487       #
488       case $prev_sh_opts in
489         *f*)
490           ;;
491         *)
492           set +f
493           ;;
494       esac
495       #
496       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
497         [Define to 1 if you have the getnameinfo function.])
498       ac_cv_func_getnameinfo="yes"
499     fi
500   fi
501 ]) # AC_DEFUN
502
503
504 dnl TYPE_SOCKADDR_STORAGE
505 dnl -------------------------------------------------
506 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
507 dnl hosts have it, but AIX 4.3 is one known exception.
508
509 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
510 [
511    AC_CHECK_TYPE([struct sockaddr_storage],
512         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
513                   [if struct sockaddr_storage is defined]), ,
514    [
515 #undef inline
516 #ifdef HAVE_WINDOWS_H
517 #ifndef WIN32_LEAN_AND_MEAN
518 #define WIN32_LEAN_AND_MEAN
519 #endif
520 #include <windows.h>
521 #ifdef HAVE_WINSOCK2_H
522 #include <winsock2.h>
523 #endif
524 #else
525 #ifdef HAVE_SYS_TYPES_H
526 #include <sys/types.h>
527 #endif
528 #ifdef HAVE_SYS_SOCKET_H
529 #include <sys/socket.h>
530 #endif
531 #ifdef HAVE_NETINET_IN_H
532 #include <netinet/in.h>
533 #endif
534 #ifdef HAVE_ARPA_INET_H
535 #include <arpa/inet.h>
536 #endif
537 #endif
538    ])
539 ])
540
541
542 dnl CURL_CHECK_NI_WITHSCOPEID
543 dnl -------------------------------------------------
544 dnl Check for working NI_WITHSCOPEID in getnameinfo()
545
546 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
547   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
548   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
549   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
550                    netdb.h netinet/in.h arpa/inet.h)
551   #
552   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
553     [ac_cv_working_ni_withscopeid], [
554     AC_RUN_IFELSE([
555       AC_LANG_PROGRAM([
556 #ifdef HAVE_STDIO_H
557 #include <stdio.h>
558 #endif
559 #ifdef HAVE_SYS_TYPES_H
560 #include <sys/types.h>
561 #endif
562 #ifdef HAVE_SYS_SOCKET_H
563 #include <sys/socket.h>
564 #endif
565 #ifdef HAVE_NETDB_H
566 #include <netdb.h>
567 #endif
568 #ifdef HAVE_NETINET_IN_H
569 #include <netinet/in.h>
570 #endif
571 #ifdef HAVE_ARPA_INET_H
572 #include <arpa/inet.h>
573 #endif
574       ],[
575 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
576 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
577         struct sockaddr_storage sa;
578 #else
579         unsigned char sa[256];
580 #endif
581         char hostbuf[NI_MAXHOST];
582         int rc;
583         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
584         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
585         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
586         int fd = socket(AF_INET6, SOCK_STREAM, 0);
587         if(fd < 0) {
588           perror("socket()");
589           return 1; /* Error creating socket */
590         }
591         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
592         if(rc) {
593           perror("getsockname()");
594           return 2; /* Error retrieving socket name */
595         }
596         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
597         if(rc) {
598           printf("rc = %s\n", gai_strerror(rc));
599           return 3; /* Error translating socket address */
600         }
601         return 0; /* Ok, NI_WITHSCOPEID works */
602 #else
603         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
604 #endif
605       ]) # AC_LANG_PROGRAM
606     ],[
607       # Exit code == 0. Program worked.
608       ac_cv_working_ni_withscopeid="yes"
609     ],[
610       # Exit code != 0. Program failed.
611       ac_cv_working_ni_withscopeid="no"
612     ],[
613       # Program is not run when cross-compiling. So we assume
614       # NI_WITHSCOPEID will work if we are able to compile it.
615       AC_COMPILE_IFELSE([
616         AC_LANG_PROGRAM([
617 #include <sys/types.h>
618 #include <sys/socket.h>
619 #include <netdb.h>
620         ],[
621           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
622         ])
623       ],[
624         ac_cv_working_ni_withscopeid="yes"
625       ],[
626         ac_cv_working_ni_withscopeid="no"
627       ]) # AC_COMPILE_IFELSE
628     ]) # AC_RUN_IFELSE
629   ]) # AC_CACHE_CHECK
630   case "$ac_cv_working_ni_withscopeid" in
631     yes)
632       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
633         [Define to 1 if NI_WITHSCOPEID exists and works.])
634       ;;
635   esac
636 ]) # AC_DEFUN
637
638
639 dnl CURL_CHECK_FUNC_RECV
640 dnl -------------------------------------------------
641 dnl Test if the socket recv() function is available, 
642 dnl and check its return type and the types of its 
643 dnl arguments. If the function succeeds HAVE_RECV 
644 dnl will be defined, defining the types of the arguments 
645 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
646 dnl and RECV_TYPE_ARG4, defining the type of the function
647 dnl return value in RECV_TYPE_RETV.
648
649 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
650   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
651   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
652   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
653   #
654   AC_MSG_CHECKING([for recv])
655   AC_TRY_LINK([
656 #undef inline 
657 #ifdef HAVE_WINDOWS_H
658 #ifndef WIN32_LEAN_AND_MEAN
659 #define WIN32_LEAN_AND_MEAN
660 #endif
661 #include <windows.h>
662 #ifdef HAVE_WINSOCK2_H
663 #include <winsock2.h>
664 #else
665 #ifdef HAVE_WINSOCK_H
666 #include <winsock.h>
667 #endif
668 #endif
669 #else
670 #ifdef HAVE_SYS_TYPES_H
671 #include <sys/types.h>
672 #endif
673 #ifdef HAVE_SYS_SOCKET_H
674 #include <sys/socket.h>
675 #endif
676 #endif
677     ],[
678       recv(0, 0, 0, 0);
679     ],[ 
680       AC_MSG_RESULT([yes])
681       curl_cv_recv="yes"
682     ],[
683       AC_MSG_RESULT([no])
684       curl_cv_recv="no"
685   ])
686   #
687   if test "$curl_cv_recv" = "yes"; then
688     AC_CACHE_CHECK([types of arguments and return type for recv],
689       [curl_cv_func_recv_args], [
690       curl_cv_func_recv_args="unknown"
691       for recv_retv in 'int' 'ssize_t'; do
692         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
693           for recv_arg2 in 'char *' 'void *'; do
694             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
695               for recv_arg4 in 'int' 'unsigned int'; do
696                 AC_COMPILE_IFELSE([
697                   AC_LANG_PROGRAM([
698 #undef inline 
699 #ifdef HAVE_WINDOWS_H
700 #ifndef WIN32_LEAN_AND_MEAN
701 #define WIN32_LEAN_AND_MEAN
702 #endif
703 #include <windows.h>
704 #ifdef HAVE_WINSOCK2_H
705 #include <winsock2.h>
706 #else
707 #ifdef HAVE_WINSOCK_H
708 #include <winsock.h>
709 #endif
710 #endif
711 #define RECVCALLCONV PASCAL
712 #else
713 #ifdef HAVE_SYS_TYPES_H
714 #include <sys/types.h>
715 #endif
716 #ifdef HAVE_SYS_SOCKET_H
717 #include <sys/socket.h>
718 #endif
719 #define RECVCALLCONV
720 #endif
721                     extern $recv_retv RECVCALLCONV recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
722                   ],[
723                     $recv_arg1 s=0;
724                     $recv_arg2 buf=0;
725                     $recv_arg3 len=0;
726                     $recv_arg4 flags=0;
727                     $recv_retv res = recv(s, buf, len, flags);
728                   ])
729                 ],[
730                    curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
731                    break 5
732                 ])
733               done
734             done
735           done
736         done
737       done
738     ]) # AC_CACHE_CHECK
739     if test "$curl_cv_func_recv_args" = "unknown"; then
740       AC_MSG_WARN([Cannot find proper types to use for recv args])
741       AC_MSG_WARN([HAVE_RECV will not be defined])
742     else
743       recv_prev_IFS=$IFS; IFS=','
744       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
745       IFS=$recv_prev_IFS
746       shift
747       #
748       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
749         [Define to the type of arg 1 for recv.])
750       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
751         [Define to the type of arg 2 for recv.])
752       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
753         [Define to the type of arg 3 for recv.])
754       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
755         [Define to the type of arg 4 for recv.])
756       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
757         [Define to the function return type for recv.])
758       #
759       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
760         [Define to 1 if you have the recv function.])
761       ac_cv_func_recv="yes"
762     fi
763   fi
764 ]) # AC_DEFUN
765
766
767 dnl CURL_CHECK_FUNC_SEND
768 dnl -------------------------------------------------
769 dnl Test if the socket send() function is available, 
770 dnl and check its return type and the types of its 
771 dnl arguments. If the function succeeds HAVE_SEND 
772 dnl will be defined, defining the types of the arguments 
773 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
774 dnl and SEND_TYPE_ARG4, defining the type of the function
775 dnl return value in SEND_TYPE_RETV, and also defining the 
776 dnl type qualifier of second argument in SEND_QUAL_ARG2.
777
778 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
779   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
780   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
781   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
782   #
783   AC_MSG_CHECKING([for send])
784   AC_TRY_LINK([
785 #undef inline 
786 #ifdef HAVE_WINDOWS_H
787 #ifndef WIN32_LEAN_AND_MEAN
788 #define WIN32_LEAN_AND_MEAN
789 #endif
790 #include <windows.h>
791 #ifdef HAVE_WINSOCK2_H
792 #include <winsock2.h>
793 #else
794 #ifdef HAVE_WINSOCK_H
795 #include <winsock.h>
796 #endif
797 #endif
798 #else
799 #ifdef HAVE_SYS_TYPES_H
800 #include <sys/types.h>
801 #endif
802 #ifdef HAVE_SYS_SOCKET_H
803 #include <sys/socket.h>
804 #endif
805 #endif
806     ],[
807       send(0, 0, 0, 0);
808     ],[ 
809       AC_MSG_RESULT([yes])
810       curl_cv_send="yes"
811     ],[
812       AC_MSG_RESULT([no])
813       curl_cv_send="no"
814   ])
815   #
816   if test "$curl_cv_send" = "yes"; then
817     AC_CACHE_CHECK([types of arguments and return type for send],
818       [curl_cv_func_send_args], [
819       curl_cv_func_send_args="unknown"
820       for send_retv in 'int' 'ssize_t'; do
821         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
822           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
823             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
824               for send_arg4 in 'int' 'unsigned int'; do
825                 AC_COMPILE_IFELSE([
826                   AC_LANG_PROGRAM([
827 #undef inline 
828 #ifdef HAVE_WINDOWS_H
829 #ifndef WIN32_LEAN_AND_MEAN
830 #define WIN32_LEAN_AND_MEAN
831 #endif
832 #include <windows.h>
833 #ifdef HAVE_WINSOCK2_H
834 #include <winsock2.h>
835 #else
836 #ifdef HAVE_WINSOCK_H
837 #include <winsock.h>
838 #endif
839 #endif
840 #define SENDCALLCONV PASCAL
841 #else
842 #ifdef HAVE_SYS_TYPES_H
843 #include <sys/types.h>
844 #endif
845 #ifdef HAVE_SYS_SOCKET_H
846 #include <sys/socket.h>
847 #endif
848 #define SENDCALLCONV
849 #endif
850                     extern $send_retv SENDCALLCONV send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
851                   ],[
852                     $send_arg1 s=0;
853                     $send_arg3 len=0;
854                     $send_arg4 flags=0;
855                     $send_retv res = send(s, 0, len, flags);
856                   ])
857                 ],[
858                    curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
859                    break 5
860                 ])
861               done
862             done
863           done
864         done
865       done
866     ]) # AC_CACHE_CHECK
867     if test "$curl_cv_func_send_args" = "unknown"; then
868       AC_MSG_WARN([Cannot find proper types to use for send args])
869       AC_MSG_WARN([HAVE_SEND will not be defined])
870     else
871       send_prev_IFS=$IFS; IFS=','
872       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
873       IFS=$send_prev_IFS
874       shift
875       #
876       send_qual_type_arg2=$[2]
877       #
878       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
879         [Define to the type of arg 1 for send.])
880       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
881         [Define to the type of arg 3 for send.])
882       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
883         [Define to the type of arg 4 for send.])
884       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
885         [Define to the function return type for send.])
886       #
887       prev_sh_opts=$-
888       #
889       case $prev_sh_opts in
890         *f*)
891           ;;
892         *)
893           set -f
894           ;;
895       esac
896       #
897       case "$send_qual_type_arg2" in
898         const*)
899           send_qual_arg2=const
900           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
901         ;;
902         *)
903           send_qual_arg2=
904           send_type_arg2=$send_qual_type_arg2
905         ;;
906       esac
907       #
908       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
909         [Define to the type qualifier of arg 2 for send.])
910       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
911         [Define to the type of arg 2 for send.])
912       #
913       case $prev_sh_opts in
914         *f*)
915           ;;
916         *)
917           set +f
918           ;;
919       esac
920       #
921       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
922         [Define to 1 if you have the send function.])
923       ac_cv_func_send="yes"
924     fi
925   fi
926 ]) # AC_DEFUN
927
928
929 dnl CURL_CHECK_MSG_NOSIGNAL
930 dnl -------------------------------------------------
931 dnl Check for MSG_NOSIGNAL
932
933 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
934   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
935   AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [
936     AC_COMPILE_IFELSE([
937       AC_LANG_PROGRAM([
938 #undef inline 
939 #ifdef HAVE_WINDOWS_H
940 #ifndef WIN32_LEAN_AND_MEAN
941 #define WIN32_LEAN_AND_MEAN
942 #endif
943 #include <windows.h>
944 #ifdef HAVE_WINSOCK2_H
945 #include <winsock2.h>
946 #else
947 #ifdef HAVE_WINSOCK_H
948 #include <winsock.h>
949 #endif
950 #endif
951 #else
952 #ifdef HAVE_SYS_TYPES_H
953 #include <sys/types.h>
954 #endif
955 #ifdef HAVE_SYS_SOCKET_H
956 #include <sys/socket.h>
957 #endif
958 #endif
959       ],[
960         int flag=MSG_NOSIGNAL;
961       ])
962     ],[
963       ac_cv_msg_nosignal="yes"
964     ],[
965       ac_cv_msg_nosignal="no"
966     ])
967   ])
968   case "$ac_cv_msg_nosignal" in
969     yes)
970       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
971         [Define to 1 if you have the MSG_NOSIGNAL flag.])
972       ;;
973   esac
974 ]) # AC_DEFUN
975
976
977 dnl CURL_CHECK_NONBLOCKING_SOCKET
978 dnl -------------------------------------------------
979 dnl Check for how to set a socket to non-blocking state. There seems to exist
980 dnl four known different ways, with the one used almost everywhere being POSIX
981 dnl and XPG3, while the other different ways for different systems (old BSD,
982 dnl Windows and Amiga).
983 dnl
984 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
985 dnl O_NONBLOCK define is found but does not work. This condition is attempted
986 dnl to get caught in this script by using an excessive number of #ifdefs...
987 dnl
988 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],
989 [
990   AC_MSG_CHECKING([non-blocking sockets style])
991
992   AC_TRY_COMPILE([
993 /* headers for O_NONBLOCK test */
994 #include <sys/types.h>
995 #include <unistd.h>
996 #include <fcntl.h>
997 ],[
998 /* try to compile O_NONBLOCK */
999
1000 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
1001 # if defined(__SVR4) || defined(__srv4__)
1002 #  define PLATFORM_SOLARIS
1003 # else
1004 #  define PLATFORM_SUNOS4
1005 # endif
1006 #endif
1007 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)
1008 # define PLATFORM_AIX_V3
1009 #endif
1010
1011 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
1012 #error "O_NONBLOCK does not work on this platform"
1013 #endif
1014   int socket;
1015   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
1016 ],[
1017 dnl the O_NONBLOCK test was fine
1018 nonblock="O_NONBLOCK"
1019 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])
1020 ],[
1021 dnl the code was bad, try a different program now, test 2
1022
1023   AC_TRY_COMPILE([
1024 /* headers for FIONBIO test */
1025 #include <unistd.h>
1026 #include <stropts.h>
1027 ],[
1028 /* FIONBIO source test (old-style unix) */
1029  int socket;
1030  int flags = ioctl(socket, FIONBIO, &flags);
1031 ],[
1032 dnl FIONBIO test was good
1033 nonblock="FIONBIO"
1034 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])
1035 ],[
1036 dnl FIONBIO test was also bad
1037 dnl the code was bad, try a different program now, test 3
1038
1039   AC_TRY_COMPILE([
1040 /* headers for ioctlsocket test (Windows) */
1041 #undef inline
1042 #ifdef HAVE_WINDOWS_H
1043 #ifndef WIN32_LEAN_AND_MEAN
1044 #define WIN32_LEAN_AND_MEAN
1045 #endif
1046 #include <windows.h>
1047 #ifdef HAVE_WINSOCK2_H
1048 #include <winsock2.h>
1049 #else
1050 #ifdef HAVE_WINSOCK_H
1051 #include <winsock.h>
1052 #endif
1053 #endif
1054 #endif
1055 ],[
1056 /* ioctlsocket source code */
1057  SOCKET sd;
1058  unsigned long flags = 0;
1059  sd = socket(0, 0, 0);
1060  ioctlsocket(sd, FIONBIO, &flags);
1061 ],[
1062 dnl ioctlsocket test was good
1063 nonblock="ioctlsocket"
1064 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])
1065 ],[
1066 dnl ioctlsocket didnt compile!, go to test 4
1067
1068   AC_TRY_LINK([
1069 /* headers for IoctlSocket test (Amiga?) */
1070 #include <sys/ioctl.h>
1071 ],[
1072 /* IoctlSocket source code */
1073  int socket;
1074  int flags = IoctlSocket(socket, FIONBIO, (long)1);
1075 ],[
1076 dnl ioctlsocket test was good
1077 nonblock="IoctlSocket"
1078 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])
1079 ],[
1080 dnl Ioctlsocket didnt compile, do test 5!
1081   AC_TRY_COMPILE([
1082 /* headers for SO_NONBLOCK test (BeOS) */
1083 #include <socket.h>
1084 ],[
1085 /* SO_NONBLOCK source code */
1086  long b = 1;
1087  int socket;
1088  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
1089 ],[
1090 dnl the SO_NONBLOCK test was good
1091 nonblock="SO_NONBLOCK"
1092 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])
1093 ],[
1094 dnl test 5 didnt compile!
1095 nonblock="nada"
1096 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])
1097 ])
1098 dnl end of fifth test
1099
1100 ])
1101 dnl end of forth test
1102
1103 ])
1104 dnl end of third test
1105
1106 ])
1107 dnl end of second test
1108
1109 ])
1110 dnl end of non-blocking try-compile test
1111   AC_MSG_RESULT($nonblock)
1112
1113   if test "$nonblock" = "nada"; then
1114     AC_MSG_WARN([non-block sockets disabled])
1115   fi
1116 ])
1117
1118
1119 dnl TYPE_IN_ADDR_T
1120 dnl -------------------------------------------------
1121 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
1122 dnl and a few other things.
1123 AC_DEFUN([TYPE_IN_ADDR_T],
1124 [
1125    AC_CHECK_TYPE([in_addr_t], ,[
1126       AC_MSG_CHECKING([for in_addr_t equivalent])
1127       AC_CACHE_VAL([curl_cv_in_addr_t_equiv],
1128       [
1129          curl_cv_in_addr_t_equiv=
1130          for t in "unsigned long" int size_t unsigned long; do
1131             AC_TRY_COMPILE([
1132 #undef inline
1133 #ifdef HAVE_WINDOWS_H
1134 #ifndef WIN32_LEAN_AND_MEAN
1135 #define WIN32_LEAN_AND_MEAN
1136 #endif
1137 #include <windows.h>
1138 #ifdef HAVE_WINSOCK2_H
1139 #include <winsock2.h>
1140 #else
1141 #ifdef HAVE_WINSOCK_H
1142 #include <winsock.h>
1143 #endif
1144 #endif
1145 #else
1146 #ifdef HAVE_SYS_TYPES_H
1147 #include <sys/types.h>
1148 #endif
1149 #ifdef HAVE_SYS_SOCKET_H
1150 #include <sys/socket.h>
1151 #endif
1152 #ifdef HAVE_NETINET_IN_H
1153 #include <netinet/in.h>
1154 #endif
1155 #ifdef HAVE_ARPA_INET_H
1156 #include <arpa/inet.h>
1157 #endif
1158 #endif
1159             ],[
1160                $t data = inet_addr ("1.2.3.4");
1161             ],[
1162                curl_cv_in_addr_t_equiv="$t"
1163                break
1164             ])
1165          done
1166
1167          if test "x$curl_cv_in_addr_t_equiv" = x; then
1168             AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
1169          fi
1170       ])
1171       AC_MSG_RESULT($curl_cv_in_addr_t_equiv)
1172       AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
1173                         [type to use in place of in_addr_t if not defined])],
1174       [
1175 #undef inline
1176 #ifdef HAVE_WINDOWS_H
1177 #ifndef WIN32_LEAN_AND_MEAN
1178 #define WIN32_LEAN_AND_MEAN
1179 #endif
1180 #include <windows.h>
1181 #ifdef HAVE_WINSOCK2_H
1182 #include <winsock2.h>
1183 #else
1184 #ifdef HAVE_WINSOCK_H
1185 #include <winsock.h>
1186 #endif
1187 #endif
1188 #else
1189 #ifdef HAVE_SYS_TYPES_H
1190 #include <sys/types.h>
1191 #endif
1192 #ifdef HAVE_SYS_SOCKET_H
1193 #include <sys/socket.h>
1194 #endif
1195 #ifdef HAVE_NETINET_IN_H
1196 #include <netinet/in.h>
1197 #endif
1198 #ifdef HAVE_ARPA_INET_H
1199 #include <arpa/inet.h>
1200 #endif
1201 #endif
1202   ]) dnl AC_CHECK_TYPE
1203 ]) dnl AC_DEFUN
1204
1205 dnl ************************************************************
1206 dnl check for "localhost", if it doesn't exist, we can't do the
1207 dnl gethostbyname_r tests!
1208 dnl 
1209
1210 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
1211 AC_MSG_CHECKING([if "localhost" resolves])
1212 AC_TRY_RUN([
1213 #include <string.h>
1214 #include <sys/types.h>
1215 #include <netdb.h>
1216
1217 int
1218 main () {
1219 struct hostent *h;
1220 h = gethostbyname("localhost");
1221 exit (h == NULL ? 1 : 0); }],[
1222       AC_MSG_RESULT(yes)],[
1223       AC_MSG_RESULT(no)
1224       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
1225
1226       ]
1227 )
1228 ])
1229
1230 dnl ************************************************************
1231 dnl check for working getaddrinfo() that works with AI_NUMERICHOST
1232 dnl
1233 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
1234   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
1235   AC_TRY_RUN( [
1236 #include <netdb.h>
1237 #include <sys/types.h>
1238 #include <sys/socket.h>
1239
1240 int main(void)
1241 {
1242     struct addrinfo hints, *ai;
1243     int error;
1244
1245     memset(&hints, 0, sizeof(hints));
1246     hints.ai_flags = AI_NUMERICHOST;
1247     hints.ai_family = AF_UNSPEC;
1248     hints.ai_socktype = SOCK_STREAM;
1249     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
1250     if (error) {
1251         return 1;
1252     }
1253     return 0;
1254 }
1255 ],[
1256   ac_cv_working_getaddrinfo="yes"
1257 ],[
1258   ac_cv_working_getaddrinfo="no"
1259 ],[
1260   ac_cv_working_getaddrinfo="yes"
1261 ])])
1262 if test "$ac_cv_working_getaddrinfo" = "yes"; then
1263   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
1264   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
1265
1266   IPV6_ENABLED=1
1267   AC_SUBST(IPV6_ENABLED)
1268 fi
1269 ])
1270
1271
1272 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
1273 [
1274   dnl check for localtime_r
1275   AC_CHECK_FUNCS(localtime_r,[
1276     AC_MSG_CHECKING(whether localtime_r is declared)
1277     AC_EGREP_CPP(localtime_r,[
1278 #include <time.h>],[
1279       AC_MSG_RESULT(yes)],[
1280       AC_MSG_RESULT(no)
1281       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
1282       AC_EGREP_CPP(localtime_r,[
1283 #define _REENTRANT
1284 #include <time.h>],[
1285         AC_DEFINE(NEED_REENTRANT)
1286         AC_MSG_RESULT(yes)],
1287         AC_MSG_RESULT(no))])])
1288 ])
1289
1290 dnl
1291 dnl This function checks for strerror_r(). If it isn't found at first, it
1292 dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
1293 dnl in order to find this function.
1294 dnl
1295 dnl If the function is found, it will then proceed to check how the function
1296 dnl actually works: glibc-style or POSIX-style.
1297 dnl
1298 dnl glibc:
1299 dnl      char *strerror_r(int errnum, char *buf, size_t n);
1300 dnl  
1301 dnl  What this one does is to return the error string (no surprises there),
1302 dnl  but it doesn't usually copy anything into buf!  The 'buf' and 'n'
1303 dnl  parameters are only meant as an optional working area, in case strerror_r
1304 dnl  needs it.  A quick test on a few systems shows that it's generally not
1305 dnl  touched at all.
1306 dnl
1307 dnl POSIX:
1308 dnl      int strerror_r(int errnum, char *buf, size_t n);
1309 dnl
1310 AC_DEFUN([CURL_CHECK_STRERROR_R],
1311 [
1312   AC_CHECK_FUNCS(strerror_r)
1313
1314   if test "x$ac_cv_func_strerror_r" = "xyes"; then
1315
1316     AC_MSG_CHECKING(whether strerror_r is declared)
1317     AC_EGREP_CPP(strerror_r,[
1318 #include <string.h>],[
1319       AC_MSG_RESULT(yes)],[
1320       AC_MSG_RESULT(no)
1321       AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
1322       AC_EGREP_CPP(strerror_r,[
1323 #define _REENTRANT
1324 #include <string.h>],[
1325         CPPFLAGS="-D_REENTRANT $CPPFLAGS"
1326         AC_MSG_RESULT(yes)],
1327         AC_MSG_RESULT(no)
1328         AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
1329        ) dnl with _THREAD_SAFE
1330     ]) dnl plain cpp for it
1331
1332     dnl determine if this strerror_r() is glibc or POSIX
1333     AC_MSG_CHECKING([for a glibc strerror_r API])
1334     AC_TRY_RUN([
1335 #include <string.h>
1336 #include <errno.h>
1337 int
1338 main () {
1339   char buffer[1024]; /* big enough to play with */
1340   char *string =
1341     strerror_r(EACCES, buffer, sizeof(buffer));
1342     /* this should've returned a string */
1343     if(!string || !string[0])
1344       return 99;
1345     return 0;
1346 }
1347 ],
1348     GLIBC_STRERROR_R="1"
1349     AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
1350     AC_MSG_RESULT([yes]),
1351     AC_MSG_RESULT([no]),
1352
1353     dnl Use an inferior method of strerror_r detection while cross-compiling
1354     AC_EGREP_CPP(yes, [
1355 #include <features.h>
1356 #ifdef __GLIBC__
1357 yes
1358 #endif
1359 ], 
1360       dnl looks like glibc, so assume a glibc-style strerror_r()
1361       GLIBC_STRERROR_R="1"
1362       AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
1363       AC_MSG_RESULT([yes]),
1364       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
1365     ) dnl while cross-compiling
1366     )
1367
1368     if test -z "$GLIBC_STRERROR_R"; then
1369
1370       AC_MSG_CHECKING([for a POSIX strerror_r API])
1371       AC_TRY_RUN([
1372 #include <string.h>
1373 #include <errno.h>
1374 int
1375 main () {
1376   char buffer[1024]; /* big enough to play with */
1377   int error =
1378     strerror_r(EACCES, buffer, sizeof(buffer));
1379     /* This should've returned zero, and written an error string in the
1380        buffer.*/
1381     if(!buffer[0] || error)
1382       return 99;
1383     return 0;
1384 }
1385 ],
1386       AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
1387       AC_MSG_RESULT([yes]),
1388       AC_MSG_RESULT([no]) ,
1389       dnl cross-compiling!
1390       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
1391     )
1392
1393     fi dnl if not using glibc API
1394
1395   fi dnl we have a strerror_r
1396
1397 ])
1398
1399 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
1400 [
1401   dnl determine if function definition for inet_ntoa_r exists.
1402   AC_CHECK_FUNCS(inet_ntoa_r,[
1403     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
1404     AC_EGREP_CPP(inet_ntoa_r,[
1405 #include <arpa/inet.h>],[
1406       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
1407       AC_MSG_RESULT(yes)],[
1408       AC_MSG_RESULT(no)
1409       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
1410       AC_EGREP_CPP(inet_ntoa_r,[
1411 #define _REENTRANT
1412 #include <arpa/inet.h>],[
1413         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
1414         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
1415         AC_MSG_RESULT(yes)],
1416         AC_MSG_RESULT(no))])])
1417 ])
1418
1419 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R],
1420 [
1421   dnl check for number of arguments to gethostbyaddr_r. it might take
1422   dnl either 5, 7, or 8 arguments.
1423   AC_CHECK_FUNCS(gethostbyaddr_r,[
1424     AC_MSG_CHECKING(if gethostbyaddr_r takes 5 arguments)
1425     AC_TRY_COMPILE([
1426 #include <sys/types.h>
1427 #include <netdb.h>],[
1428 char * address;
1429 int length;
1430 int type;
1431 struct hostent h;
1432 struct hostent_data hdata;
1433 int rc;
1434 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
1435       AC_MSG_RESULT(yes)
1436       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
1437       ac_cv_gethostbyaddr_args=5],[
1438       AC_MSG_RESULT(no)
1439       AC_MSG_CHECKING(if gethostbyaddr_r with -D_REENTRANT takes 5 arguments)
1440       AC_TRY_COMPILE([
1441 #define _REENTRANT
1442 #include <sys/types.h>
1443 #include <netdb.h>],[
1444 char * address;
1445 int length;
1446 int type;
1447 struct hostent h;
1448 struct hostent_data hdata;
1449 int rc;
1450 rc = gethostbyaddr_r(address, length, type, &h, &hdata);],[
1451         AC_MSG_RESULT(yes)
1452         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
1453         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
1454         ac_cv_gethostbyaddr_args=5],[
1455         AC_MSG_RESULT(no)
1456         AC_MSG_CHECKING(if gethostbyaddr_r takes 7 arguments)
1457         AC_TRY_COMPILE([
1458 #include <sys/types.h>
1459 #include <netdb.h>],[
1460 char * address;
1461 int length;
1462 int type;
1463 struct hostent h;
1464 char buffer[8192];
1465 int h_errnop;
1466 struct hostent * hp;
1467
1468 hp = gethostbyaddr_r(address, length, type, &h,
1469                      buffer, 8192, &h_errnop);],[
1470           AC_MSG_RESULT(yes)
1471           AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args] )
1472           ac_cv_gethostbyaddr_args=7],[
1473           AC_MSG_RESULT(no)
1474           AC_MSG_CHECKING(if gethostbyaddr_r takes 8 arguments)
1475           AC_TRY_COMPILE([
1476 #include <sys/types.h>
1477 #include <netdb.h>],[
1478 char * address;
1479 int length;
1480 int type;
1481 struct hostent h;
1482 char buffer[8192];
1483 int h_errnop;
1484 struct hostent * hp;
1485 int rc;
1486
1487 rc = gethostbyaddr_r(address, length, type, &h,
1488                      buffer, 8192, &hp, &h_errnop);],[
1489             AC_MSG_RESULT(yes)
1490             AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
1491             ac_cv_gethostbyaddr_args=8],[
1492             AC_MSG_RESULT(no)
1493             have_missing_r_funcs="$have_missing_r_funcs gethostbyaddr_r"])])])])])
1494 ])
1495
1496 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R],
1497 [
1498   dnl check for number of arguments to gethostbyname_r. it might take
1499   dnl either 3, 5, or 6 arguments.
1500   AC_CHECK_FUNCS(gethostbyname_r,[
1501     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
1502     AC_TRY_COMPILE([
1503 #include <string.h>
1504 #include <sys/types.h>
1505 #include <netdb.h>
1506 #undef NULL
1507 #define NULL (void *)0
1508
1509 int
1510 gethostbyname_r(const char *, struct hostent *, struct hostent_data *);],[
1511 struct hostent_data data;
1512 gethostbyname_r(NULL, NULL, NULL);],[
1513       AC_MSG_RESULT(yes)
1514       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
1515       ac_cv_gethostbyname_args=3],[
1516       AC_MSG_RESULT(no)
1517       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
1518       AC_TRY_COMPILE([
1519 #define _REENTRANT
1520
1521 #include <string.h>
1522 #include <sys/types.h>
1523 #include <netdb.h>
1524 #undef NULL
1525 #define NULL (void *)0
1526
1527 int
1528 gethostbyname_r(const char *,struct hostent *, struct hostent_data *);],[
1529 struct hostent_data data;
1530 gethostbyname_r(NULL, NULL, NULL);],[
1531         AC_MSG_RESULT(yes)
1532         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
1533         AC_DEFINE(NEED_REENTRANT, 1, [needs REENTRANT])
1534         ac_cv_gethostbyname_args=3],[
1535         AC_MSG_RESULT(no)
1536         AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
1537         AC_TRY_COMPILE([
1538 #include <sys/types.h>
1539 #include <netdb.h>
1540 #undef NULL
1541 #define NULL (void *)0
1542
1543 struct hostent *
1544 gethostbyname_r(const char *, struct hostent *, char *, int, int *);],[
1545 gethostbyname_r(NULL, NULL, NULL, 0, NULL);],[
1546           AC_MSG_RESULT(yes)
1547           AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
1548           ac_cv_gethostbyname_args=5],[
1549           AC_MSG_RESULT(no)
1550           AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
1551           AC_TRY_COMPILE([
1552 #include <sys/types.h>
1553 #include <netdb.h>
1554 #undef NULL
1555 #define NULL (void *)0
1556
1557 int
1558 gethostbyname_r(const char *, struct hostent *, char *, size_t,
1559 struct hostent **, int *);],[
1560 gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);],[
1561             AC_MSG_RESULT(yes)
1562             AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
1563             ac_cv_gethostbyname_args=6],[
1564             AC_MSG_RESULT(no)
1565             have_missing_r_funcs="$have_missing_r_funcs gethostbyname_r"],
1566             [ac_cv_gethostbyname_args=0])],
1567           [ac_cv_gethostbyname_args=0])],
1568         [ac_cv_gethostbyname_args=0])],
1569       [ac_cv_gethostbyname_args=0])])
1570
1571 if test "$ac_cv_func_gethostbyname_r" = "yes"; then
1572   if test "$ac_cv_gethostbyname_args" = "0"; then
1573     dnl there's a gethostbyname_r() function, but we don't know how
1574     dnl many arguments it wants!
1575     AC_MSG_ERROR([couldn't figure out how to use gethostbyname_r()])
1576   fi
1577 fi
1578 ])
1579
1580
1581 dnl **********************************************************************
1582 dnl CURL_DETECT_ICC ([ACTION-IF-YES])
1583 dnl
1584 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
1585 dnl sets the $ICC variable to "yes" or "no"
1586 dnl **********************************************************************
1587 AC_DEFUN([CURL_DETECT_ICC],
1588 [
1589     ICC="no"
1590     AC_MSG_CHECKING([for icc in use])
1591     if test "$GCC" = "yes"; then
1592        dnl check if this is icc acting as gcc in disguise
1593        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
1594          dnl action if the text is found, this it has not been replaced by the
1595          dnl cpp
1596          ICC="no",
1597          dnl the text was not found, it was replaced by the cpp
1598          ICC="yes"
1599          AC_MSG_RESULT([yes])
1600          [$1]
1601        )
1602     fi
1603     if test "$ICC" = "no"; then
1604         # this is not ICC
1605         AC_MSG_RESULT([no])
1606     fi
1607 ])
1608
1609 dnl We create a function for detecting which compiler we use and then set as
1610 dnl pendantic compiler options as possible for that particular compiler. The
1611 dnl options are only used for debug-builds.
1612
1613 AC_DEFUN([CURL_CC_DEBUG_OPTS],
1614 [
1615     if test "z$ICC" = "z"; then
1616       CURL_DETECT_ICC
1617     fi
1618
1619     if test "$GCC" = "yes"; then
1620
1621        dnl figure out gcc version!
1622        AC_MSG_CHECKING([gcc version])
1623        gccver=`$CC -dumpversion`
1624        num1=`echo $gccver | cut -d . -f1`
1625        num2=`echo $gccver | cut -d . -f2`
1626        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
1627        AC_MSG_RESULT($gccver)
1628
1629        if test "$ICC" = "yes"; then
1630          dnl this is icc, not gcc.
1631
1632          dnl ICC warnings we ignore:
1633          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
1634          dnl   "invalid format string conversion"
1635          dnl * 279 warns on static conditions in while expressions
1636          dnl * 981 warns on "operands are evaluated in unspecified order"
1637          dnl * 1418 "external definition with no prior declaration"
1638          dnl * 1419 warns on "external declaration in primary source file"
1639          dnl   which we know and do on purpose.
1640
1641          WARN="-wd279,269,981,1418,1419"
1642
1643          if test "$gccnum" -gt "600"; then
1644             dnl icc 6.0 and older doesn't have the -Wall flag
1645             WARN="-Wall $WARN"
1646          fi
1647        else dnl $ICC = yes
1648          dnl this is a set of options we believe *ALL* gcc versions support:
1649          WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
1650
1651          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
1652
1653          if test "$gccnum" -ge "207"; then
1654            dnl gcc 2.7 or later
1655            WARN="$WARN -Wmissing-declarations"
1656          fi
1657
1658          if test "$gccnum" -gt "295"; then
1659            dnl only if the compiler is newer than 2.95 since we got lots of
1660            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
1661            dnl gcc 2.95.4 on FreeBSD 4.9!
1662            WARN="$WARN -Wundef -Wno-long-long -Wsign-compare"
1663          fi
1664
1665          if test "$gccnum" -ge "296"; then
1666            dnl gcc 2.96 or later
1667            WARN="$WARN -Wfloat-equal"
1668          fi
1669
1670          if test "$gccnum" -gt "296"; then
1671            dnl this option does not exist in 2.96
1672            WARN="$WARN -Wno-format-nonliteral"
1673          fi
1674
1675          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
1676          dnl on i686-Linux as it gives us heaps with false positives.
1677          dnl Also, on gcc 4.0.X it is totally unbearable and complains all
1678          dnl over making it unusable for generic purposes. Let's not use it.
1679
1680          if test "$gccnum" -ge "303"; then
1681            dnl gcc 3.3 and later
1682            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
1683          fi
1684
1685          if test "$gccnum" -ge "304"; then
1686            # try these on gcc 3.4
1687            WARN="$WARN -Wdeclaration-after-statement"
1688          fi
1689
1690          for flag in $CPPFLAGS; do
1691            case "$flag" in
1692             -I*)
1693               dnl Include path, provide a -isystem option for the same dir
1694               dnl to prevent warnings in those dirs. The -isystem was not very
1695               dnl reliable on earlier gcc versions.
1696               add=`echo $flag | sed 's/^-I/-isystem /g'`
1697               WARN="$WARN $add"
1698               ;;
1699            esac
1700          done
1701
1702        fi dnl $ICC = no
1703
1704        CFLAGS="$CFLAGS $WARN"
1705
1706       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
1707
1708     else dnl $GCC = yes
1709
1710       AC_MSG_NOTICE([Added no extra compiler options])
1711
1712     fi dnl $GCC = yes
1713
1714     dnl strip off optimizer flags
1715     NEWFLAGS=""
1716     for flag in $CFLAGS; do
1717       case "$flag" in
1718       -O*)
1719         dnl echo "cut off $flag"
1720         ;;
1721       *)
1722         NEWFLAGS="$NEWFLAGS $flag"
1723         ;;
1724       esac
1725     done
1726     CFLAGS=$NEWFLAGS
1727
1728 ]) dnl end of AC_DEFUN()
1729
1730
1731 dnl Determine the name of the library to pass to dlopen() based on the name
1732 dnl that would normally be given to AC_CHECK_LIB.  The preprocessor symbol
1733 dnl given is set to the quoted library file name. 
1734 dnl The standard dynamic library file name is first generated, based on the
1735 dnl current system type, then a search is performed for that file on the
1736 dnl standard dynamic library path.  If it is a symbolic link, the destination
1737 dnl of the link is used as the file name, after stripping off any minor
1738 dnl version numbers. If a library file can't be found, a guess is made.
1739 dnl This macro assumes AC_PROG_LIBTOOL has been called and requires perl
1740 dnl to be available in the PATH, or $PERL to be set to its location.
1741 dnl
1742 dnl CURL_DLLIB_NAME(VARIABLE, library_name)
1743 dnl e.g. CURL_DLLIB_NAME(LDAP_NAME, ldap) on a Linux system might result
1744 dnl in LDAP_NAME holding the string "libldap.so.2".
1745
1746 AC_DEFUN([CURL_DLLIB_NAME],
1747 [
1748 AC_MSG_CHECKING([name of dynamic library $2])
1749 dnl The shared library extension variable name changes from version to
1750 dnl version of libtool.  Try a few names then just set one statically.
1751 test -z "$shared_ext" && shared_ext="$shrext_cmds"
1752 test -z "$shared_ext" && shared_ext="$shrext"
1753 test -z "$shared_ext" && shared_ext=".so"
1754
1755 dnl Create the library link name of the correct form for this platform
1756 LIBNAME_LINK_SPEC=`echo "$library_names_spec" | $SED 's/^.* //'`
1757 DLGUESSLIB=`name=$2 eval echo "$libname_spec"`
1758 DLGUESSFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$LIBNAME_LINK_SPEC"`
1759
1760 dnl Synthesize a likely dynamic library name in case we can't find an actual one
1761 SO_NAME_SPEC="$soname_spec"
1762 dnl soname_spec undefined when identical to the 1st entry in library_names_spec
1763 test -z "$SO_NAME_SPEC" && SO_NAME_SPEC=`echo "$library_names_spec" | $SED 's/ .*$//'`
1764 DLGUESSSOFILE=`libname="$DLGUESSLIB" release="" major="" versuffix="" eval echo "$SO_NAME_SPEC"`
1765
1766 if test "$cross_compiling" = yes; then
1767   dnl Can't look at filesystem when cross-compiling
1768   AC_DEFINE_UNQUOTED($1, "$DLGUESSSOFILE", [$2 dynamic library file])
1769   AC_MSG_RESULT([$DLGUESSSOFILE (guess while cross-compiling)])
1770 else
1771
1772   DLFOUNDFILE=""
1773   if test "$sys_lib_dlsearch_path_spec" ; then
1774     dnl Search for the link library name and see what it points to.
1775     for direc in $sys_lib_dlsearch_path_spec ; do
1776       DLTRYFILE="$direc/$DLGUESSFILE"
1777       dnl Find where the symbolic link for this name points
1778       changequote(<<, >>)dnl
1779       <<
1780       DLFOUNDFILE=`${PERL:-perl} -e 'use File::Basename; (basename(readlink($ARGV[0])) =~ /^(.*[^\d]\.\d+)[\d\.]*$/ && print ${1}) || exit 1;' "$DLTRYFILE" 2>&5`
1781       >>
1782       changequote([, ])dnl
1783       if test "$?" -eq "0"; then
1784         dnl Found the file link
1785         break
1786       fi
1787     done
1788   fi
1789
1790   if test -z "$DLFOUNDFILE" ; then
1791     dnl Couldn't find a link library, so guess at a name.
1792     DLFOUNDFILE="$DLGUESSSOFILE"
1793   fi
1794
1795   AC_DEFINE_UNQUOTED($1, "$DLFOUNDFILE", [$2 dynamic library file])
1796   AC_MSG_RESULT($DLFOUNDFILE)
1797 fi
1798 ])
1799
1800 # This is only a temporary fix. This macro is here to replace the broken one
1801 # delivered by the automake project (including the 1.9.6 release). As soon as
1802 # they ship a working version we SHOULD remove this work-around.
1803
1804 AC_DEFUN([AM_MISSING_HAS_RUN],
1805 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
1806 test x"${MISSING+set}" = xset || MISSING="\${SHELL} \"$am_aux_dir/missing\""
1807 # Use eval to expand $SHELL
1808 if eval "$MISSING --run true"; then
1809   am_missing_run="$MISSING --run "
1810 else
1811   am_missing_run=
1812   AC_MSG_WARN([`missing' script is too old or missing])
1813 fi
1814 ])