improve detection of strdup() and ftruncate()
[platform/upstream/curl.git] / m4 / curl-functions.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 # File version for 'aclocal' use. Keep it a single number.
25 # serial 1
26
27
28 dnl CURL_INCLUDES_SIGNAL
29 dnl -------------------------------------------------
30 dnl Set up variable with list of headers that must be
31 dnl included when signal.h is to be included.
32
33 AC_DEFUN([CURL_INCLUDES_SIGNAL], [
34 curl_includes_signal="\
35 /* includes start */
36 #ifdef HAVE_SYS_TYPES_H
37 #  include <sys/types.h>
38 #endif
39 #ifdef HAVE_SIGNAL_H
40 #  include <signal.h>
41 #endif
42 /* includes end */"
43   AC_CHECK_HEADERS(
44     sys/types.h signal.h,
45     [], [], [$curl_includes_signal])
46 ])
47
48
49 dnl CURL_INCLUDES_STDLIB
50 dnl -------------------------------------------------
51 dnl Set up variable with list of headers that must be
52 dnl included when stdlib.h is to be included.
53
54 AC_DEFUN([CURL_INCLUDES_STDLIB], [
55 curl_includes_stdlib="\
56 /* includes start */
57 #ifdef HAVE_SYS_TYPES_H
58 #  include <sys/types.h>
59 #endif
60 #ifdef HAVE_STDLIB_H
61 #  include <stdlib.h>
62 #endif
63 /* includes end */"
64   AC_CHECK_HEADERS(
65     sys/types.h stdlib.h,
66     [], [], [$curl_includes_stdlib])
67 ])
68
69
70 dnl CURL_INCLUDES_STRING
71 dnl -------------------------------------------------
72 dnl Set up variable with list of headers that must be
73 dnl included when string.h is to be included.
74
75 AC_DEFUN([CURL_INCLUDES_STRING], [
76 curl_includes_string="\
77 /* includes start */
78 #ifdef HAVE_SYS_TYPES_H
79 #  include <sys/types.h>
80 #endif
81 #ifdef HAVE_STRING_H
82 #  include <string.h>
83 #endif
84 /* includes end */"
85   AC_CHECK_HEADERS(
86     sys/types.h string.h,
87     [], [], [$curl_includes_string])
88 ])
89
90
91 dnl CURL_INCLUDES_TIME
92 dnl -------------------------------------------------
93 dnl Set up variable with list of headers that must be
94 dnl included when time.h is to be included.
95
96 AC_DEFUN([CURL_INCLUDES_TIME], [
97 AC_REQUIRE([AC_HEADER_TIME])dnl
98 curl_includes_time="\
99 /* includes start */
100 #ifdef HAVE_SYS_TYPES_H
101 #  include <sys/types.h>
102 #endif
103 #ifdef HAVE_SYS_TIME_H
104 #  include <sys/time.h>
105 #  ifdef TIME_WITH_SYS_TIME
106 #    include <time.h>
107 #  endif
108 #else
109 #  ifdef HAVE_TIME_H
110 #    include <time.h>
111 #  endif
112 #endif
113 /* includes end */"
114   AC_CHECK_HEADERS(
115     sys/types.h sys/time.h time.h,
116     [], [], [$curl_includes_time])
117 ])
118
119
120 dnl CURL_INCLUDES_UNISTD
121 dnl -------------------------------------------------
122 dnl Set up variable with list of headers that must be
123 dnl included when unistd.h is to be included.
124
125 AC_DEFUN([CURL_INCLUDES_UNISTD], [
126 curl_includes_unistd="\
127 /* includes start */
128 #ifdef HAVE_SYS_TYPES_H
129 #  include <sys/types.h>
130 #endif
131 #ifdef HAVE_UNISTD_H
132 #  include <unistd.h>
133 #endif
134 /* includes end */"
135   AC_CHECK_HEADERS(
136     sys/types.h unistd.h,
137     [], [], [$curl_includes_unistd])
138 ])
139
140
141 dnl CURL_CHECK_FUNC_FTRUNCATE
142 dnl -------------------------------------------------
143 dnl Verify if ftruncate is available, prototyped, and
144 dnl can be compiled. If all of these are true, and
145 dnl usage has not been previously disallowed with
146 dnl shell variable curl_disallow_ftruncate, then
147 dnl HAVE_FTRUNCATE will be defined.
148
149 AC_DEFUN([CURL_CHECK_FUNC_FTRUNCATE], [
150   AC_REQUIRE([CURL_INCLUDES_UNISTD])dnl
151   #
152   tst_links_ftruncate="unknown"
153   tst_proto_ftruncate="unknown"
154   tst_compi_ftruncate="unknown"
155   tst_allow_ftruncate="unknown"
156   #
157   AC_MSG_CHECKING([if ftruncate can be linked])
158   AC_LINK_IFELSE([
159     AC_LANG_FUNC_LINK_TRY([ftruncate])
160   ],[
161     AC_MSG_RESULT([yes])
162     tst_links_ftruncate="yes"
163   ],[
164     AC_MSG_RESULT([no])
165     tst_links_ftruncate="no"
166   ])
167   #
168   if test "$tst_links_ftruncate" = "yes"; then
169     AC_MSG_CHECKING([if ftruncate is prototyped])
170     AC_EGREP_CPP([ftruncate],[
171       $curl_includes_unistd
172     ],[
173       AC_MSG_RESULT([yes])
174       tst_proto_ftruncate="yes"
175     ],[
176       AC_MSG_RESULT([no])
177       tst_proto_ftruncate="no"
178     ])
179   fi
180   #
181   if test "$tst_proto_ftruncate" = "yes"; then
182     AC_MSG_CHECKING([if ftruncate is compilable])
183     AC_COMPILE_IFELSE([
184       AC_LANG_PROGRAM([[
185         $curl_includes_unistd
186       ]],[[
187         if(0 != ftruncate(0, 0))
188           return 1;
189       ]])
190     ],[
191       AC_MSG_RESULT([yes])
192       tst_compi_ftruncate="yes"
193     ],[
194       AC_MSG_RESULT([no])
195       tst_compi_ftruncate="no"
196     ])
197   fi
198   #
199   if test "$tst_compi_ftruncate" = "yes"; then
200     AC_MSG_CHECKING([if ftruncate usage allowed])
201     if test "x$curl_disallow_ftruncate" != "xyes"; then
202       AC_MSG_RESULT([yes])
203       tst_allow_ftruncate="yes"
204     else
205       AC_MSG_RESULT([no])
206       tst_allow_ftruncate="no"
207     fi
208   fi
209   #
210   AC_MSG_CHECKING([if ftruncate might be used])
211   if test "$tst_links_ftruncate" = "yes" &&
212      test "$tst_proto_ftruncate" = "yes" &&
213      test "$tst_compi_ftruncate" = "yes" &&
214      test "$tst_allow_ftruncate" = "yes"; then
215     AC_MSG_RESULT([yes])
216     AC_DEFINE_UNQUOTED(HAVE_FTRUNCATE, 1,
217       [Define to 1 if you have the ftruncate function.])
218     ac_cv_func_ftruncate="yes"
219   else
220     AC_MSG_RESULT([no])
221     ac_cv_func_ftruncate="no"
222   fi
223 ])
224
225
226 dnl CURL_CHECK_FUNC_GMTIME_R
227 dnl -------------------------------------------------
228 dnl Verify if gmtime_r is available, prototyped, can
229 dnl be compiled and seems to work. If all of these are
230 dnl true, and usage has not been previously disallowed
231 dnl with shell variable curl_disallow_gmtime_r, then
232 dnl HAVE_GMTIME_R will be defined.
233
234 AC_DEFUN([CURL_CHECK_FUNC_GMTIME_R], [
235   AC_REQUIRE([CURL_INCLUDES_TIME])dnl
236   #
237   tst_links_gmtime_r="unknown"
238   tst_proto_gmtime_r="unknown"
239   tst_compi_gmtime_r="unknown"
240   tst_works_gmtime_r="unknown"
241   tst_allow_gmtime_r="unknown"
242   #
243   AC_MSG_CHECKING([if gmtime_r can be linked])
244   AC_LINK_IFELSE([
245     AC_LANG_FUNC_LINK_TRY([gmtime_r])
246   ],[
247     AC_MSG_RESULT([yes])
248     tst_links_gmtime_r="yes"
249   ],[
250     AC_MSG_RESULT([no])
251     tst_links_gmtime_r="no"
252   ])
253   #
254   if test "$tst_links_gmtime_r" = "yes"; then
255     AC_MSG_CHECKING([if gmtime_r is prototyped])
256     AC_EGREP_CPP([gmtime_r],[
257       $curl_includes_time
258     ],[
259       AC_MSG_RESULT([yes])
260       tst_proto_gmtime_r="yes"
261     ],[
262       AC_MSG_RESULT([no])
263       tst_proto_gmtime_r="no"
264     ])
265   fi
266   #
267   if test "$tst_proto_gmtime_r" = "yes"; then
268     AC_MSG_CHECKING([if gmtime_r is compilable])
269     AC_COMPILE_IFELSE([
270       AC_LANG_PROGRAM([[
271         $curl_includes_time
272       ]],[[
273         if(0 != gmtime_r(0, 0))
274           return 1;
275       ]])
276     ],[
277       AC_MSG_RESULT([yes])
278       tst_compi_gmtime_r="yes"
279     ],[
280       AC_MSG_RESULT([no])
281       tst_compi_gmtime_r="no"
282     ])
283   fi
284   #
285   dnl only do runtime verification when not cross-compiling
286   if test "x$cross_compiling" != "xyes" &&
287     test "$tst_compi_gmtime_r" = "yes"; then
288     AC_MSG_CHECKING([if gmtime_r seems to work])
289     AC_RUN_IFELSE([
290       AC_LANG_PROGRAM([[
291         $curl_includes_time
292       ]],[[
293         time_t local = 1170352587;
294         struct tm *gmt = 0;
295         struct tm result;
296         gmt = gmtime_r(&local, &result);
297         if(gmt)
298           exit(0);
299         else
300           exit(1);
301       ]])
302     ],[
303       AC_MSG_RESULT([yes])
304       tst_works_gmtime_r="yes"
305     ],[
306       AC_MSG_RESULT([no])
307       tst_works_gmtime_r="no"
308     ])
309   fi
310   #
311   if test "$tst_works_gmtime_r" != "no"; then
312     AC_MSG_CHECKING([if gmtime_r usage allowed])
313     if test "x$curl_disallow_gmtime_r" != "xyes"; then
314       AC_MSG_RESULT([yes])
315       tst_allow_gmtime_r="yes"
316     else
317       AC_MSG_RESULT([no])
318       tst_allow_gmtime_r="no"
319     fi
320   fi
321   #
322   AC_MSG_CHECKING([if gmtime_r might be used])
323   if test "$tst_links_gmtime_r" = "yes" &&
324      test "$tst_proto_gmtime_r" = "yes" &&
325      test "$tst_compi_gmtime_r" = "yes" &&
326      test "$tst_allow_gmtime_r" = "yes" &&
327      test "$tst_works_gmtime_r" != "no"; then
328     AC_MSG_RESULT([yes])
329     AC_DEFINE_UNQUOTED(HAVE_GMTIME_R, 1,
330       [Define to 1 if you have a working gmtime_r function.])
331     ac_cv_func_gmtime_r="yes"
332   else
333     AC_MSG_RESULT([no])
334     ac_cv_func_gmtime_r="no"
335   fi
336 ])
337
338
339 dnl CURL_CHECK_FUNC_SIGACTION
340 dnl -------------------------------------------------
341 dnl Verify if sigaction is available, prototyped, and
342 dnl can be compiled. If all of these are true, and
343 dnl usage has not been previously disallowed with
344 dnl shell variable curl_disallow_sigaction, then
345 dnl HAVE_SIGACTION will be defined.
346
347 AC_DEFUN([CURL_CHECK_FUNC_SIGACTION], [
348   AC_REQUIRE([CURL_INCLUDES_SIGNAL])dnl
349   #
350   tst_links_sigaction="unknown"
351   tst_proto_sigaction="unknown"
352   tst_compi_sigaction="unknown"
353   tst_allow_sigaction="unknown"
354   #
355   AC_MSG_CHECKING([if sigaction can be linked])
356   AC_LINK_IFELSE([
357     AC_LANG_FUNC_LINK_TRY([sigaction])
358   ],[
359     AC_MSG_RESULT([yes])
360     tst_links_sigaction="yes"
361   ],[
362     AC_MSG_RESULT([no])
363     tst_links_sigaction="no"
364   ])
365   #
366   if test "$tst_links_sigaction" = "yes"; then
367     AC_MSG_CHECKING([if sigaction is prototyped])
368     AC_EGREP_CPP([sigaction],[
369       $curl_includes_signal
370     ],[
371       AC_MSG_RESULT([yes])
372       tst_proto_sigaction="yes"
373     ],[
374       AC_MSG_RESULT([no])
375       tst_proto_sigaction="no"
376     ])
377   fi
378   #
379   if test "$tst_proto_sigaction" = "yes"; then
380     AC_MSG_CHECKING([if sigaction is compilable])
381     AC_COMPILE_IFELSE([
382       AC_LANG_PROGRAM([[
383         $curl_includes_signal
384       ]],[[
385         if(0 != sigaction(0, 0, 0))
386           return 1;
387       ]])
388     ],[
389       AC_MSG_RESULT([yes])
390       tst_compi_sigaction="yes"
391     ],[
392       AC_MSG_RESULT([no])
393       tst_compi_sigaction="no"
394     ])
395   fi
396   #
397   if test "$tst_compi_sigaction" = "yes"; then
398     AC_MSG_CHECKING([if sigaction usage allowed])
399     if test "x$curl_disallow_sigaction" != "xyes"; then
400       AC_MSG_RESULT([yes])
401       tst_allow_sigaction="yes"
402     else
403       AC_MSG_RESULT([no])
404       tst_allow_sigaction="no"
405     fi
406   fi
407   #
408   AC_MSG_CHECKING([if sigaction might be used])
409   if test "$tst_links_sigaction" = "yes" &&
410      test "$tst_proto_sigaction" = "yes" &&
411      test "$tst_compi_sigaction" = "yes" &&
412      test "$tst_allow_sigaction" = "yes"; then
413     AC_MSG_RESULT([yes])
414     AC_DEFINE_UNQUOTED(HAVE_SIGACTION, 1,
415       [Define to 1 if you have the sigaction function.])
416     ac_cv_func_sigaction="yes"
417   else
418     AC_MSG_RESULT([no])
419     ac_cv_func_sigaction="no"
420   fi
421 ])
422
423
424 dnl CURL_CHECK_FUNC_STRDUP
425 dnl -------------------------------------------------
426 dnl Verify if strdup is available, prototyped, and
427 dnl can be compiled. If all of these are true, and
428 dnl usage has not been previously disallowed with
429 dnl shell variable curl_disallow_strdup, then
430 dnl HAVE_STRDUP will be defined.
431
432 AC_DEFUN([CURL_CHECK_FUNC_STRDUP], [
433   AC_REQUIRE([CURL_INCLUDES_STRING])dnl
434   #
435   tst_links_strdup="unknown"
436   tst_proto_strdup="unknown"
437   tst_compi_strdup="unknown"
438   tst_allow_strdup="unknown"
439   #
440   AC_MSG_CHECKING([if strdup can be linked])
441   AC_LINK_IFELSE([
442     AC_LANG_FUNC_LINK_TRY([strdup])
443   ],[
444     AC_MSG_RESULT([yes])
445     tst_links_strdup="yes"
446   ],[
447     AC_MSG_RESULT([no])
448     tst_links_strdup="no"
449   ])
450   #
451   if test "$tst_links_strdup" = "yes"; then
452     AC_MSG_CHECKING([if strdup is prototyped])
453     AC_EGREP_CPP([strdup],[
454       $curl_includes_string
455     ],[
456       AC_MSG_RESULT([yes])
457       tst_proto_strdup="yes"
458     ],[
459       AC_MSG_RESULT([no])
460       tst_proto_strdup="no"
461     ])
462   fi
463   #
464   if test "$tst_proto_strdup" = "yes"; then
465     AC_MSG_CHECKING([if strdup is compilable])
466     AC_COMPILE_IFELSE([
467       AC_LANG_PROGRAM([[
468         $curl_includes_string
469       ]],[[
470         if(0 != strdup(0))
471           return 1;
472       ]])
473     ],[
474       AC_MSG_RESULT([yes])
475       tst_compi_strdup="yes"
476     ],[
477       AC_MSG_RESULT([no])
478       tst_compi_strdup="no"
479     ])
480   fi
481   #
482   if test "$tst_compi_strdup" = "yes"; then
483     AC_MSG_CHECKING([if strdup usage allowed])
484     if test "x$curl_disallow_strdup" != "xyes"; then
485       AC_MSG_RESULT([yes])
486       tst_allow_strdup="yes"
487     else
488       AC_MSG_RESULT([no])
489       tst_allow_strdup="no"
490     fi
491   fi
492   #
493   AC_MSG_CHECKING([if strdup might be used])
494   if test "$tst_links_strdup" = "yes" &&
495      test "$tst_proto_strdup" = "yes" &&
496      test "$tst_compi_strdup" = "yes" &&
497      test "$tst_allow_strdup" = "yes"; then
498     AC_MSG_RESULT([yes])
499     AC_DEFINE_UNQUOTED(HAVE_STRDUP, 1,
500       [Define to 1 if you have the strdup function.])
501     ac_cv_func_strdup="yes"
502   else
503     AC_MSG_RESULT([no])
504     ac_cv_func_strdup="no"
505   fi
506 ])
507
508
509 dnl CURL_CHECK_FUNC_STRTOK_R
510 dnl -------------------------------------------------
511 dnl Verify if strtok_r is available, prototyped, and
512 dnl can be compiled. If all of these are true, and
513 dnl usage has not been previously disallowed with
514 dnl shell variable curl_disallow_strtok_r, then
515 dnl HAVE_STRTOK_R will be defined.
516
517 AC_DEFUN([CURL_CHECK_FUNC_STRTOK_R], [
518   AC_REQUIRE([CURL_INCLUDES_STRING])dnl
519   #
520   tst_links_strtok_r="unknown"
521   tst_proto_strtok_r="unknown"
522   tst_compi_strtok_r="unknown"
523   tst_allow_strtok_r="unknown"
524   #
525   AC_MSG_CHECKING([if strtok_r can be linked])
526   AC_LINK_IFELSE([
527     AC_LANG_FUNC_LINK_TRY([strtok_r])
528   ],[
529     AC_MSG_RESULT([yes])
530     tst_links_strtok_r="yes"
531   ],[
532     AC_MSG_RESULT([no])
533     tst_links_strtok_r="no"
534   ])
535   #
536   if test "$tst_links_strtok_r" = "yes"; then
537     AC_MSG_CHECKING([if strtok_r is prototyped])
538     AC_EGREP_CPP([strtok_r],[
539       $curl_includes_string
540     ],[
541       AC_MSG_RESULT([yes])
542       tst_proto_strtok_r="yes"
543     ],[
544       AC_MSG_RESULT([no])
545       tst_proto_strtok_r="no"
546     ])
547   fi
548   #
549   if test "$tst_proto_strtok_r" = "yes"; then
550     AC_MSG_CHECKING([if strtok_r is compilable])
551     AC_COMPILE_IFELSE([
552       AC_LANG_PROGRAM([[
553         $curl_includes_string
554       ]],[[
555         if(0 != strtok_r(0, 0, 0))
556           return 1;
557       ]])
558     ],[
559       AC_MSG_RESULT([yes])
560       tst_compi_strtok_r="yes"
561     ],[
562       AC_MSG_RESULT([no])
563       tst_compi_strtok_r="no"
564     ])
565   fi
566   #
567   if test "$tst_compi_strtok_r" = "yes"; then
568     AC_MSG_CHECKING([if strtok_r usage allowed])
569     if test "x$curl_disallow_strtok_r" != "xyes"; then
570       AC_MSG_RESULT([yes])
571       tst_allow_strtok_r="yes"
572     else
573       AC_MSG_RESULT([no])
574       tst_allow_strtok_r="no"
575     fi
576   fi
577   #
578   AC_MSG_CHECKING([if strtok_r might be used])
579   if test "$tst_links_strtok_r" = "yes" &&
580      test "$tst_proto_strtok_r" = "yes" &&
581      test "$tst_compi_strtok_r" = "yes" &&
582      test "$tst_allow_strtok_r" = "yes"; then
583     AC_MSG_RESULT([yes])
584     AC_DEFINE_UNQUOTED(HAVE_STRTOK_R, 1,
585       [Define to 1 if you have the strtok_r function.])
586     ac_cv_func_strtok_r="yes"
587   else
588     AC_MSG_RESULT([no])
589     ac_cv_func_strtok_r="no"
590   fi
591 ])
592
593
594 dnl CURL_CHECK_FUNC_STRTOLL
595 dnl -------------------------------------------------
596 dnl Verify if strtoll is available, prototyped, and
597 dnl can be compiled. If all of these are true, and
598 dnl usage has not been previously disallowed with
599 dnl shell variable curl_disallow_strtoll, then
600 dnl HAVE_STRTOLL will be defined.
601
602 AC_DEFUN([CURL_CHECK_FUNC_STRTOLL], [
603   AC_REQUIRE([CURL_INCLUDES_STDLIB])dnl
604   #
605   tst_links_strtoll="unknown"
606   tst_proto_strtoll="unknown"
607   tst_compi_strtoll="unknown"
608   tst_allow_strtoll="unknown"
609   #
610   AC_MSG_CHECKING([if strtoll can be linked])
611   AC_LINK_IFELSE([
612     AC_LANG_FUNC_LINK_TRY([strtoll])
613   ],[
614     AC_MSG_RESULT([yes])
615     tst_links_strtoll="yes"
616   ],[
617     AC_MSG_RESULT([no])
618     tst_links_strtoll="no"
619   ])
620   #
621   if test "$tst_links_strtoll" = "yes"; then
622     AC_MSG_CHECKING([if strtoll is prototyped])
623     AC_EGREP_CPP([strtoll],[
624       $curl_includes_stdlib
625     ],[
626       AC_MSG_RESULT([yes])
627       tst_proto_strtoll="yes"
628     ],[
629       AC_MSG_RESULT([no])
630       tst_proto_strtoll="no"
631     ])
632   fi
633   #
634   if test "$tst_proto_strtoll" = "yes"; then
635     AC_MSG_CHECKING([if strtoll is compilable])
636     AC_COMPILE_IFELSE([
637       AC_LANG_PROGRAM([[
638         $curl_includes_stdlib
639       ]],[[
640         if(0 != strtoll(0, 0, 0))
641           return 1;
642       ]])
643     ],[
644       AC_MSG_RESULT([yes])
645       tst_compi_strtoll="yes"
646     ],[
647       AC_MSG_RESULT([no])
648       tst_compi_strtoll="no"
649     ])
650   fi
651   #
652   if test "$tst_compi_strtoll" = "yes"; then
653     AC_MSG_CHECKING([if strtoll usage allowed])
654     if test "x$curl_disallow_strtoll" != "xyes"; then
655       AC_MSG_RESULT([yes])
656       tst_allow_strtoll="yes"
657     else
658       AC_MSG_RESULT([no])
659       tst_allow_strtoll="no"
660     fi
661   fi
662   #
663   AC_MSG_CHECKING([if strtoll might be used])
664   if test "$tst_links_strtoll" = "yes" &&
665      test "$tst_proto_strtoll" = "yes" &&
666      test "$tst_compi_strtoll" = "yes" &&
667      test "$tst_allow_strtoll" = "yes"; then
668     AC_MSG_RESULT([yes])
669     AC_DEFINE_UNQUOTED(HAVE_STRTOLL, 1,
670       [Define to 1 if you have the strtoll function.])
671     ac_cv_func_strtoll="yes"
672   else
673     AC_MSG_RESULT([no])
674     ac_cv_func_strtoll="no"
675   fi
676 ])
677
678