checks for gethostbyaddr_r with 7 and 8 args now also done with -D_REENTRANT
[platform/upstream/curl.git] / acinclude.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2008, 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_COMPILER_HALT_ON_ERROR
26 dnl -------------------------------------------------
27 dnl Verifies if the compiler actually halts after the
28 dnl compilation phase without generating any object
29 dnl code file, when the source compiles with errors.
30
31 AC_DEFUN([CURL_CHECK_COMPILER_HALT_ON_ERROR], [
32   AC_MSG_CHECKING([if compiler halts on compilation errors])
33   AC_COMPILE_IFELSE([
34     AC_LANG_PROGRAM([[
35     ]],[[
36       force compilation error
37     ]])
38   ],[
39     AC_MSG_RESULT([no])
40     AC_MSG_ERROR([compiler does not halt on compilation errors.])
41   ],[
42     AC_MSG_RESULT([yes])
43   ])
44 ])
45
46
47 dnl CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE
48 dnl -------------------------------------------------
49 dnl Verifies if the compiler actually halts after the
50 dnl compilation phase without generating any object
51 dnl code file, when the source code tries to define a
52 dnl type for a constant array with negative dimension.
53
54 AC_DEFUN([CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE], [
55   AC_REQUIRE([CURL_CHECK_COMPILER_HALT_ON_ERROR])dnl
56   AC_MSG_CHECKING([if compiler halts on negative sized arrays])
57   AC_COMPILE_IFELSE([
58     AC_LANG_PROGRAM([[
59       typedef char bad_t[sizeof(char) == sizeof(int) ? -1 : -1 ];
60     ]],[[
61       bad_t dummy;
62     ]])
63   ],[
64     AC_MSG_RESULT([no])
65     AC_MSG_ERROR([compiler does not halt on negative sized arrays.])
66   ],[
67     AC_MSG_RESULT([yes])
68   ])
69 ])
70
71
72 dnl CURL_CHECK_DEF(SYMBOL, [INCLUDES], [SILENT])
73 dnl -------------------------------------------------
74 dnl Use the C preprocessor to find out if the given object-style symbol
75 dnl is defined and get its expansion. This macro will not use default
76 dnl includes even if no INCLUDES argument is given. This macro will run
77 dnl silently when invoked with three arguments.
78
79 AC_DEFUN([CURL_CHECK_DEF], [
80   AS_VAR_PUSHDEF([ac_HaveDef], [curl_cv_have_def_$1])dnl
81   AS_VAR_PUSHDEF([ac_Def], [curl_cv_def_$1])dnl
82   ifelse($3,,[AC_MSG_CHECKING([for preprocessor definition of $1])])
83   tmp_exp=""
84   AC_PREPROC_IFELSE([
85     AC_LANG_SOURCE(
86 ifelse($2,,,[$2])[[
87 #ifdef $1
88 CURL_DEF_TOKEN $1
89 #endif
90     ]])
91   ],[
92     tmp_exp=`eval "$ac_cpp conftest.$ac_ext" 2>/dev/null | \
93       "$GREP" CURL_DEF_TOKEN 2>/dev/null | \
94       "$SED" 's/.*CURL_DEF_TOKEN[[ ]]//' 2>/dev/null | \
95       "$SED" 'q' 2>/dev/null`
96     if test "$tmp_exp" = "$1"; then
97       tmp_exp=""
98     fi
99   ])
100   if test -z "$tmp_exp"; then
101     AS_VAR_SET([ac_HaveDef], [no])
102     ifelse($3,,[AC_MSG_RESULT([no])])
103   else
104     AS_VAR_SET([ac_HaveDef], [yes])
105     AS_VAR_SET([ac_Def], [$tmp_exp])
106     ifelse($3,,[AC_MSG_RESULT([$tmp_exp])])
107   fi
108   AS_VAR_POPDEF([ac_Def])dnl
109   AS_VAR_POPDEF([ac_HaveDef])dnl
110 ])
111
112
113 dnl CURL_CHECK_HEADER_WINDOWS
114 dnl -------------------------------------------------
115 dnl Check for compilable and valid windows.h header 
116
117 AC_DEFUN([CURL_CHECK_HEADER_WINDOWS], [
118   AC_CACHE_CHECK([for windows.h], [ac_cv_header_windows_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       ]],[[
127 #if defined(__CYGWIN__) || defined(__CEGCC__)
128         HAVE_WINDOWS_H shall not be defined.
129 #else
130         int dummy=2*WINVER;
131 #endif
132       ]])
133     ],[
134       ac_cv_header_windows_h="yes"
135     ],[
136       ac_cv_header_windows_h="no"
137     ])
138   ])
139   case "$ac_cv_header_windows_h" in
140     yes)
141       AC_DEFINE_UNQUOTED(HAVE_WINDOWS_H, 1,
142         [Define to 1 if you have the windows.h header file.])
143       AC_DEFINE_UNQUOTED(WIN32_LEAN_AND_MEAN, 1,
144         [Define to avoid automatic inclusion of winsock.h])
145       ;;
146   esac
147 ])
148
149
150 dnl CURL_CHECK_NATIVE_WINDOWS
151 dnl -------------------------------------------------
152 dnl Check if building a native Windows target
153
154 AC_DEFUN([CURL_CHECK_NATIVE_WINDOWS], [
155   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
156   AC_CACHE_CHECK([whether build target is a native Windows one], [ac_cv_native_windows], [
157     if test "$ac_cv_header_windows_h" = "no"; then
158       ac_cv_native_windows="no"
159     else
160       AC_COMPILE_IFELSE([
161         AC_LANG_PROGRAM([[
162         ]],[[
163 #if defined(__MINGW32__) || defined(__MINGW32CE__) || \
164    (defined(_MSC_VER) && (defined(_WIN32) || defined(_WIN64)))
165           int dummy=1;
166 #else
167           Not a native Windows build target.
168 #endif
169         ]])
170       ],[
171         ac_cv_native_windows="yes"
172       ],[
173         ac_cv_native_windows="no"
174       ])
175     fi
176   ])
177   case "$ac_cv_native_windows" in
178     yes)
179       AC_DEFINE_UNQUOTED(NATIVE_WINDOWS, 1,
180         [Define to 1 if you are building a native Windows target.])
181       ;;
182   esac
183 ])
184
185
186 dnl CURL_CHECK_HEADER_WINSOCK
187 dnl -------------------------------------------------
188 dnl Check for compilable and valid winsock.h header 
189
190 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK], [
191   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
192   AC_CACHE_CHECK([for winsock.h], [ac_cv_header_winsock_h], [
193     AC_COMPILE_IFELSE([
194       AC_LANG_PROGRAM([[
195 #undef inline
196 #ifndef WIN32_LEAN_AND_MEAN
197 #define WIN32_LEAN_AND_MEAN
198 #endif
199 #include <windows.h>
200 #include <winsock.h>
201       ]],[[
202 #if defined(__CYGWIN__) || defined(__CEGCC__)
203         HAVE_WINSOCK_H shall not be defined.
204 #else
205         int dummy=WSACleanup();
206 #endif
207       ]])
208     ],[
209       ac_cv_header_winsock_h="yes"
210     ],[
211       ac_cv_header_winsock_h="no"
212     ])
213   ])
214   case "$ac_cv_header_winsock_h" in
215     yes)
216       AC_DEFINE_UNQUOTED(HAVE_WINSOCK_H, 1,
217         [Define to 1 if you have the winsock.h header file.])
218       ;;
219   esac
220 ])
221
222
223 dnl CURL_CHECK_HEADER_WINSOCK2
224 dnl -------------------------------------------------
225 dnl Check for compilable and valid winsock2.h header 
226
227 AC_DEFUN([CURL_CHECK_HEADER_WINSOCK2], [
228   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
229   AC_CACHE_CHECK([for winsock2.h], [ac_cv_header_winsock2_h], [
230     AC_COMPILE_IFELSE([
231       AC_LANG_PROGRAM([[
232 #undef inline
233 #ifndef WIN32_LEAN_AND_MEAN
234 #define WIN32_LEAN_AND_MEAN
235 #endif
236 #include <windows.h>
237 #include <winsock2.h>
238       ]],[[
239 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
240         HAVE_WINSOCK2_H shall not be defined.
241 #else
242         int dummy=2*IPPROTO_ESP;
243 #endif
244       ]])
245     ],[
246       ac_cv_header_winsock2_h="yes"
247     ],[
248       ac_cv_header_winsock2_h="no"
249     ])
250   ])
251   case "$ac_cv_header_winsock2_h" in
252     yes)
253       AC_DEFINE_UNQUOTED(HAVE_WINSOCK2_H, 1,
254         [Define to 1 if you have the winsock2.h header file.])
255       ;;
256   esac
257 ])
258
259
260 dnl CURL_CHECK_HEADER_WS2TCPIP
261 dnl -------------------------------------------------
262 dnl Check for compilable and valid ws2tcpip.h header
263
264 AC_DEFUN([CURL_CHECK_HEADER_WS2TCPIP], [
265   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
266   AC_CACHE_CHECK([for ws2tcpip.h], [ac_cv_header_ws2tcpip_h], [
267     AC_COMPILE_IFELSE([
268       AC_LANG_PROGRAM([[
269 #undef inline
270 #ifndef WIN32_LEAN_AND_MEAN
271 #define WIN32_LEAN_AND_MEAN
272 #endif
273 #include <windows.h>
274 #include <winsock2.h>
275 #include <ws2tcpip.h>
276       ]],[[
277 #if defined(__CYGWIN__) || defined(__CEGCC__) || defined(__MINGW32CE__)
278         HAVE_WS2TCPIP_H shall not be defined.
279 #else
280         int dummy=2*IP_PKTINFO;
281 #endif
282       ]])
283     ],[
284       ac_cv_header_ws2tcpip_h="yes"
285     ],[
286       ac_cv_header_ws2tcpip_h="no"
287     ])
288   ])
289   case "$ac_cv_header_ws2tcpip_h" in
290     yes)
291       AC_DEFINE_UNQUOTED(HAVE_WS2TCPIP_H, 1,
292         [Define to 1 if you have the ws2tcpip.h header file.])
293       ;;
294   esac
295 ])
296
297
298 dnl CURL_CHECK_HEADER_WINLDAP
299 dnl -------------------------------------------------
300 dnl Check for compilable and valid winldap.h header
301
302 AC_DEFUN([CURL_CHECK_HEADER_WINLDAP], [
303   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
304   AC_CACHE_CHECK([for winldap.h], [ac_cv_header_winldap_h], [
305     AC_COMPILE_IFELSE([
306       AC_LANG_PROGRAM([[
307 #undef inline
308 #ifdef HAVE_WINDOWS_H
309 #ifndef WIN32_LEAN_AND_MEAN
310 #define WIN32_LEAN_AND_MEAN
311 #endif
312 #include <windows.h>
313 #endif
314 #include <winldap.h>
315       ]],[[
316 #if defined(__CYGWIN__) || defined(__CEGCC__)
317         HAVE_WINLDAP_H shall not be defined.
318 #else
319         LDAP *ldp = ldap_init("dummy", LDAP_PORT);
320         ULONG res = ldap_unbind(ldp);
321 #endif
322       ]])
323     ],[
324       ac_cv_header_winldap_h="yes"
325     ],[
326       ac_cv_header_winldap_h="no"
327     ])
328   ])
329   case "$ac_cv_header_winldap_h" in
330     yes)
331       AC_DEFINE_UNQUOTED(HAVE_WINLDAP_H, 1,
332         [Define to 1 if you have the winldap.h header file.])
333       ;;
334   esac
335 ])
336
337
338 dnl CURL_CHECK_HEADER_WINBER
339 dnl -------------------------------------------------
340 dnl Check for compilable and valid winber.h header
341
342 AC_DEFUN([CURL_CHECK_HEADER_WINBER], [
343   AC_REQUIRE([CURL_CHECK_HEADER_WINLDAP])dnl
344   AC_CACHE_CHECK([for winber.h], [ac_cv_header_winber_h], [
345     AC_COMPILE_IFELSE([
346       AC_LANG_PROGRAM([[
347 #undef inline
348 #ifdef HAVE_WINDOWS_H
349 #ifndef WIN32_LEAN_AND_MEAN
350 #define WIN32_LEAN_AND_MEAN
351 #endif
352 #include <windows.h>
353 #endif
354 #include <winldap.h>
355 #include <winber.h>
356       ]],[[
357 #if defined(__CYGWIN__) || defined(__CEGCC__)
358         HAVE_WINBER_H shall not be defined.
359 #else
360         BERVAL *bvp = NULL;
361         BerElement *bep = ber_init(bvp);
362         ber_free(bep, 1);
363 #endif
364       ]])
365     ],[
366       ac_cv_header_winber_h="yes"
367     ],[
368       ac_cv_header_winber_h="no"
369     ])
370   ])
371   case "$ac_cv_header_winber_h" in
372     yes)
373       AC_DEFINE_UNQUOTED(HAVE_WINBER_H, 1,
374         [Define to 1 if you have the winber.h header file.])
375       ;;
376   esac
377 ])
378
379
380 dnl CURL_CHECK_HEADER_LBER
381 dnl -------------------------------------------------
382 dnl Check for compilable and valid lber.h header,
383 dnl and check if it is needed even with ldap.h
384
385 AC_DEFUN([CURL_CHECK_HEADER_LBER], [
386   AC_REQUIRE([CURL_CHECK_HEADER_WINDOWS])dnl
387   AC_CACHE_CHECK([for lber.h], [ac_cv_header_lber_h], [
388     AC_COMPILE_IFELSE([
389       AC_LANG_PROGRAM([[
390 #undef inline
391 #ifdef HAVE_WINDOWS_H
392 #ifndef WIN32_LEAN_AND_MEAN
393 #define WIN32_LEAN_AND_MEAN
394 #endif
395 #include <windows.h>
396 #else
397 #ifdef HAVE_SYS_TYPES_H
398 #include <sys/types.h>
399 #endif
400 #endif
401 #ifndef NULL
402 #define NULL (void *)0
403 #endif
404 #include <lber.h>
405       ]],[[
406         BerValue *bvp = NULL;
407         BerElement *bep = ber_init(bvp);
408         ber_free(bep, 1);
409       ]])
410     ],[
411       ac_cv_header_lber_h="yes"
412     ],[
413       ac_cv_header_lber_h="no"
414     ])
415   ])
416   if test "$ac_cv_header_lber_h" = "yes"; then
417     AC_DEFINE_UNQUOTED(HAVE_LBER_H, 1,
418       [Define to 1 if you have the lber.h header file.])
419     #
420     AC_COMPILE_IFELSE([
421       AC_LANG_PROGRAM([[
422 #undef inline
423 #ifdef HAVE_WINDOWS_H
424 #ifndef WIN32_LEAN_AND_MEAN
425 #define WIN32_LEAN_AND_MEAN
426 #endif
427 #include <windows.h>
428 #else
429 #ifdef HAVE_SYS_TYPES_H
430 #include <sys/types.h>
431 #endif
432 #endif
433 #ifndef NULL
434 #define NULL (void *)0
435 #endif
436 #ifndef LDAP_DEPRECATED
437 #define LDAP_DEPRECATED 1
438 #endif
439 #include <ldap.h>
440       ]],[[
441         BerValue *bvp = NULL;
442         BerElement *bep = ber_init(bvp);
443         ber_free(bep, 1);
444       ]])
445     ],[
446       curl_cv_need_header_lber_h="no"
447     ],[
448       curl_cv_need_header_lber_h="yes"
449     ])
450     #
451     case "$curl_cv_need_header_lber_h" in
452       yes)
453         AC_DEFINE_UNQUOTED(NEED_LBER_H, 1,
454           [Define to 1 if you need the lber.h header file even with ldap.h])
455         ;;
456     esac
457   fi
458 ])
459
460
461 dnl CURL_CHECK_HEADER_LDAP
462 dnl -------------------------------------------------
463 dnl Check for compilable and valid ldap.h header
464
465 AC_DEFUN([CURL_CHECK_HEADER_LDAP], [
466   AC_REQUIRE([CURL_CHECK_HEADER_LBER])dnl
467   AC_CACHE_CHECK([for ldap.h], [ac_cv_header_ldap_h], [
468     AC_COMPILE_IFELSE([
469       AC_LANG_PROGRAM([[
470 #undef inline
471 #ifdef HAVE_WINDOWS_H
472 #ifndef WIN32_LEAN_AND_MEAN
473 #define WIN32_LEAN_AND_MEAN
474 #endif
475 #include <windows.h>
476 #else
477 #ifdef HAVE_SYS_TYPES_H
478 #include <sys/types.h>
479 #endif
480 #endif
481 #ifndef LDAP_DEPRECATED
482 #define LDAP_DEPRECATED 1
483 #endif
484 #ifdef NEED_LBER_H
485 #include <lber.h>
486 #endif
487 #include <ldap.h>
488       ]],[[
489         LDAP *ldp = ldap_init("dummy", LDAP_PORT);
490         int res = ldap_unbind(ldp);
491       ]])
492     ],[
493       ac_cv_header_ldap_h="yes"
494     ],[
495       ac_cv_header_ldap_h="no"
496     ])
497   ])
498   case "$ac_cv_header_ldap_h" in
499     yes)
500       AC_DEFINE_UNQUOTED(HAVE_LDAP_H, 1,
501         [Define to 1 if you have the ldap.h header file.])
502       ;;
503   esac
504 ])
505
506
507 dnl CURL_CHECK_HEADER_LDAP_SSL
508 dnl -------------------------------------------------
509 dnl Check for compilable and valid ldap_ssl.h header
510
511 AC_DEFUN([CURL_CHECK_HEADER_LDAP_SSL], [
512   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
513   AC_CACHE_CHECK([for ldap_ssl.h], [ac_cv_header_ldap_ssl_h], [
514     AC_COMPILE_IFELSE([
515       AC_LANG_PROGRAM([[
516 #undef inline
517 #ifdef HAVE_WINDOWS_H
518 #ifndef WIN32_LEAN_AND_MEAN
519 #define WIN32_LEAN_AND_MEAN
520 #endif
521 #include <windows.h>
522 #else
523 #ifdef HAVE_SYS_TYPES_H
524 #include <sys/types.h>
525 #endif
526 #endif
527 #ifndef LDAP_DEPRECATED
528 #define LDAP_DEPRECATED 1
529 #endif
530 #ifdef NEED_LBER_H
531 #include <lber.h>
532 #endif
533 #ifdef HAVE_LDAP_H
534 #include <ldap.h>
535 #endif
536 #include <ldap_ssl.h>
537       ]],[[
538         LDAP *ldp = ldapssl_init("dummy", LDAPS_PORT, 1);
539       ]])
540     ],[
541       ac_cv_header_ldap_ssl_h="yes"
542     ],[
543       ac_cv_header_ldap_ssl_h="no"
544     ])
545   ])
546   case "$ac_cv_header_ldap_ssl_h" in
547     yes)
548       AC_DEFINE_UNQUOTED(HAVE_LDAP_SSL_H, 1,
549         [Define to 1 if you have the ldap_ssl.h header file.])
550       ;;
551   esac
552 ])
553
554
555 dnl CURL_CHECK_HEADER_LDAPSSL
556 dnl -------------------------------------------------
557 dnl Check for compilable and valid ldapssl.h header
558
559 AC_DEFUN([CURL_CHECK_HEADER_LDAPSSL], [
560   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
561   AC_CACHE_CHECK([for ldapssl.h], [ac_cv_header_ldapssl_h], [
562     AC_COMPILE_IFELSE([
563       AC_LANG_PROGRAM([[
564 #undef inline
565 #ifdef HAVE_WINDOWS_H
566 #ifndef WIN32_LEAN_AND_MEAN
567 #define WIN32_LEAN_AND_MEAN
568 #endif
569 #include <windows.h>
570 #else
571 #ifdef HAVE_SYS_TYPES_H
572 #include <sys/types.h>
573 #endif
574 #endif
575 #ifndef NULL
576 #define NULL (void *)0
577 #endif
578 #ifndef LDAP_DEPRECATED
579 #define LDAP_DEPRECATED 1
580 #endif
581 #ifdef NEED_LBER_H
582 #include <lber.h>
583 #endif
584 #ifdef HAVE_LDAP_H
585 #include <ldap.h>
586 #endif
587 #include <ldapssl.h>
588       ]],[[
589         char *cert_label = NULL;
590         LDAP *ldp = ldap_ssl_init("dummy", LDAPS_PORT, cert_label);
591       ]])
592     ],[
593       ac_cv_header_ldapssl_h="yes"
594     ],[
595       ac_cv_header_ldapssl_h="no"
596     ])
597   ])
598   case "$ac_cv_header_ldapssl_h" in
599     yes)
600       AC_DEFINE_UNQUOTED(HAVE_LDAPSSL_H, 1,
601         [Define to 1 if you have the ldapssl.h header file.])
602       ;;
603   esac
604 ])
605
606
607 dnl CURL_CHECK_LIBS_WINLDAP
608 dnl -------------------------------------------------
609 dnl Check for libraries needed for WINLDAP support,
610 dnl and prepended to LIBS any needed libraries.
611 dnl This macro can take an optional parameter with a
612 dnl white space separated list of libraries to check
613 dnl before the WINLDAP default ones.
614
615 AC_DEFUN([CURL_CHECK_LIBS_WINLDAP], [
616   AC_REQUIRE([CURL_CHECK_HEADER_WINBER])dnl
617   #
618   AC_MSG_CHECKING([for WINLDAP libraries])
619   #
620   u_libs=""
621   #
622   ifelse($1,,,[
623     for x_lib in $1; do
624       case "$x_lib" in
625         -l*)
626           l_lib="$x_lib"
627           ;;
628         *)
629           l_lib="-l$x_lib"
630           ;;
631       esac
632       if test -z "$u_libs"; then
633         u_libs="$l_lib"
634       else
635         u_libs="$u_libs $l_lib"
636       fi
637     done
638   ])
639   #
640   curl_cv_save_LIBS="$LIBS"
641   curl_cv_ldap_LIBS="unknown"
642   #
643   for x_nlibs in '' "$u_libs" \
644     '-lwldap32' ; do
645     if test "$curl_cv_ldap_LIBS" = "unknown"; then
646       if test -z "$x_nlibs"; then
647         LIBS="$curl_cv_save_LIBS"
648       else
649         LIBS="$x_nlibs $curl_cv_save_LIBS"
650       fi
651       AC_LINK_IFELSE([
652         AC_LANG_PROGRAM([[
653 #undef inline
654 #ifdef HAVE_WINDOWS_H
655 #ifndef WIN32_LEAN_AND_MEAN
656 #define WIN32_LEAN_AND_MEAN
657 #endif
658 #include <windows.h>
659 #ifdef HAVE_WINLDAP_H
660 #include <winldap.h>
661 #endif
662 #ifdef HAVE_WINBER_H
663 #include <winber.h>
664 #endif
665 #endif
666         ]],[[
667           BERVAL *bvp = NULL;
668           BerElement *bep = ber_init(bvp);
669           LDAP *ldp = ldap_init("dummy", LDAP_PORT);
670           ULONG res = ldap_unbind(ldp);
671           ber_free(bep, 1);
672         ]])
673       ],[
674         curl_cv_ldap_LIBS="$x_nlibs"
675       ])
676     fi
677   done
678   #
679   LIBS="$curl_cv_save_LIBS"
680   #
681   case X-"$curl_cv_ldap_LIBS" in
682     X-unknown)
683       AC_MSG_RESULT([cannot find WINLDAP libraries])
684       ;;
685     X-)
686       AC_MSG_RESULT([no additional lib required])
687       ;;
688     *)
689       if test -z "$curl_cv_save_LIBS"; then
690         LIBS="$curl_cv_ldap_LIBS"
691       else
692         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
693       fi
694       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
695       ;;
696   esac
697   #
698 ])
699
700
701 dnl CURL_CHECK_LIBS_LDAP
702 dnl -------------------------------------------------
703 dnl Check for libraries needed for LDAP support,
704 dnl and prepended to LIBS any needed libraries.
705 dnl This macro can take an optional parameter with a
706 dnl white space separated list of libraries to check
707 dnl before the default ones.
708
709 AC_DEFUN([CURL_CHECK_LIBS_LDAP], [
710   AC_REQUIRE([CURL_CHECK_HEADER_LDAP])dnl
711   #
712   AC_MSG_CHECKING([for LDAP libraries])
713   #
714   u_libs=""
715   #
716   ifelse($1,,,[
717     for x_lib in $1; do
718       case "$x_lib" in
719         -l*)
720           l_lib="$x_lib"
721           ;;
722         *)
723           l_lib="-l$x_lib"
724           ;;
725       esac
726       if test -z "$u_libs"; then
727         u_libs="$l_lib"
728       else
729         u_libs="$u_libs $l_lib"
730       fi
731     done
732   ])
733   #
734   curl_cv_save_LIBS="$LIBS"
735   curl_cv_ldap_LIBS="unknown"
736   #
737   for x_nlibs in '' "$u_libs" \
738     '-lldap' \
739     '-llber -lldap' \
740     '-lldap -llber' \
741     '-lldapssl -lldapx -lldapsdk' \
742     '-lldapsdk -lldapx -lldapssl' ; do
743     if test "$curl_cv_ldap_LIBS" = "unknown"; then
744       if test -z "$x_nlibs"; then
745         LIBS="$curl_cv_save_LIBS"
746       else
747         LIBS="$x_nlibs $curl_cv_save_LIBS"
748       fi
749       AC_LINK_IFELSE([
750         AC_LANG_PROGRAM([[
751 #undef inline
752 #ifdef HAVE_WINDOWS_H
753 #ifndef WIN32_LEAN_AND_MEAN
754 #define WIN32_LEAN_AND_MEAN
755 #endif
756 #include <windows.h>
757 #else
758 #ifdef HAVE_SYS_TYPES_H
759 #include <sys/types.h>
760 #endif
761 #endif
762 #ifndef NULL
763 #define NULL (void *)0
764 #endif
765 #ifndef LDAP_DEPRECATED
766 #define LDAP_DEPRECATED 1
767 #endif
768 #ifdef NEED_LBER_H
769 #include <lber.h>
770 #endif
771 #ifdef HAVE_LDAP_H
772 #include <ldap.h>
773 #endif
774         ]],[[
775           BerValue *bvp = NULL;
776           BerElement *bep = ber_init(bvp);
777           LDAP *ldp = ldap_init("dummy", LDAP_PORT);
778           int res = ldap_unbind(ldp);
779           ber_free(bep, 1);
780         ]])
781       ],[
782         curl_cv_ldap_LIBS="$x_nlibs"
783       ])
784     fi
785   done
786   #
787   LIBS="$curl_cv_save_LIBS"
788   #
789   case X-"$curl_cv_ldap_LIBS" in
790     X-unknown)
791       AC_MSG_RESULT([cannot find LDAP libraries])
792       ;;
793     X-)
794       AC_MSG_RESULT([no additional lib required])
795       ;;
796     *)
797       if test -z "$curl_cv_save_LIBS"; then
798         LIBS="$curl_cv_ldap_LIBS"
799       else
800         LIBS="$curl_cv_ldap_LIBS $curl_cv_save_LIBS"
801       fi
802       AC_MSG_RESULT([$curl_cv_ldap_LIBS])
803       ;;
804   esac
805   #
806 ])
807
808
809 dnl CURL_CHECK_HEADER_MALLOC
810 dnl -------------------------------------------------
811 dnl Check for compilable and valid malloc.h header,
812 dnl and check if it is needed even with stdlib.h
813
814 AC_DEFUN([CURL_CHECK_HEADER_MALLOC], [
815   AC_CACHE_CHECK([for malloc.h], [ac_cv_header_malloc_h], [
816     AC_COMPILE_IFELSE([
817       AC_LANG_PROGRAM([[
818 #include <malloc.h>
819       ]],[[
820         void *p = malloc(10);
821         void *q = calloc(10,10);
822         free(p);
823         free(q);
824       ]])
825     ],[
826       ac_cv_header_malloc_h="yes"
827     ],[
828       ac_cv_header_malloc_h="no"
829     ])
830   ])
831   if test "$ac_cv_header_malloc_h" = "yes"; then
832     AC_DEFINE_UNQUOTED(HAVE_MALLOC_H, 1,
833       [Define to 1 if you have the malloc.h header file.])
834     #
835     AC_COMPILE_IFELSE([
836       AC_LANG_PROGRAM([[
837 #include <stdlib.h>
838       ]],[[
839         void *p = malloc(10);
840         void *q = calloc(10,10);
841         free(p);
842         free(q);
843       ]])
844     ],[
845       curl_cv_need_header_malloc_h="no"
846     ],[
847       curl_cv_need_header_malloc_h="yes"
848     ])
849     #
850     case "$curl_cv_need_header_malloc_h" in
851       yes)
852         AC_DEFINE_UNQUOTED(NEED_MALLOC_H, 1,
853           [Define to 1 if you need the malloc.h header file even with stdlib.h])
854         ;;
855     esac
856   fi
857 ])
858
859
860 dnl CURL_CHECK_TYPE_SOCKLEN_T
861 dnl -------------------------------------------------
862 dnl Check for existing socklen_t type, and provide
863 dnl an equivalent type if socklen_t not available
864
865 AC_DEFUN([CURL_CHECK_TYPE_SOCKLEN_T], [
866   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
867   AC_CHECK_TYPE([socklen_t], ,[
868     dnl socklen_t not available
869     AC_CACHE_CHECK([for socklen_t equivalent],
870       [curl_cv_socklen_t_equiv], [
871       curl_cv_socklen_t_equiv="unknown"
872       for arg1 in 'int' 'SOCKET'; do
873         for arg2 in "struct sockaddr" void; do
874           for t in int size_t unsigned long "unsigned long"; do
875             if test "$curl_cv_socklen_t_equiv" = "unknown"; then
876               AC_COMPILE_IFELSE([
877                 AC_LANG_PROGRAM([[
878 #undef inline
879 #ifdef HAVE_WINDOWS_H
880 #ifndef WIN32_LEAN_AND_MEAN
881 #define WIN32_LEAN_AND_MEAN
882 #endif
883 #include <windows.h>
884 #ifdef HAVE_WINSOCK2_H
885 #include <winsock2.h>
886 #else
887 #ifdef HAVE_WINSOCK_H
888 #include <winsock.h>
889 #endif
890 #endif
891 #define GETPEERNCALLCONV PASCAL
892 #else
893 #ifdef HAVE_SYS_TYPES_H
894 #include <sys/types.h>
895 #endif
896 #ifdef HAVE_SYS_SOCKET_H
897 #include <sys/socket.h>
898 #endif
899 #define GETPEERNCALLCONV
900 #endif
901                   extern int GETPEERNCALLCONV getpeername($arg1, $arg2 *, $t *);
902                 ]],[[
903                   $t len=0;
904                   getpeername(0,0,&len);
905                 ]])
906               ],[
907                 curl_cv_socklen_t_equiv="$t"
908               ])
909             fi
910           done
911         done
912       done
913     ])
914     case "$curl_cv_socklen_t_equiv" in
915       unknown)
916         AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
917         ;;
918       *)
919         AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
920           [Type to use in place of socklen_t when system does not provide it.])
921         ;;
922     esac
923   ],[
924 #undef inline
925 #ifdef HAVE_WINDOWS_H
926 #ifndef WIN32_LEAN_AND_MEAN
927 #define WIN32_LEAN_AND_MEAN
928 #endif
929 #include <windows.h>
930 #ifdef HAVE_WINSOCK2_H
931 #include <winsock2.h>
932 #ifdef HAVE_WS2TCPIP_H
933 #include <ws2tcpip.h>
934 #endif
935 #endif
936 #else
937 #ifdef HAVE_SYS_TYPES_H
938 #include <sys/types.h>
939 #endif
940 #ifdef HAVE_SYS_SOCKET_H
941 #include <sys/socket.h>
942 #endif
943 #endif
944   ])
945 ])
946
947
948 dnl CURL_CHECK_FUNC_GETNAMEINFO
949 dnl -------------------------------------------------
950 dnl Test if the getnameinfo function is available, 
951 dnl and check the types of five of its arguments.
952 dnl If the function succeeds HAVE_GETNAMEINFO will be
953 dnl defined, defining the types of the arguments in
954 dnl GETNAMEINFO_TYPE_ARG1, GETNAMEINFO_TYPE_ARG2,
955 dnl GETNAMEINFO_TYPE_ARG46 and GETNAMEINFO_TYPE_ARG7,
956 dnl and also defining the type qualifier of first 
957 dnl argument in GETNAMEINFO_QUAL_ARG1.
958
959 AC_DEFUN([CURL_CHECK_FUNC_GETNAMEINFO], [
960   AC_REQUIRE([CURL_CHECK_HEADER_WS2TCPIP])dnl
961   AC_REQUIRE([CURL_CHECK_TYPE_SOCKLEN_T])dnl
962   AC_CHECK_HEADERS(sys/types.h sys/socket.h netdb.h)
963   #
964   AC_MSG_CHECKING([for getnameinfo])
965   AC_LINK_IFELSE([
966     AC_LANG_FUNC_LINK_TRY([getnameinfo])
967   ],[
968     AC_MSG_RESULT([yes])
969     curl_cv_getnameinfo="yes"
970   ],[
971     AC_MSG_RESULT([no])
972     curl_cv_getnameinfo="no"
973   ])
974   #
975   if test "$curl_cv_getnameinfo" != "yes"; then
976     AC_MSG_CHECKING([deeper for getnameinfo])
977     AC_LINK_IFELSE([
978       AC_LANG_PROGRAM([[
979       ]],[[
980         getnameinfo();
981       ]])
982     ],[
983       AC_MSG_RESULT([yes])
984       curl_cv_getnameinfo="yes"
985     ],[
986       AC_MSG_RESULT([but still no])
987       curl_cv_getnameinfo="no"
988     ])
989   fi
990   #
991   if test "$curl_cv_getnameinfo" != "yes"; then
992     AC_MSG_CHECKING([deeper and deeper for getnameinfo])
993     AC_LINK_IFELSE([
994       AC_LANG_PROGRAM([[
995 #undef inline
996 #ifdef HAVE_WINDOWS_H
997 #ifndef WIN32_LEAN_AND_MEAN
998 #define WIN32_LEAN_AND_MEAN
999 #endif
1000 #include <windows.h>
1001 #ifdef HAVE_WINSOCK2_H
1002 #include <winsock2.h>
1003 #ifdef HAVE_WS2TCPIP_H
1004 #include <ws2tcpip.h>
1005 #endif
1006 #endif
1007 #else
1008 #ifdef HAVE_SYS_TYPES_H
1009 #include <sys/types.h>
1010 #endif
1011 #ifdef HAVE_SYS_SOCKET_H
1012 #include <sys/socket.h>
1013 #endif
1014 #ifdef HAVE_NETDB_H
1015 #include <netdb.h>
1016 #endif
1017 #endif
1018       ]],[[
1019         getnameinfo(0, 0, 0, 0, 0, 0, 0);
1020       ]])
1021     ],[
1022       AC_MSG_RESULT([yes])
1023       curl_cv_getnameinfo="yes"
1024     ],[
1025       AC_MSG_RESULT([but still no])
1026       curl_cv_getnameinfo="no"
1027     ])
1028   fi
1029   #
1030   if test "$curl_cv_getnameinfo" = "yes"; then
1031     AC_CACHE_CHECK([types of arguments for getnameinfo],
1032       [curl_cv_func_getnameinfo_args], [
1033       curl_cv_func_getnameinfo_args="unknown"
1034       for gni_arg1 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
1035         for gni_arg2 in 'socklen_t' 'size_t' 'int'; do
1036           for gni_arg46 in 'size_t' 'int' 'socklen_t' 'unsigned int' 'DWORD'; do
1037             for gni_arg7 in 'int' 'unsigned int'; do
1038               if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
1039                 AC_COMPILE_IFELSE([
1040                   AC_LANG_PROGRAM([[
1041 #undef inline 
1042 #ifdef HAVE_WINDOWS_H
1043 #ifndef WIN32_LEAN_AND_MEAN
1044 #define WIN32_LEAN_AND_MEAN
1045 #endif
1046 #if (!defined(_WIN32_WINNT)) || (_WIN32_WINNT < 0x0501)
1047 #undef _WIN32_WINNT
1048 #define _WIN32_WINNT 0x0501
1049 #endif
1050 #include <windows.h>
1051 #ifdef HAVE_WINSOCK2_H
1052 #include <winsock2.h> 
1053 #ifdef HAVE_WS2TCPIP_H
1054 #include <ws2tcpip.h>
1055 #endif
1056 #endif
1057 #define GNICALLCONV WSAAPI
1058 #else
1059 #ifdef HAVE_SYS_TYPES_H
1060 #include <sys/types.h>
1061 #endif
1062 #ifdef HAVE_SYS_SOCKET_H
1063 #include <sys/socket.h>
1064 #endif
1065 #ifdef HAVE_NETDB_H
1066 #include <netdb.h>
1067 #endif
1068 #define GNICALLCONV
1069 #endif
1070                     extern int GNICALLCONV getnameinfo($gni_arg1, $gni_arg2,
1071                                            char *, $gni_arg46,
1072                                            char *, $gni_arg46,
1073                                            $gni_arg7);
1074                   ]],[[
1075                     $gni_arg2 salen=0;
1076                     $gni_arg46 hostlen=0;
1077                     $gni_arg46 servlen=0;
1078                     $gni_arg7 flags=0;
1079                     int res = getnameinfo(0, salen, 0, hostlen, 0, servlen, flags);
1080                   ]])
1081                 ],[
1082                   curl_cv_func_getnameinfo_args="$gni_arg1,$gni_arg2,$gni_arg46,$gni_arg7"
1083                 ])
1084               fi
1085             done
1086           done
1087         done
1088       done
1089     ]) # AC_CACHE_CHECK
1090     if test "$curl_cv_func_getnameinfo_args" = "unknown"; then
1091       AC_MSG_WARN([Cannot find proper types to use for getnameinfo args])
1092       AC_MSG_WARN([HAVE_GETNAMEINFO will not be defined])
1093     else
1094       gni_prev_IFS=$IFS; IFS=','
1095       set dummy `echo "$curl_cv_func_getnameinfo_args" | sed 's/\*/\*/g'`
1096       IFS=$gni_prev_IFS
1097       shift
1098       #
1099       gni_qual_type_arg1=$[1]
1100       #
1101       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG2, $[2],
1102         [Define to the type of arg 2 for getnameinfo.])
1103       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG46, $[3],
1104         [Define to the type of args 4 and 6 for getnameinfo.])
1105       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG7, $[4],
1106         [Define to the type of arg 7 for getnameinfo.])
1107       #
1108       prev_sh_opts=$-
1109       #
1110       case $prev_sh_opts in
1111         *f*)
1112           ;;
1113         *)
1114           set -f
1115           ;;
1116       esac
1117       #
1118       case "$gni_qual_type_arg1" in
1119         const*)
1120           gni_qual_arg1=const
1121           gni_type_arg1=`echo $gni_qual_type_arg1 | sed 's/^const //'`
1122         ;;
1123         *)
1124           gni_qual_arg1=
1125           gni_type_arg1=$gni_qual_type_arg1
1126         ;;
1127       esac
1128       #
1129       AC_DEFINE_UNQUOTED(GETNAMEINFO_QUAL_ARG1, $gni_qual_arg1,
1130         [Define to the type qualifier of arg 1 for getnameinfo.])
1131       AC_DEFINE_UNQUOTED(GETNAMEINFO_TYPE_ARG1, $gni_type_arg1,
1132         [Define to the type of arg 1 for getnameinfo.])
1133       #
1134       case $prev_sh_opts in
1135         *f*)
1136           ;;
1137         *)
1138           set +f
1139           ;;
1140       esac
1141       #
1142       AC_DEFINE_UNQUOTED(HAVE_GETNAMEINFO, 1,
1143         [Define to 1 if you have the getnameinfo function.])
1144       ac_cv_func_getnameinfo="yes"
1145     fi
1146   fi
1147 ]) # AC_DEFUN
1148
1149
1150 dnl TYPE_SOCKADDR_STORAGE
1151 dnl -------------------------------------------------
1152 dnl Check for struct sockaddr_storage. Most IPv6-enabled 
1153 dnl hosts have it, but AIX 4.3 is one known exception.
1154
1155 AC_DEFUN([TYPE_SOCKADDR_STORAGE],
1156 [
1157    AC_CHECK_TYPE([struct sockaddr_storage],
1158         AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE, 1,
1159                   [if struct sockaddr_storage is defined]), ,
1160    [
1161 #undef inline
1162 #ifdef HAVE_WINDOWS_H
1163 #ifndef WIN32_LEAN_AND_MEAN
1164 #define WIN32_LEAN_AND_MEAN
1165 #endif
1166 #include <windows.h>
1167 #ifdef HAVE_WINSOCK2_H
1168 #include <winsock2.h>
1169 #endif
1170 #else
1171 #ifdef HAVE_SYS_TYPES_H
1172 #include <sys/types.h>
1173 #endif
1174 #ifdef HAVE_SYS_SOCKET_H
1175 #include <sys/socket.h>
1176 #endif
1177 #ifdef HAVE_NETINET_IN_H
1178 #include <netinet/in.h>
1179 #endif
1180 #ifdef HAVE_ARPA_INET_H
1181 #include <arpa/inet.h>
1182 #endif
1183 #endif
1184    ])
1185 ])
1186
1187
1188 dnl CURL_CHECK_NI_WITHSCOPEID
1189 dnl -------------------------------------------------
1190 dnl Check for working NI_WITHSCOPEID in getnameinfo()
1191
1192 AC_DEFUN([CURL_CHECK_NI_WITHSCOPEID], [
1193   AC_REQUIRE([CURL_CHECK_FUNC_GETNAMEINFO])dnl
1194   AC_REQUIRE([TYPE_SOCKADDR_STORAGE])dnl
1195   AC_CHECK_HEADERS(stdio.h sys/types.h sys/socket.h \
1196                    netdb.h netinet/in.h arpa/inet.h)
1197   #
1198   AC_CACHE_CHECK([for working NI_WITHSCOPEID], 
1199     [ac_cv_working_ni_withscopeid], [
1200     AC_RUN_IFELSE([
1201       AC_LANG_PROGRAM([[
1202 #ifdef HAVE_STDIO_H
1203 #include <stdio.h>
1204 #endif
1205 #ifdef HAVE_SYS_TYPES_H
1206 #include <sys/types.h>
1207 #endif
1208 #ifdef HAVE_SYS_SOCKET_H
1209 #include <sys/socket.h>
1210 #endif
1211 #ifdef HAVE_NETDB_H
1212 #include <netdb.h>
1213 #endif
1214 #ifdef HAVE_NETINET_IN_H
1215 #include <netinet/in.h>
1216 #endif
1217 #ifdef HAVE_ARPA_INET_H
1218 #include <arpa/inet.h>
1219 #endif
1220       ]],[[
1221 #if defined(NI_WITHSCOPEID) && defined(HAVE_GETNAMEINFO)
1222 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
1223         struct sockaddr_storage sa;
1224 #else
1225         unsigned char sa[256];
1226 #endif
1227         char hostbuf[NI_MAXHOST];
1228         int rc;
1229         GETNAMEINFO_TYPE_ARG2 salen = (GETNAMEINFO_TYPE_ARG2)sizeof(sa);
1230         GETNAMEINFO_TYPE_ARG46 hostlen = (GETNAMEINFO_TYPE_ARG46)sizeof(hostbuf);
1231         GETNAMEINFO_TYPE_ARG7 flags = NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
1232         int fd = socket(AF_INET6, SOCK_STREAM, 0);
1233         if(fd < 0) {
1234           perror("socket()");
1235           return 1; /* Error creating socket */
1236         }
1237         rc = getsockname(fd, (GETNAMEINFO_TYPE_ARG1)&sa, &salen);
1238         if(rc) {
1239           perror("getsockname()");
1240           return 2; /* Error retrieving socket name */
1241         }
1242         rc = getnameinfo((GETNAMEINFO_TYPE_ARG1)&sa, salen, hostbuf, hostlen, NULL, 0, flags);
1243         if(rc) {
1244           printf("rc = %s\n", gai_strerror(rc));
1245           return 3; /* Error translating socket address */
1246         }
1247         return 0; /* Ok, NI_WITHSCOPEID works */
1248 #else
1249         return 4; /* Error, NI_WITHSCOPEID not defined or no getnameinfo() */
1250 #endif
1251       ]]) # AC_LANG_PROGRAM
1252     ],[
1253       # Exit code == 0. Program worked.
1254       ac_cv_working_ni_withscopeid="yes"
1255     ],[
1256       # Exit code != 0. Program failed.
1257       ac_cv_working_ni_withscopeid="no"
1258     ],[
1259       # Program is not run when cross-compiling. So we assume
1260       # NI_WITHSCOPEID will work if we are able to compile it.
1261       AC_COMPILE_IFELSE([
1262         AC_LANG_PROGRAM([[
1263 #include <sys/types.h>
1264 #include <sys/socket.h>
1265 #include <netdb.h>
1266         ]],[[
1267           unsigned int dummy= NI_NUMERICHOST | NI_NUMERICSERV | NI_WITHSCOPEID;
1268         ]])
1269       ],[
1270         ac_cv_working_ni_withscopeid="yes"
1271       ],[
1272         ac_cv_working_ni_withscopeid="no"
1273       ]) # AC_COMPILE_IFELSE
1274     ]) # AC_RUN_IFELSE
1275   ]) # AC_CACHE_CHECK
1276   case "$ac_cv_working_ni_withscopeid" in
1277     yes)
1278       AC_DEFINE(HAVE_NI_WITHSCOPEID, 1,
1279         [Define to 1 if NI_WITHSCOPEID exists and works.])
1280       ;;
1281   esac
1282 ]) # AC_DEFUN
1283
1284
1285 dnl CURL_CHECK_FUNC_RECV
1286 dnl -------------------------------------------------
1287 dnl Test if the socket recv() function is available, 
1288 dnl and check its return type and the types of its 
1289 dnl arguments. If the function succeeds HAVE_RECV 
1290 dnl will be defined, defining the types of the arguments 
1291 dnl in RECV_TYPE_ARG1, RECV_TYPE_ARG2, RECV_TYPE_ARG3 
1292 dnl and RECV_TYPE_ARG4, defining the type of the function
1293 dnl return value in RECV_TYPE_RETV.
1294
1295 AC_DEFUN([CURL_CHECK_FUNC_RECV], [
1296   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1297   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1298   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1299   #
1300   AC_MSG_CHECKING([for recv])
1301   AC_LINK_IFELSE([
1302     AC_LANG_PROGRAM([[
1303 #undef inline 
1304 #ifdef HAVE_WINDOWS_H
1305 #ifndef WIN32_LEAN_AND_MEAN
1306 #define WIN32_LEAN_AND_MEAN
1307 #endif
1308 #include <windows.h>
1309 #ifdef HAVE_WINSOCK2_H
1310 #include <winsock2.h>
1311 #else
1312 #ifdef HAVE_WINSOCK_H
1313 #include <winsock.h>
1314 #endif
1315 #endif
1316 #else
1317 #ifdef HAVE_SYS_TYPES_H
1318 #include <sys/types.h>
1319 #endif
1320 #ifdef HAVE_SYS_SOCKET_H
1321 #include <sys/socket.h>
1322 #endif
1323 #endif
1324     ]],[[
1325       recv(0, 0, 0, 0);
1326     ]])
1327   ],[
1328     AC_MSG_RESULT([yes])
1329     curl_cv_recv="yes"
1330   ],[
1331     AC_MSG_RESULT([no])
1332     curl_cv_recv="no"
1333   ])
1334   #
1335   if test "$curl_cv_recv" = "yes"; then
1336     AC_CACHE_CHECK([types of args and return type for recv],
1337       [curl_cv_func_recv_args], [
1338       curl_cv_func_recv_args="unknown"
1339       for recv_retv in 'int' 'ssize_t'; do
1340         for recv_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1341           for recv_arg2 in 'char *' 'void *'; do
1342             for recv_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1343               for recv_arg4 in 'int' 'unsigned int'; do
1344                 if test "$curl_cv_func_recv_args" = "unknown"; then
1345                   AC_COMPILE_IFELSE([
1346                     AC_LANG_PROGRAM([[
1347 #undef inline 
1348 #ifdef HAVE_WINDOWS_H
1349 #ifndef WIN32_LEAN_AND_MEAN
1350 #define WIN32_LEAN_AND_MEAN
1351 #endif
1352 #include <windows.h>
1353 #ifdef HAVE_WINSOCK2_H
1354 #include <winsock2.h>
1355 #else
1356 #ifdef HAVE_WINSOCK_H
1357 #include <winsock.h>
1358 #endif
1359 #endif
1360 #define RECVCALLCONV PASCAL
1361 #else
1362 #ifdef HAVE_SYS_TYPES_H
1363 #include <sys/types.h>
1364 #endif
1365 #ifdef HAVE_SYS_SOCKET_H
1366 #include <sys/socket.h>
1367 #endif
1368 #define RECVCALLCONV
1369 #endif
1370                       extern $recv_retv RECVCALLCONV
1371                       recv($recv_arg1, $recv_arg2, $recv_arg3, $recv_arg4);
1372                     ]],[[
1373                       $recv_arg1 s=0;
1374                       $recv_arg2 buf=0;
1375                       $recv_arg3 len=0;
1376                       $recv_arg4 flags=0;
1377                       $recv_retv res = recv(s, buf, len, flags);
1378                     ]])
1379                   ],[
1380                     curl_cv_func_recv_args="$recv_arg1,$recv_arg2,$recv_arg3,$recv_arg4,$recv_retv"
1381                   ])
1382                 fi
1383               done
1384             done
1385           done
1386         done
1387       done
1388     ]) # AC_CACHE_CHECK
1389     if test "$curl_cv_func_recv_args" = "unknown"; then
1390       AC_MSG_ERROR([Cannot find proper types to use for recv args])
1391     else
1392       recv_prev_IFS=$IFS; IFS=','
1393       set dummy `echo "$curl_cv_func_recv_args" | sed 's/\*/\*/g'`
1394       IFS=$recv_prev_IFS
1395       shift
1396       #
1397       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG1, $[1],
1398         [Define to the type of arg 1 for recv.])
1399       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG2, $[2],
1400         [Define to the type of arg 2 for recv.])
1401       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG3, $[3],
1402         [Define to the type of arg 3 for recv.])
1403       AC_DEFINE_UNQUOTED(RECV_TYPE_ARG4, $[4],
1404         [Define to the type of arg 4 for recv.])
1405       AC_DEFINE_UNQUOTED(RECV_TYPE_RETV, $[5],
1406         [Define to the function return type for recv.])
1407       #
1408       AC_DEFINE_UNQUOTED(HAVE_RECV, 1,
1409         [Define to 1 if you have the recv function.])
1410       ac_cv_func_recv="yes"
1411     fi
1412   else
1413     AC_MSG_ERROR([Unable to link function recv])
1414   fi
1415 ]) # AC_DEFUN
1416
1417
1418 dnl CURL_CHECK_FUNC_SEND
1419 dnl -------------------------------------------------
1420 dnl Test if the socket send() function is available, 
1421 dnl and check its return type and the types of its 
1422 dnl arguments. If the function succeeds HAVE_SEND 
1423 dnl will be defined, defining the types of the arguments 
1424 dnl in SEND_TYPE_ARG1, SEND_TYPE_ARG2, SEND_TYPE_ARG3 
1425 dnl and SEND_TYPE_ARG4, defining the type of the function
1426 dnl return value in SEND_TYPE_RETV, and also defining the 
1427 dnl type qualifier of second argument in SEND_QUAL_ARG2.
1428
1429 AC_DEFUN([CURL_CHECK_FUNC_SEND], [
1430   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1431   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1432   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1433   #
1434   AC_MSG_CHECKING([for send])
1435   AC_LINK_IFELSE([
1436     AC_LANG_PROGRAM([[
1437 #undef inline 
1438 #ifdef HAVE_WINDOWS_H
1439 #ifndef WIN32_LEAN_AND_MEAN
1440 #define WIN32_LEAN_AND_MEAN
1441 #endif
1442 #include <windows.h>
1443 #ifdef HAVE_WINSOCK2_H
1444 #include <winsock2.h>
1445 #else
1446 #ifdef HAVE_WINSOCK_H
1447 #include <winsock.h>
1448 #endif
1449 #endif
1450 #else
1451 #ifdef HAVE_SYS_TYPES_H
1452 #include <sys/types.h>
1453 #endif
1454 #ifdef HAVE_SYS_SOCKET_H
1455 #include <sys/socket.h>
1456 #endif
1457 #endif
1458     ]],[[
1459       send(0, 0, 0, 0);
1460     ]])
1461   ],[
1462     AC_MSG_RESULT([yes])
1463     curl_cv_send="yes"
1464   ],[
1465     AC_MSG_RESULT([no])
1466     curl_cv_send="no"
1467   ])
1468   #
1469   if test "$curl_cv_send" = "yes"; then
1470     AC_CACHE_CHECK([types of args and return type for send],
1471       [curl_cv_func_send_args], [
1472       curl_cv_func_send_args="unknown"
1473       for send_retv in 'int' 'ssize_t'; do
1474         for send_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1475           for send_arg2 in 'char *' 'void *' 'const char *' 'const void *'; do
1476             for send_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1477               for send_arg4 in 'int' 'unsigned int'; do
1478                 if test "$curl_cv_func_send_args" = "unknown"; then
1479                   AC_COMPILE_IFELSE([
1480                     AC_LANG_PROGRAM([[
1481 #undef inline 
1482 #ifdef HAVE_WINDOWS_H
1483 #ifndef WIN32_LEAN_AND_MEAN
1484 #define WIN32_LEAN_AND_MEAN
1485 #endif
1486 #include <windows.h>
1487 #ifdef HAVE_WINSOCK2_H
1488 #include <winsock2.h>
1489 #else
1490 #ifdef HAVE_WINSOCK_H
1491 #include <winsock.h>
1492 #endif
1493 #endif
1494 #define SENDCALLCONV PASCAL
1495 #else
1496 #ifdef HAVE_SYS_TYPES_H
1497 #include <sys/types.h>
1498 #endif
1499 #ifdef HAVE_SYS_SOCKET_H
1500 #include <sys/socket.h>
1501 #endif
1502 #define SENDCALLCONV
1503 #endif
1504                       extern $send_retv SENDCALLCONV
1505                       send($send_arg1, $send_arg2, $send_arg3, $send_arg4);
1506                     ]],[[
1507                       $send_arg1 s=0;
1508                       $send_arg3 len=0;
1509                       $send_arg4 flags=0;
1510                       $send_retv res = send(s, 0, len, flags);
1511                     ]])
1512                   ],[
1513                     curl_cv_func_send_args="$send_arg1,$send_arg2,$send_arg3,$send_arg4,$send_retv"
1514                   ])
1515                 fi
1516               done
1517             done
1518           done
1519         done
1520       done
1521     ]) # AC_CACHE_CHECK
1522     if test "$curl_cv_func_send_args" = "unknown"; then
1523       AC_MSG_ERROR([Cannot find proper types to use for send args])
1524     else
1525       send_prev_IFS=$IFS; IFS=','
1526       set dummy `echo "$curl_cv_func_send_args" | sed 's/\*/\*/g'`
1527       IFS=$send_prev_IFS
1528       shift
1529       #
1530       send_qual_type_arg2=$[2]
1531       #
1532       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG1, $[1],
1533         [Define to the type of arg 1 for send.])
1534       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG3, $[3],
1535         [Define to the type of arg 3 for send.])
1536       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG4, $[4],
1537         [Define to the type of arg 4 for send.])
1538       AC_DEFINE_UNQUOTED(SEND_TYPE_RETV, $[5],
1539         [Define to the function return type for send.])
1540       #
1541       prev_sh_opts=$-
1542       #
1543       case $prev_sh_opts in
1544         *f*)
1545           ;;
1546         *)
1547           set -f
1548           ;;
1549       esac
1550       #
1551       case "$send_qual_type_arg2" in
1552         const*)
1553           send_qual_arg2=const
1554           send_type_arg2=`echo $send_qual_type_arg2 | sed 's/^const //'`
1555         ;;
1556         *)
1557           send_qual_arg2=
1558           send_type_arg2=$send_qual_type_arg2
1559         ;;
1560       esac
1561       #
1562       AC_DEFINE_UNQUOTED(SEND_QUAL_ARG2, $send_qual_arg2,
1563         [Define to the type qualifier of arg 2 for send.])
1564       AC_DEFINE_UNQUOTED(SEND_TYPE_ARG2, $send_type_arg2,
1565         [Define to the type of arg 2 for send.])
1566       #
1567       case $prev_sh_opts in
1568         *f*)
1569           ;;
1570         *)
1571           set +f
1572           ;;
1573       esac
1574       #
1575       AC_DEFINE_UNQUOTED(HAVE_SEND, 1,
1576         [Define to 1 if you have the send function.])
1577       ac_cv_func_send="yes"
1578     fi
1579   else
1580     AC_MSG_ERROR([Unable to link function send])
1581   fi
1582 ]) # AC_DEFUN
1583
1584
1585 dnl CURL_CHECK_FUNC_RECVFROM
1586 dnl -------------------------------------------------
1587 dnl Test if the socket recvfrom() function is available,
1588 dnl and check its return type and the types of its
1589 dnl arguments. If the function succeeds HAVE_RECVFROM
1590 dnl will be defined, defining the types of the arguments
1591 dnl in RECVFROM_TYPE_ARG1, RECVFROM_TYPE_ARG2, and so on
1592 dnl to RECVFROM_TYPE_ARG6, defining also the type of the
1593 dnl function return value in RECVFROM_TYPE_RETV.
1594 dnl Notice that the types returned for pointer arguments
1595 dnl will actually be the type pointed by the pointer.
1596
1597 AC_DEFUN([CURL_CHECK_FUNC_RECVFROM], [
1598   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1599   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1600   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1601   #
1602   AC_MSG_CHECKING([for recvfrom])
1603   AC_LINK_IFELSE([
1604     AC_LANG_PROGRAM([[
1605 #undef inline 
1606 #ifdef HAVE_WINDOWS_H
1607 #ifndef WIN32_LEAN_AND_MEAN
1608 #define WIN32_LEAN_AND_MEAN
1609 #endif
1610 #include <windows.h>
1611 #ifdef HAVE_WINSOCK2_H
1612 #include <winsock2.h>
1613 #else
1614 #ifdef HAVE_WINSOCK_H
1615 #include <winsock.h>
1616 #endif
1617 #endif
1618 #else
1619 #ifdef HAVE_SYS_TYPES_H
1620 #include <sys/types.h>
1621 #endif
1622 #ifdef HAVE_SYS_SOCKET_H
1623 #include <sys/socket.h>
1624 #endif
1625 #endif
1626     ]],[[
1627       recvfrom(0, 0, 0, 0, 0, 0);
1628     ]])
1629   ],[
1630     AC_MSG_RESULT([yes])
1631     curl_cv_recvfrom="yes"
1632   ],[
1633     AC_MSG_RESULT([no])
1634     curl_cv_recvfrom="no"
1635   ])
1636   #
1637   if test "$curl_cv_recvfrom" = "yes"; then
1638     AC_CACHE_CHECK([types of args and return type for recvfrom],
1639       [curl_cv_func_recvfrom_args], [
1640       curl_cv_func_recvfrom_args="unknown"
1641       for recvfrom_retv in 'int' 'ssize_t'; do
1642         for recvfrom_arg1 in 'int' 'ssize_t' 'SOCKET'; do
1643           for recvfrom_arg2 in 'char *' 'void *'; do
1644             for recvfrom_arg3 in 'size_t' 'int' 'socklen_t' 'unsigned int'; do
1645               for recvfrom_arg4 in 'int' 'unsigned int'; do
1646                 for recvfrom_arg5 in 'struct sockaddr *' 'void *'; do
1647                   for recvfrom_arg6 in 'socklen_t *' 'int *' 'unsigned int *' 'size_t *' 'void *'; do
1648                     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1649                       AC_COMPILE_IFELSE([
1650                         AC_LANG_PROGRAM([[
1651 #undef inline 
1652 #ifdef HAVE_WINDOWS_H
1653 #ifndef WIN32_LEAN_AND_MEAN
1654 #define WIN32_LEAN_AND_MEAN
1655 #endif
1656 #include <windows.h>
1657 #ifdef HAVE_WINSOCK2_H
1658 #include <winsock2.h>
1659 #else
1660 #ifdef HAVE_WINSOCK_H
1661 #include <winsock.h>
1662 #endif
1663 #endif
1664 #define RECVFROMCALLCONV PASCAL
1665 #else
1666 #ifdef HAVE_SYS_TYPES_H
1667 #include <sys/types.h>
1668 #endif
1669 #ifdef HAVE_SYS_SOCKET_H
1670 #include <sys/socket.h>
1671 #endif
1672 #define RECVFROMCALLCONV
1673 #endif
1674                           extern $recvfrom_retv RECVFROMCALLCONV
1675                           recvfrom($recvfrom_arg1, $recvfrom_arg2,
1676                                    $recvfrom_arg3, $recvfrom_arg4,
1677                                    $recvfrom_arg5, $recvfrom_arg6);
1678                         ]],[[
1679                           $recvfrom_arg1 s=0;
1680                           $recvfrom_arg2 buf=0;
1681                           $recvfrom_arg3 len=0;
1682                           $recvfrom_arg4 flags=0;
1683                           $recvfrom_arg5 addr=0;
1684                           $recvfrom_arg6 addrlen=0;
1685                           $recvfrom_retv res=0;
1686                           res = recvfrom(s, buf, len, flags, addr, addrlen);
1687                         ]])
1688                       ],[
1689                         curl_cv_func_recvfrom_args="$recvfrom_arg1,$recvfrom_arg2,$recvfrom_arg3,$recvfrom_arg4,$recvfrom_arg5,$recvfrom_arg6,$recvfrom_retv"
1690                       ])
1691                     fi
1692                   done
1693                 done
1694               done
1695             done
1696           done
1697         done
1698       done
1699     ]) # AC_CACHE_CHECK
1700     if test "$curl_cv_func_recvfrom_args" = "unknown"; then
1701       AC_MSG_ERROR([Cannot find proper types to use for recvfrom args])
1702     else
1703       recvfrom_prev_IFS=$IFS; IFS=','
1704       set dummy `echo "$curl_cv_func_recvfrom_args" | sed 's/\*/\*/g'`
1705       IFS=$recvfrom_prev_IFS
1706       shift
1707       #
1708       recvfrom_ptrt_arg2=$[2]
1709       recvfrom_ptrt_arg5=$[5]
1710       recvfrom_ptrt_arg6=$[6]
1711       #
1712       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG1, $[1],
1713         [Define to the type of arg 1 for recvfrom.])
1714       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG3, $[3],
1715         [Define to the type of arg 3 for recvfrom.])
1716       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG4, $[4],
1717         [Define to the type of arg 4 for recvfrom.])
1718       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_RETV, $[7],
1719         [Define to the function return type for recvfrom.])
1720       #
1721       prev_sh_opts=$-
1722       #
1723       case $prev_sh_opts in
1724         *f*)
1725           ;;
1726         *)
1727           set -f
1728           ;;
1729       esac
1730       #
1731       recvfrom_type_arg2=`echo $recvfrom_ptrt_arg2 | sed 's/ \*//'`
1732       recvfrom_type_arg5=`echo $recvfrom_ptrt_arg5 | sed 's/ \*//'`
1733       recvfrom_type_arg6=`echo $recvfrom_ptrt_arg6 | sed 's/ \*//'`
1734       #
1735       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2, $recvfrom_type_arg2,
1736         [Define to the type pointed by arg 2 for recvfrom.])
1737       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5, $recvfrom_type_arg5,
1738         [Define to the type pointed by arg 5 for recvfrom.])
1739       AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6, $recvfrom_type_arg6,
1740         [Define to the type pointed by arg 6 for recvfrom.])
1741       #
1742       if test "$recvfrom_type_arg2" = "void"; then
1743         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG2_IS_VOID, 1,
1744           [Define to 1 if the type pointed by arg 2 for recvfrom is void.])
1745       fi
1746       if test "$recvfrom_type_arg5" = "void"; then
1747         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG5_IS_VOID, 1,
1748           [Define to 1 if the type pointed by arg 5 for recvfrom is void.])
1749       fi
1750       if test "$recvfrom_type_arg6" = "void"; then
1751         AC_DEFINE_UNQUOTED(RECVFROM_TYPE_ARG6_IS_VOID, 1,
1752           [Define to 1 if the type pointed by arg 6 for recvfrom is void.])
1753       fi
1754       #
1755       case $prev_sh_opts in
1756         *f*)
1757           ;;
1758         *)
1759           set +f
1760           ;;
1761       esac
1762       #
1763       AC_DEFINE_UNQUOTED(HAVE_RECVFROM, 1,
1764         [Define to 1 if you have the recvfrom function.])
1765       ac_cv_func_recvfrom="yes"
1766     fi
1767   else
1768     AC_MSG_ERROR([Unable to link function recvfrom])
1769   fi
1770 ]) # AC_DEFUN
1771
1772
1773 dnl CURL_CHECK_MSG_NOSIGNAL
1774 dnl -------------------------------------------------
1775 dnl Check for MSG_NOSIGNAL
1776
1777 AC_DEFUN([CURL_CHECK_MSG_NOSIGNAL], [
1778   AC_CHECK_HEADERS(sys/types.h sys/socket.h)
1779   AC_CACHE_CHECK([for MSG_NOSIGNAL], [ac_cv_msg_nosignal], [
1780     AC_COMPILE_IFELSE([
1781       AC_LANG_PROGRAM([[
1782 #undef inline 
1783 #ifdef HAVE_WINDOWS_H
1784 #ifndef WIN32_LEAN_AND_MEAN
1785 #define WIN32_LEAN_AND_MEAN
1786 #endif
1787 #include <windows.h>
1788 #ifdef HAVE_WINSOCK2_H
1789 #include <winsock2.h>
1790 #else
1791 #ifdef HAVE_WINSOCK_H
1792 #include <winsock.h>
1793 #endif
1794 #endif
1795 #else
1796 #ifdef HAVE_SYS_TYPES_H
1797 #include <sys/types.h>
1798 #endif
1799 #ifdef HAVE_SYS_SOCKET_H
1800 #include <sys/socket.h>
1801 #endif
1802 #endif
1803       ]],[[
1804         int flag=MSG_NOSIGNAL;
1805       ]])
1806     ],[
1807       ac_cv_msg_nosignal="yes"
1808     ],[
1809       ac_cv_msg_nosignal="no"
1810     ])
1811   ])
1812   case "$ac_cv_msg_nosignal" in
1813     yes)
1814       AC_DEFINE_UNQUOTED(HAVE_MSG_NOSIGNAL, 1,
1815         [Define to 1 if you have the MSG_NOSIGNAL flag.])
1816       ;;
1817   esac
1818 ]) # AC_DEFUN
1819
1820
1821 dnl CURL_CHECK_STRUCT_TIMEVAL
1822 dnl -------------------------------------------------
1823 dnl Check for timeval struct
1824
1825 AC_DEFUN([CURL_CHECK_STRUCT_TIMEVAL], [
1826   AC_REQUIRE([AC_HEADER_TIME])dnl
1827   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK])dnl
1828   AC_REQUIRE([CURL_CHECK_HEADER_WINSOCK2])dnl
1829   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
1830   AC_CACHE_CHECK([for struct timeval], [ac_cv_struct_timeval], [
1831     AC_COMPILE_IFELSE([
1832       AC_LANG_PROGRAM([[
1833 #undef inline 
1834 #ifdef HAVE_WINDOWS_H
1835 #ifndef WIN32_LEAN_AND_MEAN
1836 #define WIN32_LEAN_AND_MEAN
1837 #endif
1838 #include <windows.h>
1839 #ifdef HAVE_WINSOCK2_H
1840 #include <winsock2.h>
1841 #else
1842 #ifdef HAVE_WINSOCK_H
1843 #include <winsock.h>
1844 #endif
1845 #endif
1846 #endif
1847 #ifdef HAVE_SYS_TYPES_H
1848 #include <sys/types.h>
1849 #endif
1850 #ifdef HAVE_SYS_TIME_H
1851 #include <sys/time.h>
1852 #ifdef TIME_WITH_SYS_TIME
1853 #include <time.h>
1854 #endif
1855 #else
1856 #ifdef HAVE_TIME_H
1857 #include <time.h>
1858 #endif
1859 #endif
1860       ]],[[
1861         struct timeval ts;
1862         ts.tv_sec  = 0;
1863         ts.tv_usec = 0;
1864       ]])
1865     ],[
1866       ac_cv_struct_timeval="yes"
1867     ],[
1868       ac_cv_struct_timeval="no"
1869     ])
1870   ])
1871   case "$ac_cv_struct_timeval" in
1872     yes)
1873       AC_DEFINE_UNQUOTED(HAVE_STRUCT_TIMEVAL, 1,
1874         [Define to 1 if you have the timeval struct.])
1875       ;;
1876   esac
1877 ]) # AC_DEFUN
1878
1879
1880 dnl TYPE_SIG_ATOMIC_T
1881 dnl -------------------------------------------------
1882 dnl Check if the sig_atomic_t type is available, and
1883 dnl verify if it is already defined as volatile.
1884
1885 AC_DEFUN([TYPE_SIG_ATOMIC_T], [
1886   AC_CHECK_HEADERS(signal.h)
1887   AC_CHECK_TYPE([sig_atomic_t],[
1888     AC_DEFINE(HAVE_SIG_ATOMIC_T, 1,
1889       [Define to 1 if sig_atomic_t is an available typedef.])
1890   ], ,[
1891 #ifdef HAVE_SIGNAL_H
1892 #include <signal.h>
1893 #endif
1894   ])
1895   case "$ac_cv_type_sig_atomic_t" in
1896     yes)
1897       #
1898       AC_MSG_CHECKING([if sig_atomic_t is already defined as volatile])
1899       AC_LINK_IFELSE([
1900         AC_LANG_PROGRAM([[
1901 #ifdef HAVE_SIGNAL_H
1902 #include <signal.h>
1903 #endif
1904         ]],[[
1905           static volatile sig_atomic_t dummy = 0;
1906         ]])
1907       ],[
1908         AC_MSG_RESULT([no])
1909         ac_cv_sig_atomic_t_volatile="no"
1910       ],[
1911         AC_MSG_RESULT([yes])
1912         ac_cv_sig_atomic_t_volatile="yes"
1913       ])
1914       #
1915       if test "$ac_cv_sig_atomic_t_volatile" = "yes"; then
1916         AC_DEFINE(HAVE_SIG_ATOMIC_T_VOLATILE, 1,
1917           [Define to 1 if sig_atomic_t is already defined as volatile.])
1918       fi
1919       ;;
1920   esac
1921 ]) # AC_DEFUN
1922
1923
1924 dnl CURL_CHECK_NONBLOCKING_SOCKET
1925 dnl -------------------------------------------------
1926 dnl Check for how to set a socket to non-blocking state. There seems to exist
1927 dnl four known different ways, with the one used almost everywhere being POSIX
1928 dnl and XPG3, while the other different ways for different systems (old BSD,
1929 dnl Windows and Amiga).
1930 dnl
1931 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the
1932 dnl O_NONBLOCK define is found but does not work. This condition is attempted
1933 dnl to get caught in this script by using an excessive number of #ifdefs...
1934
1935 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET], [
1936   AC_MSG_CHECKING([non-blocking sockets style])
1937   nonblock="unknown"
1938   #
1939   AC_COMPILE_IFELSE([
1940     AC_LANG_PROGRAM([[
1941 /* headers for O_NONBLOCK test */
1942 #include <sys/types.h>
1943 #include <unistd.h>
1944 #include <fcntl.h>
1945 /* */
1946 #if defined(sun) || defined(__sun__) || \
1947     defined(__SUNPRO_C) || defined(__SUNPRO_CC)
1948 # if defined(__SVR4) || defined(__srv4__)
1949 #  define PLATFORM_SOLARIS
1950 # else
1951 #  define PLATFORM_SUNOS4
1952 # endif
1953 #endif
1954 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX41)
1955 # define PLATFORM_AIX_V3
1956 #endif
1957 /* */
1958 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)
1959 #error "O_NONBLOCK does not work on this platform"
1960 #endif
1961     ]],[[
1962       /* O_NONBLOCK source test */
1963       int socket;
1964       int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);
1965     ]])
1966   ],[
1967     dnl the O_NONBLOCK test was fine
1968     nonblock="O_NONBLOCK"
1969     AC_DEFINE(HAVE_O_NONBLOCK, 1,
1970       [use O_NONBLOCK for non-blocking sockets])
1971   ])
1972   #
1973   if test "$nonblock" = "unknown"; then
1974     AC_COMPILE_IFELSE([
1975       AC_LANG_PROGRAM([[
1976 /* headers for FIONBIO test */
1977 #include <unistd.h>
1978 #include <stropts.h>
1979       ]],[[
1980         /* FIONBIO source test (old-style unix) */
1981         int socket;
1982         int flags = ioctl(socket, FIONBIO, &flags);
1983       ]])
1984     ],[
1985       dnl FIONBIO test was good
1986       nonblock="FIONBIO"
1987       AC_DEFINE(HAVE_FIONBIO, 1,
1988         [use FIONBIO for non-blocking sockets])
1989     ])
1990   fi
1991   #
1992   if test "$nonblock" = "unknown"; then
1993     AC_COMPILE_IFELSE([
1994       AC_LANG_PROGRAM([[
1995 /* headers for ioctlsocket test (Windows) */
1996 #undef inline
1997 #ifdef HAVE_WINDOWS_H
1998 #ifndef WIN32_LEAN_AND_MEAN
1999 #define WIN32_LEAN_AND_MEAN
2000 #endif
2001 #include <windows.h>
2002 #ifdef HAVE_WINSOCK2_H
2003 #include <winsock2.h>
2004 #else
2005 #ifdef HAVE_WINSOCK_H
2006 #include <winsock.h>
2007 #endif
2008 #endif
2009 #endif
2010       ]],[[
2011         /* ioctlsocket source code (Windows) */
2012         SOCKET sd;
2013         unsigned long flags = 0;
2014         sd = socket(0, 0, 0);
2015         ioctlsocket(sd, FIONBIO, &flags);
2016       ]])
2017     ],[
2018       dnl ioctlsocket test was good
2019       nonblock="ioctlsocket"
2020       AC_DEFINE(HAVE_IOCTLSOCKET, 1,
2021         [use ioctlsocket() for non-blocking sockets])
2022     ])
2023   fi
2024   #
2025   if test "$nonblock" = "unknown"; then
2026     AC_LINK_IFELSE([
2027       AC_LANG_PROGRAM([[
2028 /* headers for IoctlSocket test (Amiga?) */
2029 #include <sys/ioctl.h>
2030       ]],[[
2031         /* IoctlSocket source code (Amiga?) */
2032         int socket;
2033         int flags = IoctlSocket(socket, FIONBIO, (long)1);
2034       ]])
2035     ],[
2036       dnl Ioctlsocket test was good
2037       nonblock="IoctlSocket"
2038       AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1,
2039         [use Ioctlsocket() for non-blocking sockets])
2040     ])
2041   fi
2042   #
2043   if test "$nonblock" = "unknown"; then
2044     AC_COMPILE_IFELSE([
2045       AC_LANG_PROGRAM([[
2046 /* headers for SO_NONBLOCK test (BeOS) */
2047 #include <socket.h>
2048       ]],[[
2049         /* SO_NONBLOCK source code (BeOS) */
2050         long b = 1;
2051         int socket;
2052         int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));
2053       ]])
2054     ],[
2055       dnl the SO_NONBLOCK test was good
2056       nonblock="SO_NONBLOCK"
2057       AC_DEFINE(HAVE_SO_NONBLOCK, 1,
2058         [use SO_NONBLOCK for non-blocking sockets])
2059     ])
2060   fi
2061   #
2062   AC_MSG_RESULT($nonblock)
2063   #
2064   if test "$nonblock" = "unknown"; then
2065     AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1,
2066       [disabled non-blocking sockets])
2067     AC_MSG_WARN([non-block sockets disabled])
2068   fi
2069 ])
2070
2071
2072 dnl TYPE_IN_ADDR_T
2073 dnl -------------------------------------------------
2074 dnl Check for in_addr_t: it is used to receive the return code of inet_addr()
2075 dnl and a few other things.
2076
2077 AC_DEFUN([TYPE_IN_ADDR_T], [
2078   AC_CHECK_TYPE([in_addr_t], ,[
2079     dnl in_addr_t not available
2080     AC_CACHE_CHECK([for in_addr_t equivalent],
2081       [curl_cv_in_addr_t_equiv], [
2082       curl_cv_in_addr_t_equiv="unknown"
2083       for t in "unsigned long" int size_t unsigned long; do
2084         if test "$curl_cv_in_addr_t_equiv" = "unknown"; then
2085           AC_LINK_IFELSE([
2086             AC_LANG_PROGRAM([[
2087 #undef inline
2088 #ifdef HAVE_WINDOWS_H
2089 #ifndef WIN32_LEAN_AND_MEAN
2090 #define WIN32_LEAN_AND_MEAN
2091 #endif
2092 #include <windows.h>
2093 #ifdef HAVE_WINSOCK2_H
2094 #include <winsock2.h>
2095 #else
2096 #ifdef HAVE_WINSOCK_H
2097 #include <winsock.h>
2098 #endif
2099 #endif
2100 #else
2101 #ifdef HAVE_SYS_TYPES_H
2102 #include <sys/types.h>
2103 #endif
2104 #ifdef HAVE_SYS_SOCKET_H
2105 #include <sys/socket.h>
2106 #endif
2107 #ifdef HAVE_NETINET_IN_H
2108 #include <netinet/in.h>
2109 #endif
2110 #ifdef HAVE_ARPA_INET_H
2111 #include <arpa/inet.h>
2112 #endif
2113 #endif
2114             ]],[[
2115               $t data = inet_addr ("1.2.3.4");
2116             ]])
2117           ],[
2118             curl_cv_in_addr_t_equiv="$t"
2119           ])
2120         fi
2121       done
2122     ])
2123     case "$curl_cv_in_addr_t_equiv" in
2124       unknown)
2125         AC_MSG_ERROR([Cannot find a type to use in place of in_addr_t])
2126         ;;
2127       *)
2128         AC_DEFINE_UNQUOTED(in_addr_t, $curl_cv_in_addr_t_equiv,
2129           [Type to use in place of in_addr_t when system does not provide it.])
2130         ;;
2131     esac
2132   ],[
2133 #undef inline
2134 #ifdef HAVE_WINDOWS_H
2135 #ifndef WIN32_LEAN_AND_MEAN
2136 #define WIN32_LEAN_AND_MEAN
2137 #endif
2138 #include <windows.h>
2139 #ifdef HAVE_WINSOCK2_H
2140 #include <winsock2.h>
2141 #else
2142 #ifdef HAVE_WINSOCK_H
2143 #include <winsock.h>
2144 #endif
2145 #endif
2146 #else
2147 #ifdef HAVE_SYS_TYPES_H
2148 #include <sys/types.h>
2149 #endif
2150 #ifdef HAVE_SYS_SOCKET_H
2151 #include <sys/socket.h>
2152 #endif
2153 #ifdef HAVE_NETINET_IN_H
2154 #include <netinet/in.h>
2155 #endif
2156 #ifdef HAVE_ARPA_INET_H
2157 #include <arpa/inet.h>
2158 #endif
2159 #endif
2160   ]) dnl AC_CHECK_TYPE
2161 ]) dnl AC_DEFUN
2162
2163
2164 dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
2165 dnl -------------------------------------------------
2166 dnl Check if monotonic clock_gettime is available.
2167
2168 AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
2169   AC_REQUIRE([AC_HEADER_TIME])dnl
2170   AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
2171   AC_MSG_CHECKING([for monotonic clock_gettime])
2172   AC_COMPILE_IFELSE([
2173     AC_LANG_PROGRAM([[
2174 #ifdef HAVE_SYS_TYPES_H
2175 #include <sys/types.h>
2176 #endif
2177 #ifdef HAVE_SYS_TIME_H
2178 #include <sys/time.h>
2179 #ifdef TIME_WITH_SYS_TIME
2180 #include <time.h>
2181 #endif
2182 #else
2183 #ifdef HAVE_TIME_H
2184 #include <time.h>
2185 #endif
2186 #endif
2187     ]],[[
2188       struct timespec ts;
2189       (void)clock_gettime(CLOCK_MONOTONIC, &ts);
2190     ]])
2191   ],[
2192     AC_MSG_RESULT([yes])
2193     ac_cv_func_clock_gettime="yes"
2194   ],[
2195     AC_MSG_RESULT([no])
2196     ac_cv_func_clock_gettime="no"
2197   ])
2198   dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally postponed
2199   dnl until library linking and run-time checks for clock_gettime succeed.
2200 ]) dnl AC_DEFUN
2201
2202
2203 dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
2204 dnl -------------------------------------------------
2205 dnl If monotonic clock_gettime is available then,
2206 dnl check and prepended to LIBS any needed libraries.
2207
2208 AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
2209   AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
2210   #
2211   if test "$ac_cv_func_clock_gettime" = "yes"; then
2212     #
2213     AC_MSG_CHECKING([for clock_gettime in libraries])
2214     #
2215     curl_cv_save_LIBS="$LIBS"
2216     curl_cv_gclk_LIBS="unknown"
2217     #
2218     for x_xlibs in '' '-lrt' '-lposix4' ; do
2219       if test "$curl_cv_gclk_LIBS" = "unknown"; then
2220         if test -z "$x_xlibs"; then
2221           LIBS="$curl_cv_save_LIBS"
2222         else
2223           LIBS="$x_xlibs $curl_cv_save_LIBS"
2224         fi
2225         AC_LINK_IFELSE([
2226           AC_LANG_PROGRAM([[
2227 #ifdef HAVE_SYS_TYPES_H
2228 #include <sys/types.h>
2229 #endif
2230 #ifdef HAVE_SYS_TIME_H
2231 #include <sys/time.h>
2232 #ifdef TIME_WITH_SYS_TIME
2233 #include <time.h>
2234 #endif
2235 #else
2236 #ifdef HAVE_TIME_H
2237 #include <time.h>
2238 #endif
2239 #endif
2240           ]],[[
2241             struct timespec ts;
2242             (void)clock_gettime(CLOCK_MONOTONIC, &ts);
2243           ]])
2244         ],[
2245           curl_cv_gclk_LIBS="$x_xlibs"
2246         ])
2247       fi
2248     done
2249     #
2250     LIBS="$curl_cv_save_LIBS"
2251     #
2252     case X-"$curl_cv_gclk_LIBS" in
2253       X-unknown)
2254         AC_MSG_RESULT([cannot find clock_gettime])
2255         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
2256         ac_cv_func_clock_gettime="no"
2257         ;;
2258       X-)
2259         AC_MSG_RESULT([no additional lib required])
2260         ac_cv_func_clock_gettime="yes"
2261         ;;
2262       *)
2263         if test -z "$curl_cv_save_LIBS"; then
2264           LIBS="$curl_cv_gclk_LIBS"
2265         else
2266           LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
2267         fi
2268         AC_MSG_RESULT([$curl_cv_gclk_LIBS])
2269         ac_cv_func_clock_gettime="yes"
2270         ;;
2271     esac
2272     #
2273     dnl only do runtime verification when not cross-compiling
2274     if test "x$cross_compiling" != "xyes" &&
2275       test "$ac_cv_func_clock_gettime" = "yes"; then
2276       AC_MSG_CHECKING([if monotonic clock_gettime works])
2277       AC_RUN_IFELSE([
2278         AC_LANG_PROGRAM([[
2279 #ifdef HAVE_SYS_TYPES_H
2280 #include <sys/types.h>
2281 #endif
2282 #ifdef HAVE_SYS_TIME_H
2283 #include <sys/time.h>
2284 #ifdef TIME_WITH_SYS_TIME
2285 #include <time.h>
2286 #endif
2287 #else
2288 #ifdef HAVE_TIME_H
2289 #include <time.h>
2290 #endif
2291 #endif
2292         ]],[[
2293           struct timespec ts;
2294           if (0 == clock_gettime(CLOCK_MONOTONIC, &ts))
2295             exit(0);
2296           else
2297             exit(1);
2298         ]])
2299       ],[
2300         AC_MSG_RESULT([yes])
2301       ],[
2302         AC_MSG_RESULT([no])
2303         AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
2304         ac_cv_func_clock_gettime="no"
2305         LIBS="$curl_cv_save_LIBS"
2306       ])
2307     fi
2308     #
2309     case "$ac_cv_func_clock_gettime" in
2310       yes)
2311         AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
2312           [Define to 1 if you have the clock_gettime function and monotonic timer.])
2313         ;;
2314     esac
2315     #
2316   fi
2317   #
2318 ]) dnl AC_DEFUN
2319
2320
2321 dnl CURL_CHECK_FUNC_SELECT
2322 dnl -------------------------------------------------
2323 dnl Test if the socket select() function is available,
2324 dnl and check its return type and the types of its
2325 dnl arguments. If the function succeeds HAVE_SELECT
2326 dnl will be defined, defining the types of the
2327 dnl arguments in SELECT_TYPE_ARG1, SELECT_TYPE_ARG234
2328 dnl and SELECT_TYPE_ARG5, defining the type of the
2329 dnl function return value in SELECT_TYPE_RETV, and
2330 dnl also defining the type qualifier of fifth argument
2331 dnl in SELECT_QUAL_ARG5.
2332
2333 AC_DEFUN([CURL_CHECK_FUNC_SELECT], [
2334   AC_REQUIRE([CURL_CHECK_STRUCT_TIMEVAL])dnl
2335   AC_CHECK_HEADERS(sys/select.h sys/socket.h)
2336   #
2337   AC_MSG_CHECKING([for select])
2338   AC_LINK_IFELSE([
2339     AC_LANG_PROGRAM([[
2340 #undef inline
2341 #ifdef HAVE_WINDOWS_H
2342 #ifndef WIN32_LEAN_AND_MEAN
2343 #define WIN32_LEAN_AND_MEAN
2344 #endif
2345 #include <windows.h>
2346 #ifdef HAVE_WINSOCK2_H
2347 #include <winsock2.h>
2348 #else
2349 #ifdef HAVE_WINSOCK_H
2350 #include <winsock.h>
2351 #endif
2352 #endif
2353 #endif
2354 #ifdef HAVE_SYS_TYPES_H
2355 #include <sys/types.h>
2356 #endif
2357 #ifdef HAVE_SYS_TIME_H
2358 #include <sys/time.h>
2359 #ifdef TIME_WITH_SYS_TIME
2360 #include <time.h>
2361 #endif
2362 #else
2363 #ifdef HAVE_TIME_H
2364 #include <time.h>
2365 #endif
2366 #endif
2367 #ifndef HAVE_WINDOWS_H
2368 #ifdef HAVE_SYS_SELECT_H
2369 #include <sys/select.h>
2370 #endif
2371 #ifdef HAVE_SYS_SOCKET_H
2372 #include <sys/socket.h>
2373 #endif
2374 #endif
2375     ]],[[
2376       select(0, 0, 0, 0, 0);
2377     ]])
2378   ],[
2379     AC_MSG_RESULT([yes])
2380     curl_cv_select="yes"
2381   ],[
2382     AC_MSG_RESULT([no])
2383     curl_cv_select="no"
2384   ])
2385   #
2386   if test "$curl_cv_select" = "yes"; then
2387     AC_CACHE_CHECK([types of args and return type for select],
2388       [curl_cv_func_select_args], [
2389       curl_cv_func_select_args="unknown"
2390       for sel_retv in 'int' 'ssize_t'; do
2391         for sel_arg1 in 'int' 'ssize_t' 'size_t' 'unsigned long int' 'unsigned int'; do
2392           for sel_arg234 in 'fd_set *' 'int *' 'void *'; do
2393             for sel_arg5 in 'struct timeval *' 'const struct timeval *'; do
2394               if test "$curl_cv_func_select_args" = "unknown"; then
2395                 AC_COMPILE_IFELSE([
2396                   AC_LANG_PROGRAM([[
2397 #undef inline
2398 #ifdef HAVE_WINDOWS_H
2399 #ifndef WIN32_LEAN_AND_MEAN
2400 #define WIN32_LEAN_AND_MEAN
2401 #endif
2402 #include <windows.h>
2403 #ifdef HAVE_WINSOCK2_H
2404 #include <winsock2.h>
2405 #else
2406 #ifdef HAVE_WINSOCK_H
2407 #include <winsock.h>
2408 #endif
2409 #endif
2410 #define SELECTCALLCONV PASCAL
2411 #endif
2412 #ifdef HAVE_SYS_TYPES_H
2413 #include <sys/types.h>
2414 #endif
2415 #ifdef HAVE_SYS_TIME_H
2416 #include <sys/time.h>
2417 #ifdef TIME_WITH_SYS_TIME
2418 #include <time.h>
2419 #endif
2420 #else
2421 #ifdef HAVE_TIME_H
2422 #include <time.h>
2423 #endif
2424 #endif
2425 #ifndef HAVE_WINDOWS_H
2426 #ifdef HAVE_SYS_SELECT_H
2427 #include <sys/select.h>
2428 #endif
2429 #ifdef HAVE_SYS_SOCKET_H
2430 #include <sys/socket.h>
2431 #endif
2432 #define SELECTCALLCONV
2433 #endif
2434 #ifndef HAVE_STRUCT_TIMEVAL
2435                     struct timeval {
2436                       long tv_sec;
2437                       long tv_usec;
2438                     };
2439 #endif
2440                     extern $sel_retv SELECTCALLCONV select($sel_arg1,
2441                                                            $sel_arg234,
2442                                                            $sel_arg234,
2443                                                            $sel_arg234,
2444                                                            $sel_arg5);
2445                   ]],[[
2446                     $sel_arg1   nfds=0;
2447                     $sel_arg234 rfds=0;
2448                     $sel_arg234 wfds=0;
2449                     $sel_arg234 efds=0;
2450                     $sel_retv res = select(nfds, rfds, wfds, efds, 0);
2451                   ]])
2452                 ],[
2453                   curl_cv_func_select_args="$sel_arg1,$sel_arg234,$sel_arg5,$sel_retv"
2454                 ])
2455               fi
2456             done
2457           done
2458         done
2459       done
2460     ]) # AC_CACHE_CHECK
2461     if test "$curl_cv_func_select_args" = "unknown"; then
2462       AC_MSG_WARN([Cannot find proper types to use for select args])
2463       AC_MSG_WARN([HAVE_SELECT will not be defined])
2464     else
2465       select_prev_IFS=$IFS; IFS=','
2466       set dummy `echo "$curl_cv_func_select_args" | sed 's/\*/\*/g'`
2467       IFS=$select_prev_IFS
2468       shift
2469       #
2470       sel_qual_type_arg5=$[3]
2471       #
2472       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG1, $[1],
2473         [Define to the type of arg 1 for select.])
2474       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG234, $[2],
2475         [Define to the type of args 2, 3 and 4 for select.])
2476       AC_DEFINE_UNQUOTED(SELECT_TYPE_RETV, $[4],
2477         [Define to the function return type for select.])
2478       #
2479       prev_sh_opts=$-
2480       #
2481       case $prev_sh_opts in
2482         *f*)
2483           ;;
2484         *)
2485           set -f
2486           ;;
2487       esac
2488       #
2489       case "$sel_qual_type_arg5" in
2490         const*)
2491           sel_qual_arg5=const
2492           sel_type_arg5=`echo $sel_qual_type_arg5 | sed 's/^const //'`
2493         ;;
2494         *)
2495           sel_qual_arg5=
2496           sel_type_arg5=$sel_qual_type_arg5
2497         ;;
2498       esac
2499       #
2500       AC_DEFINE_UNQUOTED(SELECT_QUAL_ARG5, $sel_qual_arg5,
2501         [Define to the type qualifier of arg 5 for select.])
2502       AC_DEFINE_UNQUOTED(SELECT_TYPE_ARG5, $sel_type_arg5,
2503         [Define to the type of arg 5 for select.])
2504       #
2505       case $prev_sh_opts in
2506         *f*)
2507           ;;
2508         *)
2509           set +f
2510           ;;
2511       esac
2512       #
2513       AC_DEFINE_UNQUOTED(HAVE_SELECT, 1,
2514         [Define to 1 if you have the select function.])
2515       ac_cv_func_select="yes"
2516     fi
2517   fi
2518 ]) # AC_DEFUN
2519
2520
2521 dnl ************************************************************
2522 dnl check for "localhost", if it doesn't exist, we can't do the
2523 dnl gethostbyname_r tests!
2524 dnl 
2525
2526 AC_DEFUN([CURL_CHECK_WORKING_RESOLVER],[
2527 AC_MSG_CHECKING([if "localhost" resolves])
2528 AC_TRY_RUN([
2529 #include <string.h>
2530 #include <sys/types.h>
2531 #include <netdb.h>
2532 #ifndef NULL
2533 #define NULL (void *)0
2534 #endif
2535
2536 int
2537 main () {
2538 struct hostent *h;
2539 h = gethostbyname("localhost");
2540 exit (h == NULL ? 1 : 0); }],[
2541       AC_MSG_RESULT(yes)],[
2542       AC_MSG_RESULT(no)
2543       AC_MSG_ERROR([can't figure out gethostbyname_r() since localhost doesn't resolve])
2544
2545       ]
2546 )
2547 ])
2548
2549 dnl ************************************************************
2550 dnl check for working getaddrinfo() that works with AI_NUMERICHOST
2551 dnl
2552 AC_DEFUN([CURL_CHECK_WORKING_GETADDRINFO],[
2553   AC_CACHE_CHECK(for working getaddrinfo, ac_cv_working_getaddrinfo,[
2554   AC_TRY_RUN( [
2555 #include <netdb.h>
2556 #include <sys/types.h>
2557 #include <sys/socket.h>
2558
2559 int main(void)
2560 {
2561     struct addrinfo hints, *ai;
2562     int error;
2563
2564     memset(&hints, 0, sizeof(hints));
2565     hints.ai_flags = AI_NUMERICHOST;
2566     hints.ai_family = AF_UNSPEC;
2567     hints.ai_socktype = SOCK_STREAM;
2568     error = getaddrinfo("127.0.0.1", "8080", &hints, &ai);
2569     if (error) {
2570         return 1;
2571     }
2572     return 0;
2573 }
2574 ],[
2575   ac_cv_working_getaddrinfo="yes"
2576 ],[
2577   ac_cv_working_getaddrinfo="no"
2578 ],[
2579   ac_cv_working_getaddrinfo="yes"
2580 ])])
2581 if test "$ac_cv_working_getaddrinfo" = "yes"; then
2582   AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if getaddrinfo exists and works])
2583   AC_DEFINE(ENABLE_IPV6, 1, [Define if you want to enable IPv6 support])
2584
2585   IPV6_ENABLED=1
2586   AC_SUBST(IPV6_ENABLED)
2587 fi
2588 ])
2589
2590
2591 AC_DEFUN([CURL_CHECK_LOCALTIME_R],
2592 [
2593   dnl check for localtime_r
2594   AC_CHECK_FUNCS(localtime_r,[
2595     AC_MSG_CHECKING(whether localtime_r is declared)
2596     AC_EGREP_CPP(localtime_r,[
2597 #undef _REENTRANT
2598 #include <time.h>],[
2599       AC_MSG_RESULT(yes)],[
2600       AC_MSG_RESULT(no)
2601       AC_MSG_CHECKING(whether localtime_r with -D_REENTRANT is declared)
2602       AC_EGREP_CPP(localtime_r,[
2603 #undef _REENTRANT
2604 #undef _REENTRANT
2605 #define _REENTRANT
2606 #include <time.h>],[
2607         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
2608         AC_MSG_RESULT(yes)],
2609         AC_MSG_RESULT(no))])])
2610 ])
2611
2612 dnl
2613 dnl This function checks for strerror_r(). If it isn't found at first, it
2614 dnl retries with _THREAD_SAFE defined, as that is what AIX seems to require
2615 dnl in order to find this function.
2616 dnl
2617 dnl If the function is found, it will then proceed to check how the function
2618 dnl actually works: glibc-style or POSIX-style.
2619 dnl
2620 dnl glibc:
2621 dnl      char *strerror_r(int errnum, char *buf, size_t n);
2622 dnl  
2623 dnl  What this one does is to return the error string (no surprises there),
2624 dnl  but it doesn't usually copy anything into buf!  The 'buf' and 'n'
2625 dnl  parameters are only meant as an optional working area, in case strerror_r
2626 dnl  needs it.  A quick test on a few systems shows that it's generally not
2627 dnl  touched at all.
2628 dnl
2629 dnl POSIX:
2630 dnl      int strerror_r(int errnum, char *buf, size_t n);
2631 dnl
2632 AC_DEFUN([CURL_CHECK_STRERROR_R],
2633 [
2634   AC_CHECK_FUNCS(strerror_r)
2635
2636   if test "x$ac_cv_func_strerror_r" = "xyes"; then
2637
2638     AC_MSG_CHECKING(whether strerror_r is declared)
2639     AC_EGREP_CPP(strerror_r,[
2640 #undef _REENTRANT
2641 #include <string.h>],[
2642       AC_MSG_RESULT(yes)],[
2643       AC_MSG_RESULT(no)
2644       AC_MSG_CHECKING(whether strerror_r with -D_REENTRANT is declared)
2645       AC_EGREP_CPP(strerror_r,[
2646 #undef _REENTRANT
2647 #define _REENTRANT
2648 #include <string.h>],[
2649         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
2650         AC_MSG_RESULT(yes)],
2651         AC_MSG_RESULT(no)
2652         AC_DEFINE(HAVE_NO_STRERROR_R_DECL, 1, [we have no strerror_r() proto])
2653        ) dnl with _THREAD_SAFE
2654     ]) dnl plain cpp for it
2655
2656     dnl determine if this strerror_r() is glibc or POSIX
2657     AC_MSG_CHECKING([for a glibc strerror_r API])
2658     AC_TRY_RUN([
2659 #include <string.h>
2660 #include <errno.h>
2661 int
2662 main () {
2663   char buffer[1024]; /* big enough to play with */
2664   char *string =
2665     strerror_r(EACCES, buffer, sizeof(buffer));
2666     /* this should've returned a string */
2667     if(!string || !string[0])
2668       return 99;
2669     return 0;
2670 }
2671 ],
2672     GLIBC_STRERROR_R="1"
2673     AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
2674     AC_MSG_RESULT([yes]),
2675     AC_MSG_RESULT([no]),
2676
2677     dnl Use an inferior method of strerror_r detection while cross-compiling
2678     AC_EGREP_CPP(yes, [
2679 #include <features.h>
2680 #ifdef __GLIBC__
2681 yes
2682 #endif
2683 ], 
2684       dnl looks like glibc, so assume a glibc-style strerror_r()
2685       GLIBC_STRERROR_R="1"
2686       AC_DEFINE(HAVE_GLIBC_STRERROR_R, 1, [we have a glibc-style strerror_r()])
2687       AC_MSG_RESULT([yes]),
2688       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
2689     ) dnl while cross-compiling
2690     )
2691
2692     if test -z "$GLIBC_STRERROR_R"; then
2693
2694       AC_MSG_CHECKING([for a POSIX strerror_r API])
2695       AC_TRY_RUN([
2696 #include <string.h>
2697 #include <errno.h>
2698 int
2699 main () {
2700   char buffer[1024]; /* big enough to play with */
2701   int error =
2702     strerror_r(EACCES, buffer, sizeof(buffer));
2703     /* This should've returned zero, and written an error string in the
2704        buffer.*/
2705     if(!buffer[0] || error)
2706       return 99;
2707     return 0;
2708 }
2709 ],
2710       AC_DEFINE(HAVE_POSIX_STRERROR_R, 1, [we have a POSIX-style strerror_r()])
2711       AC_MSG_RESULT([yes]),
2712       AC_MSG_RESULT([no]) ,
2713       dnl cross-compiling!
2714       AC_MSG_NOTICE([cannot determine strerror_r() style: edit lib/config.h manually!])
2715     )
2716
2717     fi dnl if not using glibc API
2718
2719   fi dnl we have a strerror_r
2720
2721 ])
2722
2723 AC_DEFUN([CURL_CHECK_INET_NTOA_R],
2724 [
2725   dnl determine if function definition for inet_ntoa_r exists.
2726   AC_CHECK_FUNCS(inet_ntoa_r,[
2727     AC_MSG_CHECKING(whether inet_ntoa_r is declared)
2728     AC_EGREP_CPP(inet_ntoa_r,[
2729 #undef _REENTRANT
2730 #include <arpa/inet.h>],[
2731       AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
2732       AC_MSG_RESULT(yes)],[
2733       AC_MSG_RESULT(no)
2734       AC_MSG_CHECKING(whether inet_ntoa_r with -D_REENTRANT is declared)
2735       AC_EGREP_CPP(inet_ntoa_r,[
2736 #undef _REENTRANT
2737 #define _REENTRANT
2738 #include <arpa/inet.h>],[
2739         AC_DEFINE(HAVE_INET_NTOA_R_DECL, 1, [inet_ntoa_r() is declared])
2740         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT defined])
2741         AC_MSG_RESULT(yes)],
2742         AC_MSG_RESULT(no))])])
2743 ])
2744
2745
2746 dnl CURL_CHECK_GETHOSTBYADDR_R
2747 dnl -------------------------------------------------
2748 dnl check number of arguments for gethostbyaddr_r, it
2749 dnl might take either 5, 7, or 8 arguments.
2750
2751 AC_DEFUN([CURL_CHECK_GETHOSTBYADDR_R], [
2752   #
2753   AC_MSG_CHECKING([for gethostbyaddr_r])
2754   AC_LINK_IFELSE([
2755     AC_LANG_FUNC_LINK_TRY([gethostbyaddr_r])
2756   ],[
2757     AC_MSG_RESULT([yes])
2758     tmp_cv_gethostbyaddr_r="yes"
2759   ],[
2760     AC_MSG_RESULT([no])
2761     tmp_cv_gethostbyaddr_r="no"
2762   ])
2763   #
2764   if test "$tmp_cv_gethostbyaddr_r" != "yes"; then
2765     AC_MSG_CHECKING([deeper for gethostbyaddr_r])
2766     AC_LINK_IFELSE([
2767       AC_LANG_PROGRAM([[
2768       ]],[[
2769         gethostbyaddr_r();
2770       ]])
2771     ],[
2772       AC_MSG_RESULT([yes])
2773       tmp_cv_gethostbyaddr_r="yes"
2774     ],[
2775       AC_MSG_RESULT([but still no])
2776       tmp_cv_gethostbyaddr_r="no"
2777     ])
2778   fi
2779   #
2780   if test "$tmp_cv_gethostbyaddr_r" = "yes"; then
2781
2782     ac_cv_gethostbyaddr_r_args="unknown"
2783
2784     AC_MSG_CHECKING([if gethostbyaddr_r takes 5 arguments])
2785     AC_COMPILE_IFELSE([
2786       AC_LANG_PROGRAM([[
2787 #undef _REENTRANT
2788 #include <sys/types.h>
2789 #include <netdb.h>
2790       ]],[[
2791         char * address;
2792         int length;
2793         int type;
2794         struct hostent h;
2795         struct hostent_data hdata;
2796         int rc;
2797         rc = gethostbyaddr_r(address, length, type, &h, &hdata);
2798       ]])
2799     ],[
2800       AC_MSG_RESULT([yes])
2801       AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
2802       ac_cv_gethostbyaddr_r_args="5"
2803     ],[
2804       AC_MSG_RESULT([no])
2805     ])
2806
2807     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2808       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 5 arguments])
2809       AC_COMPILE_IFELSE([
2810         AC_LANG_PROGRAM([[
2811 #undef _REENTRANT
2812 #define _REENTRANT
2813 #include <sys/types.h>
2814 #include <netdb.h>
2815         ]],[[
2816           char * address;
2817           int length;
2818           int type;
2819           struct hostent h;
2820           struct hostent_data hdata;
2821           int rc;
2822           rc = gethostbyaddr_r(address, length, type, &h, &hdata);
2823         ]])
2824       ],[
2825         AC_MSG_RESULT([yes])
2826         AC_DEFINE(HAVE_GETHOSTBYADDR_R_5, 1, [gethostbyaddr_r() takes 5 args])
2827         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
2828         ac_cv_gethostbyaddr_r_args="5"
2829       ],[
2830         AC_MSG_RESULT([no])
2831       ])
2832     fi
2833
2834     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2835       AC_MSG_CHECKING([if gethostbyaddr_r takes 7 arguments])
2836       AC_COMPILE_IFELSE([
2837         AC_LANG_PROGRAM([[
2838 #undef _REENTRANT
2839 #include <sys/types.h>
2840 #include <netdb.h>
2841         ]],[[
2842           char * address;
2843           int length;
2844           int type;
2845           struct hostent h;
2846           char buffer[8192];
2847           int h_errnop;
2848           struct hostent * hp;
2849           hp = gethostbyaddr_r(address, length, type, &h,
2850                                buffer, 8192, &h_errnop);
2851         ]])
2852       ],[
2853         AC_MSG_RESULT([yes])
2854         AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args])
2855         ac_cv_gethostbyaddr_r_args="7"
2856       ],[
2857         AC_MSG_RESULT([no])
2858       ])
2859     fi
2860
2861     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2862       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 7 arguments])
2863       AC_COMPILE_IFELSE([
2864         AC_LANG_PROGRAM([[
2865 #undef _REENTRANT
2866 #define _REENTRANT
2867 #include <sys/types.h>
2868 #include <netdb.h>
2869         ]],[[
2870           char * address;
2871           int length;
2872           int type;
2873           struct hostent h;
2874           char buffer[8192];
2875           int h_errnop;
2876           struct hostent * hp;
2877           hp = gethostbyaddr_r(address, length, type, &h,
2878                                buffer, 8192, &h_errnop);
2879         ]])
2880       ],[
2881         AC_MSG_RESULT([yes])
2882         AC_DEFINE(HAVE_GETHOSTBYADDR_R_7, 1, [gethostbyaddr_r() takes 7 args])
2883         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
2884         ac_cv_gethostbyaddr_r_args="7"
2885       ],[
2886         AC_MSG_RESULT([no])
2887       ])
2888     fi
2889
2890     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2891       AC_MSG_CHECKING([if gethostbyaddr_r takes 8 arguments])
2892       AC_COMPILE_IFELSE([
2893         AC_LANG_PROGRAM([[
2894 #undef _REENTRANT
2895 #include <sys/types.h>
2896 #include <netdb.h>
2897         ]],[[
2898           char * address;
2899           int length;
2900           int type;
2901           struct hostent h;
2902           char buffer[8192];
2903           int h_errnop;
2904           struct hostent * hp;
2905           int rc;
2906           rc = gethostbyaddr_r(address, length, type, &h,
2907                                buffer, 8192, &hp, &h_errnop);
2908         ]])
2909       ],[
2910         AC_MSG_RESULT([yes])
2911         AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
2912         ac_cv_gethostbyaddr_r_args="8"
2913       ],[
2914         AC_MSG_RESULT([no])
2915       ])
2916     fi
2917
2918     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2919       AC_MSG_CHECKING([if gethostbyaddr_r with -D_REENTRANT takes 8 arguments])
2920       AC_COMPILE_IFELSE([
2921         AC_LANG_PROGRAM([[
2922 #undef _REENTRANT
2923 #define _REENTRANT
2924 #include <sys/types.h>
2925 #include <netdb.h>
2926         ]],[[
2927           char * address;
2928           int length;
2929           int type;
2930           struct hostent h;
2931           char buffer[8192];
2932           int h_errnop;
2933           struct hostent * hp;
2934           int rc;
2935           rc = gethostbyaddr_r(address, length, type, &h,
2936                                buffer, 8192, &hp, &h_errnop);
2937         ]])
2938       ],[
2939         AC_MSG_RESULT([yes])
2940         AC_DEFINE(HAVE_GETHOSTBYADDR_R_8, 1, [gethostbyaddr_r() takes 8 args])
2941         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
2942         ac_cv_gethostbyaddr_r_args="8"
2943       ],[
2944         AC_MSG_RESULT([no])
2945       ])
2946     fi
2947
2948     if test "$ac_cv_gethostbyaddr_r_args" = "unknown"; then
2949       AC_MSG_WARN([Cannot find out how to use gethostbyaddr_r])
2950       AC_MSG_WARN([HAVE_GETHOSTBYADDR_R will not be defined])
2951       ac_cv_func_gethostbyaddr_r="no"
2952     else
2953       AC_DEFINE_UNQUOTED(HAVE_GETHOSTBYADDR_R, 1,
2954         [Define to 1 if you have the gethostbyaddr_r function.])
2955       ac_cv_func_gethostbyaddr_r="yes"
2956     fi
2957
2958   else
2959     ac_cv_func_gethostbyaddr_r="no"
2960   fi
2961 ])
2962
2963
2964 dnl CURL_CHECK_GETHOSTBYNAME_R
2965 dnl -------------------------------------------------
2966 dnl check number of arguments for gethostbyname_r, it
2967 dnl might take either 3, 5, or 6 arguments.
2968
2969 AC_DEFUN([CURL_CHECK_GETHOSTBYNAME_R], [
2970   #
2971   AC_MSG_CHECKING([for gethostbyname_r])
2972   AC_LINK_IFELSE([
2973     AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
2974   ],[
2975     AC_MSG_RESULT([yes])
2976     tmp_cv_gethostbyname_r="yes"
2977   ],[
2978     AC_MSG_RESULT([no])
2979     tmp_cv_gethostbyname_r="no"
2980   ])
2981   #
2982   if test "$tmp_cv_gethostbyname_r" != "yes"; then
2983     AC_MSG_CHECKING([deeper for gethostbyname_r])
2984     AC_LINK_IFELSE([
2985       AC_LANG_PROGRAM([[
2986       ]],[[
2987         gethostbyname_r();
2988       ]])
2989     ],[
2990       AC_MSG_RESULT([yes])
2991       tmp_cv_gethostbyname_r="yes"
2992     ],[
2993       AC_MSG_RESULT([but still no])
2994       tmp_cv_gethostbyname_r="no"
2995     ])
2996   fi
2997   #
2998   if test "$tmp_cv_gethostbyname_r" = "yes"; then
2999
3000     ac_cv_gethostbyname_r_args="unknown"
3001
3002     AC_MSG_CHECKING([if gethostbyname_r takes 3 arguments])
3003     AC_COMPILE_IFELSE([
3004       AC_LANG_PROGRAM([[
3005 #undef _REENTRANT
3006 #include <string.h>
3007 #include <sys/types.h>
3008 #include <netdb.h>
3009 #undef NULL
3010 #define NULL (void *)0
3011         int
3012         gethostbyname_r(const char *, struct hostent *,
3013                         struct hostent_data *);
3014       ]],[[
3015         struct hostent_data data;
3016         gethostbyname_r(NULL, NULL, NULL);
3017       ]])
3018     ],[
3019       AC_MSG_RESULT([yes])
3020       AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
3021       ac_cv_gethostbyname_r_args="3"
3022     ],[
3023       AC_MSG_RESULT([no])
3024     ])
3025
3026     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3027       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 3 arguments])
3028       AC_COMPILE_IFELSE([
3029         AC_LANG_PROGRAM([[
3030 #undef _REENTRANT
3031 #define _REENTRANT
3032 #include <string.h>
3033 #include <sys/types.h>
3034 #include <netdb.h>
3035 #undef NULL
3036 #define NULL (void *)0
3037           int
3038           gethostbyname_r(const char *, struct hostent *,
3039                           struct hostent_data *);
3040         ]],[[
3041           struct hostent_data data;
3042           gethostbyname_r(NULL, NULL, NULL);
3043         ]])
3044       ],[
3045         AC_MSG_RESULT([yes])
3046         AC_DEFINE(HAVE_GETHOSTBYNAME_R_3, 1, [gethostbyname_r() takes 3 args])
3047         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
3048         ac_cv_gethostbyname_r_args="3"
3049       ],[
3050         AC_MSG_RESULT([no])
3051       ])
3052     fi
3053
3054     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3055       AC_MSG_CHECKING([if gethostbyname_r takes 5 arguments])
3056       AC_COMPILE_IFELSE([
3057         AC_LANG_PROGRAM([[
3058 #undef _REENTRANT
3059 #include <sys/types.h>
3060 #include <netdb.h>
3061 #undef NULL
3062 #define NULL (void *)0
3063           struct hostent *
3064           gethostbyname_r(const char *, struct hostent *,
3065                           char *, int, int *);
3066         ]],[[
3067           gethostbyname_r(NULL, NULL, NULL, 0, NULL);
3068         ]])
3069       ],[
3070         AC_MSG_RESULT([yes])
3071         AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
3072         ac_cv_gethostbyname_r_args="5"
3073       ],[
3074         AC_MSG_RESULT([no])
3075       ])
3076     fi
3077
3078     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3079       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 5 arguments])
3080       AC_COMPILE_IFELSE([
3081         AC_LANG_PROGRAM([[
3082 #undef _REENTRANT
3083 #define _REENTRANT
3084 #include <sys/types.h>
3085 #include <netdb.h>
3086 #undef NULL
3087 #define NULL (void *)0
3088           struct hostent *
3089           gethostbyname_r(const char *, struct hostent *,
3090                           char *, int, int *);
3091         ]],[[
3092           gethostbyname_r(NULL, NULL, NULL, 0, NULL);
3093         ]])
3094       ],[
3095         AC_MSG_RESULT([yes])
3096         AC_DEFINE(HAVE_GETHOSTBYNAME_R_5, 1, [gethostbyname_r() takes 5 args])
3097         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
3098         ac_cv_gethostbyname_r_args="5"
3099       ],[
3100         AC_MSG_RESULT([no])
3101       ])
3102     fi
3103
3104     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3105       AC_MSG_CHECKING([if gethostbyname_r takes 6 arguments])
3106       AC_COMPILE_IFELSE([
3107         AC_LANG_PROGRAM([[
3108 #undef _REENTRANT
3109 #include <sys/types.h>
3110 #include <netdb.h>
3111 #undef NULL
3112 #define NULL (void *)0
3113           int
3114           gethostbyname_r(const char *, struct hostent *,
3115                           char *, size_t, struct hostent **, int *);
3116         ]],[[
3117           gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
3118         ]])
3119       ],[
3120         AC_MSG_RESULT([yes])
3121         AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
3122         ac_cv_gethostbyname_r_args="6"
3123       ],[
3124         AC_MSG_RESULT([no])
3125       ])
3126     fi
3127
3128     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3129       AC_MSG_CHECKING([if gethostbyname_r with -D_REENTRANT takes 6 arguments])
3130       AC_COMPILE_IFELSE([
3131         AC_LANG_PROGRAM([[
3132 #undef _REENTRANT
3133 #define _REENTRANT
3134 #include <sys/types.h>
3135 #include <netdb.h>
3136 #undef NULL
3137 #define NULL (void *)0
3138           int
3139           gethostbyname_r(const char *, struct hostent *,
3140                           char *, size_t, struct hostent **, int *);
3141         ]],[[
3142           gethostbyname_r(NULL, NULL, NULL, 0, NULL, NULL);
3143         ]])
3144       ],[
3145         AC_MSG_RESULT([yes])
3146         AC_DEFINE(HAVE_GETHOSTBYNAME_R_6, 1, [gethostbyname_r() takes 6 args])
3147         AC_DEFINE(NEED_REENTRANT, 1, [need REENTRANT])
3148         ac_cv_gethostbyname_r_args="6"
3149       ],[
3150         AC_MSG_RESULT([no])
3151       ])
3152     fi
3153
3154     if test "$ac_cv_gethostbyname_r_args" = "unknown"; then
3155       AC_MSG_WARN([Cannot find out how to use gethostbyname_r])
3156       AC_MSG_WARN([HAVE_GETHOSTBYNAME_R will not be defined])
3157       ac_cv_func_gethostbyname_r="no"
3158     else
3159       AC_DEFINE_UNQUOTED(HAVE_GETHOSTBYNAME_R, 1,
3160         [Define to 1 if you have the gethostbyname_r function.])
3161       ac_cv_func_gethostbyname_r="yes"
3162     fi
3163
3164   else
3165     ac_cv_func_gethostbyname_r="no"
3166   fi
3167 ])
3168
3169
3170 dnl **********************************************************************
3171 dnl CURL_DETECT_ICC ([ACTION-IF-YES])
3172 dnl
3173 dnl check if this is the Intel ICC compiler, and if so run the ACTION-IF-YES
3174 dnl sets the $ICC variable to "yes" or "no"
3175 dnl **********************************************************************
3176 AC_DEFUN([CURL_DETECT_ICC],
3177 [
3178     ICC="no"
3179     AC_MSG_CHECKING([for icc in use])
3180     if test "$GCC" = "yes"; then
3181        dnl check if this is icc acting as gcc in disguise
3182        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],
3183          dnl action if the text is found, this it has not been replaced by the
3184          dnl cpp
3185          ICC="no",
3186          dnl the text was not found, it was replaced by the cpp
3187          ICC="yes"
3188          AC_MSG_RESULT([yes])
3189          [$1]
3190        )
3191     fi
3192     if test "$ICC" = "no"; then
3193         # this is not ICC
3194         AC_MSG_RESULT([no])
3195     fi
3196 ])
3197
3198 dnl We create a function for detecting which compiler we use and then set as
3199 dnl pendantic compiler options as possible for that particular compiler. The
3200 dnl options are only used for debug-builds.
3201
3202 AC_DEFUN([CURL_CC_DEBUG_OPTS],
3203 [
3204     if test "z$ICC" = "z"; then
3205       CURL_DETECT_ICC
3206     fi
3207
3208     if test "$GCC" = "yes"; then
3209
3210        dnl figure out gcc version!
3211        AC_MSG_CHECKING([gcc version])
3212        gccver=`$CC -dumpversion`
3213        num1=`echo $gccver | cut -d . -f1`
3214        num2=`echo $gccver | cut -d . -f2`
3215        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`
3216        AC_MSG_RESULT($gccver)
3217
3218        if test "$ICC" = "yes"; then
3219          dnl this is icc, not gcc.
3220
3221          dnl ICC warnings we ignore:
3222          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:
3223          dnl   "invalid format string conversion"
3224          dnl * 279 warns on static conditions in while expressions
3225          dnl * 981 warns on "operands are evaluated in unspecified order"
3226          dnl * 1418 "external definition with no prior declaration"
3227          dnl * 1419 warns on "external declaration in primary source file"
3228          dnl   which we know and do on purpose.
3229
3230          WARN="-wd279,269,981,1418,1419"
3231
3232          if test "$gccnum" -gt "600"; then
3233             dnl icc 6.0 and older doesn't have the -Wall flag
3234             WARN="-Wall $WARN"
3235          fi
3236        else dnl $ICC = yes
3237          dnl this is a set of options we believe *ALL* gcc versions support:
3238          WARN="-W -Wall -Wwrite-strings -pedantic -Wpointer-arith -Wnested-externs -Winline -Wmissing-prototypes"
3239
3240          dnl -Wcast-align is a bit too annoying on all gcc versions ;-)
3241
3242          if test "$gccnum" -ge "207"; then
3243            dnl gcc 2.7 or later
3244            WARN="$WARN -Wmissing-declarations"
3245          fi
3246
3247          if test "$gccnum" -gt "295"; then
3248            dnl only if the compiler is newer than 2.95 since we got lots of
3249            dnl "`_POSIX_C_SOURCE' is not defined" in system headers with
3250            dnl gcc 2.95.4 on FreeBSD 4.9!
3251            WARN="$WARN -Wundef -Wno-long-long -Wsign-compare -Wshadow -Wno-multichar"
3252          fi
3253
3254          if test "$gccnum" -ge "296"; then
3255            dnl gcc 2.96 or later
3256            WARN="$WARN -Wfloat-equal"
3257          fi
3258
3259          if test "$gccnum" -gt "296"; then
3260            dnl this option does not exist in 2.96
3261            WARN="$WARN -Wno-format-nonliteral"
3262          fi
3263
3264          dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on
3265          dnl on i686-Linux as it gives us heaps with false positives.
3266          dnl Also, on gcc 4.0.X it is totally unbearable and complains all
3267          dnl over making it unusable for generic purposes. Let's not use it.
3268
3269          if test "$gccnum" -ge "303"; then
3270            dnl gcc 3.3 and later
3271            WARN="$WARN -Wendif-labels -Wstrict-prototypes"
3272          fi
3273
3274          if test "$gccnum" -ge "304"; then
3275            # try these on gcc 3.4
3276            WARN="$WARN -Wdeclaration-after-statement"
3277          fi
3278
3279          for flag in $CPPFLAGS; do
3280            case "$flag" in
3281             -I*)
3282               dnl Include path, provide a -isystem option for the same dir
3283               dnl to prevent warnings in those dirs. The -isystem was not very
3284               dnl reliable on earlier gcc versions.
3285               add=`echo $flag | sed 's/^-I/-isystem /g'`
3286               WARN="$WARN $add"
3287               ;;
3288            esac
3289          done
3290
3291        fi dnl $ICC = no
3292
3293        CFLAGS="$CFLAGS $WARN"
3294
3295       AC_MSG_NOTICE([Added this set of compiler options: $WARN])
3296
3297     else dnl $GCC = yes
3298
3299       AC_MSG_NOTICE([Added no extra compiler options])
3300
3301     fi dnl $GCC = yes
3302
3303     dnl strip off optimizer flags
3304     NEWFLAGS=""
3305     for flag in $CFLAGS; do
3306       case "$flag" in
3307       -O*)
3308         dnl echo "cut off $flag"
3309         ;;
3310       *)
3311         NEWFLAGS="$NEWFLAGS $flag"
3312         ;;
3313       esac
3314     done
3315     CFLAGS=$NEWFLAGS
3316
3317 ]) dnl end of AC_DEFUN()
3318
3319 # This is only a temporary fix. This macro is here to replace the broken one
3320 # delivered by the automake project (including the 1.9.6 release). As soon as
3321 # they ship a working version we SHOULD remove this work-around.
3322
3323 AC_DEFUN([AM_MISSING_HAS_RUN],
3324 [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
3325 test x"${MISSING+set}" = xset || MISSING="\${SHELL} \"$am_aux_dir/missing\""
3326 # Use eval to expand $SHELL
3327 if eval "$MISSING --run true"; then
3328   am_missing_run="$MISSING --run "
3329 else
3330   am_missing_run=
3331   AC_MSG_WARN([`missing' script is too old or missing])
3332 fi
3333 ])
3334
3335
3336 dnl CURL_VERIFY_RUNTIMELIBS
3337 dnl -------------------------------------------------
3338 dnl Verify that the shared libs found so far can be used when running
3339 dnl programs, since otherwise the situation will create odd configure errors
3340 dnl that are misleading people.
3341 dnl
3342 dnl Make sure this test is run BEFORE the first test in the script that
3343 dnl runs anything, which at the time of this writing is the AC_CHECK_SIZEOF
3344 dnl macro. It must also run AFTER all lib-checking macros are complete.
3345
3346 AC_DEFUN([CURL_VERIFY_RUNTIMELIBS], [
3347
3348   dnl this test is of course not sensible if we are cross-compiling!
3349   if test "x$cross_compiling" != xyes; then
3350
3351     dnl just run a program to verify that the libs checked for previous to this
3352     dnl point also is available run-time!
3353     AC_MSG_CHECKING([run-time libs availability])
3354     AC_TRY_RUN([
3355 main()
3356 {
3357   return 0;
3358 }
3359 ],
3360     AC_MSG_RESULT([fine]),
3361     AC_MSG_RESULT([failed])
3362     AC_MSG_ERROR([one or more libs available at link-time are not available run-time. Libs used at link-time: $LIBS])
3363     )
3364
3365     dnl if this test fails, configure has already stopped
3366   fi
3367 ])
3368
3369
3370 dnl CURL_CHECK_VARIADIC_MACROS
3371 dnl -------------------------------------------------
3372 dnl Check compiler support of variadic macros
3373
3374 AC_DEFUN([CURL_CHECK_VARIADIC_MACROS], [
3375   AC_CACHE_CHECK([for compiler support of C99 variadic macro style],
3376     [curl_cv_variadic_macros_c99], [
3377     AC_COMPILE_IFELSE([
3378       AC_LANG_PROGRAM([[
3379 #define c99_vmacro3(first, ...) fun3(first, __VA_ARGS__)
3380 #define c99_vmacro2(first, ...) fun2(first, __VA_ARGS__)
3381         int fun3(int arg1, int arg2, int arg3);
3382         int fun2(int arg1, int arg2);
3383         int fun3(int arg1, int arg2, int arg3)
3384         { return arg1 + arg2 + arg3; }
3385         int fun2(int arg1, int arg2)
3386         { return arg1 + arg2; }
3387       ]],[[
3388         int res3 = c99_vmacro3(1, 2, 3);
3389         int res2 = c99_vmacro2(1, 2);
3390       ]])
3391     ],[
3392       curl_cv_variadic_macros_c99="yes"
3393     ],[
3394       curl_cv_variadic_macros_c99="no"
3395     ])
3396   ])
3397   case "$curl_cv_variadic_macros_c99" in
3398     yes)
3399       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_C99, 1,
3400         [Define to 1 if compiler supports C99 variadic macro style.])
3401       ;;
3402   esac
3403   AC_CACHE_CHECK([for compiler support of old gcc variadic macro style],
3404     [curl_cv_variadic_macros_gcc], [
3405     AC_COMPILE_IFELSE([
3406       AC_LANG_PROGRAM([[
3407 #define gcc_vmacro3(first, args...) fun3(first, args)
3408 #define gcc_vmacro2(first, args...) fun2(first, args)
3409         int fun3(int arg1, int arg2, int arg3);
3410         int fun2(int arg1, int arg2);
3411         int fun3(int arg1, int arg2, int arg3)
3412         { return arg1 + arg2 + arg3; }
3413         int fun2(int arg1, int arg2)
3414         { return arg1 + arg2; }
3415       ]],[[
3416         int res3 = gcc_vmacro3(1, 2, 3);
3417         int res2 = gcc_vmacro2(1, 2);
3418       ]])
3419     ],[
3420       curl_cv_variadic_macros_gcc="yes"
3421     ],[
3422       curl_cv_variadic_macros_gcc="no"
3423     ])
3424   ])
3425   case "$curl_cv_variadic_macros_gcc" in
3426     yes)
3427       AC_DEFINE_UNQUOTED(HAVE_VARIADIC_MACROS_GCC, 1,
3428         [Define to 1 if compiler supports old gcc variadic macro style.])
3429       ;;
3430   esac
3431 ])
3432
3433
3434 dnl CURL_CHECK_CA_BUNDLE
3435 dnl -------------------------------------------------
3436 dnl Check if a default ca-bundle should be used
3437 dnl
3438 dnl regarding the paths this will scan:
3439 dnl /etc/ssl/certs/ca-certificates.crt Debian systems
3440 dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
3441 dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
3442 dnl /etc/ssl/certs/ (ca path) SUSE
3443
3444 AC_DEFUN([CURL_CHECK_CA_BUNDLE], [
3445
3446   AC_MSG_CHECKING([default CA cert bundle/path])
3447
3448   AC_ARG_WITH(ca-bundle,
3449 AC_HELP_STRING([--with-ca-bundle=FILE], [File name to use as CA bundle])
3450 AC_HELP_STRING([--without-ca-bundle], [Don't use a default CA bundle]),
3451   [
3452     want_ca="$withval"
3453     if test "x$want_ca" = "xyes"; then
3454       AC_MSG_ERROR([--with-ca-bundle=FILE requires a path to the CA bundle])
3455     fi
3456   ],
3457   [ want_ca="unset" ])
3458   AC_ARG_WITH(ca-path,
3459 AC_HELP_STRING([--with-ca-path=DIRECTORY], [Directory to use as CA path])
3460 AC_HELP_STRING([--without-ca-path], [Don't use a default CA path]),
3461   [
3462     want_capath="$withval"
3463     if test "x$want_capath" = "xyes"; then
3464       AC_MSG_ERROR([--with-ca-path=DIRECTORY requires a path to the CA path directory])
3465     fi
3466   ],
3467   [ want_capath="unset"])
3468
3469   if test "x$want_ca" != "xno" -a "x$want_ca" != "xunset" -a \
3470           "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
3471     dnl both given
3472     AC_MSG_ERROR([Can't specify both --with-ca-bundle and --with-ca-path.])
3473   elif test "x$want_ca" != "xno" -a "x$want_ca" != "xunset"; then
3474     dnl --with-ca-bundle given
3475     ca="$want_ca"
3476     capath="no"
3477   elif test "x$want_capath" != "xno" -a "x$want_capath" != "xunset"; then
3478     dnl --with-ca-path given
3479     if test "x$OPENSSL_ENABLED" != "x1"; then
3480       AC_MSG_ERROR([--with-ca-path only works with openSSL])
3481     fi
3482     capath="$want_capath"
3483     ca="no"
3484   else
3485     dnl neither of --with-ca-* given
3486     dnl first try autodetecting a CA bundle , then a CA path
3487     dnl both autodetections can be skipped by --without-ca-*
3488     ca="no"
3489     capath="no"
3490     if test "x$want_ca" = "xunset"; then
3491       dnl the path we previously would have installed the curl ca bundle
3492       dnl to, and thus we now check for an already existing cert in that place
3493       dnl in case we find no other
3494       if test "x$prefix" != xNONE; then
3495         cac="${prefix}/share/curl/curl-ca-bundle.crt"
3496       else
3497         cac="$ac_default_prefix/share/curl/curl-ca-bundle.crt"
3498       fi
3499
3500       for a in /etc/ssl/certs/ca-certificates.crt \
3501                /etc/pki/tls/certs/ca-bundle.crt \
3502                /usr/share/ssl/certs/ca-bundle.crt \
3503                "$cac"; do
3504         if test -f "$a"; then
3505           ca="$a"
3506           break
3507         fi
3508       done
3509     fi
3510     if test "x$want_capath" = "xunset" -a "x$ca" = "xno" -a \
3511             "x$OPENSSL_ENABLED" = "x1"; then
3512       for a in /etc/ssl/certs/; do
3513         if test -d "$a" && ls "$a"/[[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]].0 >/dev/null 2>/dev/null; then
3514           capath="$a"
3515           break
3516         fi
3517       done
3518     fi
3519   fi
3520         
3521     
3522
3523   if test "x$ca" != "xno"; then
3524     CURL_CA_BUNDLE='"'$ca'"'
3525     AC_DEFINE_UNQUOTED(CURL_CA_BUNDLE, "$ca", [Location of default ca bundle])
3526     AC_SUBST(CURL_CA_BUNDLE)
3527     AC_MSG_RESULT([$ca])
3528   elif test "x$capath" != "xno"; then
3529     CURL_CA_PATH="\"$capath\""
3530     AC_DEFINE_UNQUOTED(CURL_CA_PATH, "$capath", [Location of default ca path])
3531     AC_MSG_RESULT([$capath (capath)])
3532   else
3533     AC_MSG_RESULT([no])
3534   fi
3535 ])
3536