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