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