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