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