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