smtp: use the upload buffer size for scratch buffer malloc
[platform/upstream/curl.git] / m4 / curl-reentrant.m4
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2009, 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 https://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 #***************************************************************************
22
23 # File version for 'aclocal' use. Keep it a single number.
24 # serial 10
25
26 dnl Note 1
27 dnl ------
28 dnl None of the CURL_CHECK_NEED_REENTRANT_* macros shall use HAVE_FOO_H to
29 dnl conditionally include header files. These macros are used early in the
30 dnl configure process much before header file availability is known.
31
32
33 dnl CURL_CHECK_NEED_REENTRANT_ERRNO
34 dnl -------------------------------------------------
35 dnl Checks if the preprocessor _REENTRANT definition
36 dnl makes errno available as a preprocessor macro.
37
38 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_ERRNO], [
39   AC_COMPILE_IFELSE([
40     AC_LANG_PROGRAM([[
41 #include <errno.h>
42     ]],[[
43       if(0 != errno)
44         return 1;
45     ]])
46   ],[
47     tmp_errno="yes"
48   ],[
49     tmp_errno="no"
50   ])
51   if test "$tmp_errno" = "yes"; then
52     AC_COMPILE_IFELSE([
53       AC_LANG_PROGRAM([[
54 #include <errno.h>
55       ]],[[
56 #ifdef errno
57         int dummy=1;
58 #else
59         force compilation error
60 #endif
61       ]])
62     ],[
63       tmp_errno="errno_macro_defined"
64     ],[
65       AC_COMPILE_IFELSE([
66         AC_LANG_PROGRAM([[
67 #define _REENTRANT
68 #include <errno.h>
69         ]],[[
70 #ifdef errno
71           int dummy=1;
72 #else
73           force compilation error
74 #endif
75         ]])
76       ],[
77         tmp_errno="errno_macro_needs_reentrant"
78         tmp_need_reentrant="yes"
79       ])
80     ])
81   fi
82 ])
83
84
85 dnl CURL_CHECK_NEED_REENTRANT_GMTIME_R
86 dnl -------------------------------------------------
87 dnl Checks if the preprocessor _REENTRANT definition
88 dnl makes function gmtime_r compiler visible.
89
90 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GMTIME_R], [
91   AC_LINK_IFELSE([
92     AC_LANG_FUNC_LINK_TRY([gmtime_r])
93   ],[
94     tmp_gmtime_r="yes"
95   ],[
96     tmp_gmtime_r="no"
97   ])
98   if test "$tmp_gmtime_r" = "yes"; then
99     AC_EGREP_CPP([gmtime_r],[
100 #include <sys/types.h>
101 #include <time.h>
102     ],[
103       tmp_gmtime_r="proto_declared"
104     ],[
105       AC_EGREP_CPP([gmtime_r],[
106 #define _REENTRANT
107 #include <sys/types.h>
108 #include <time.h>
109       ],[
110         tmp_gmtime_r="proto_needs_reentrant"
111         tmp_need_reentrant="yes"
112       ])
113     ])
114   fi
115 ])
116
117
118 dnl CURL_CHECK_NEED_REENTRANT_LOCALTIME_R
119 dnl -------------------------------------------------
120 dnl Checks if the preprocessor _REENTRANT definition
121 dnl makes function localtime_r compiler visible.
122
123 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_LOCALTIME_R], [
124   AC_LINK_IFELSE([
125     AC_LANG_FUNC_LINK_TRY([localtime_r])
126   ],[
127     tmp_localtime_r="yes"
128   ],[
129     tmp_localtime_r="no"
130   ])
131   if test "$tmp_localtime_r" = "yes"; then
132     AC_EGREP_CPP([localtime_r],[
133 #include <sys/types.h>
134 #include <time.h>
135     ],[
136       tmp_localtime_r="proto_declared"
137     ],[
138       AC_EGREP_CPP([localtime_r],[
139 #define _REENTRANT
140 #include <sys/types.h>
141 #include <time.h>
142       ],[
143         tmp_localtime_r="proto_needs_reentrant"
144         tmp_need_reentrant="yes"
145       ])
146     ])
147   fi
148 ])
149
150
151 dnl CURL_CHECK_NEED_REENTRANT_STRERROR_R
152 dnl -------------------------------------------------
153 dnl Checks if the preprocessor _REENTRANT definition
154 dnl makes function strerror_r compiler visible.
155
156 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRERROR_R], [
157   AC_LINK_IFELSE([
158     AC_LANG_FUNC_LINK_TRY([strerror_r])
159   ],[
160     tmp_strerror_r="yes"
161   ],[
162     tmp_strerror_r="no"
163   ])
164   if test "$tmp_strerror_r" = "yes"; then
165     AC_EGREP_CPP([strerror_r],[
166 #include <sys/types.h>
167 #include <string.h>
168     ],[
169       tmp_strerror_r="proto_declared"
170     ],[
171       AC_EGREP_CPP([strerror_r],[
172 #define _REENTRANT
173 #include <sys/types.h>
174 #include <string.h>
175       ],[
176         tmp_strerror_r="proto_needs_reentrant"
177         tmp_need_reentrant="yes"
178       ])
179     ])
180   fi
181 ])
182
183
184 dnl CURL_CHECK_NEED_REENTRANT_STRTOK_R
185 dnl -------------------------------------------------
186 dnl Checks if the preprocessor _REENTRANT definition
187 dnl makes function strtok_r compiler visible.
188
189 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_STRTOK_R], [
190   AC_LINK_IFELSE([
191     AC_LANG_FUNC_LINK_TRY([strtok_r])
192   ],[
193     tmp_strtok_r="yes"
194   ],[
195     tmp_strtok_r="no"
196   ])
197   if test "$tmp_strtok_r" = "yes"; then
198     AC_EGREP_CPP([strtok_r],[
199 #include <sys/types.h>
200 #include <string.h>
201     ],[
202       tmp_strtok_r="proto_declared"
203     ],[
204       AC_EGREP_CPP([strtok_r],[
205 #define _REENTRANT
206 #include <sys/types.h>
207 #include <string.h>
208       ],[
209         tmp_strtok_r="proto_needs_reentrant"
210         tmp_need_reentrant="yes"
211       ])
212     ])
213   fi
214 ])
215
216
217 dnl CURL_CHECK_NEED_REENTRANT_INET_NTOA_R
218 dnl -------------------------------------------------
219 dnl Checks if the preprocessor _REENTRANT definition
220 dnl makes function inet_ntoa_r compiler visible.
221
222 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_INET_NTOA_R], [
223   AC_LINK_IFELSE([
224     AC_LANG_FUNC_LINK_TRY([inet_ntoa_r])
225   ],[
226     tmp_inet_ntoa_r="yes"
227   ],[
228     tmp_inet_ntoa_r="no"
229   ])
230   if test "$tmp_inet_ntoa_r" = "yes"; then
231     AC_EGREP_CPP([inet_ntoa_r],[
232 #include <sys/types.h>
233 #include <sys/socket.h>
234 #include <netinet/in.h>
235 #include <arpa/inet.h>
236     ],[
237       tmp_inet_ntoa_r="proto_declared"
238     ],[
239       AC_EGREP_CPP([inet_ntoa_r],[
240 #define _REENTRANT
241 #include <sys/types.h>
242 #include <sys/socket.h>
243 #include <netinet/in.h>
244 #include <arpa/inet.h>
245       ],[
246         tmp_inet_ntoa_r="proto_needs_reentrant"
247         tmp_need_reentrant="yes"
248       ])
249     ])
250   fi
251 ])
252
253
254 dnl CURL_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
255 dnl -------------------------------------------------
256 dnl Checks if the preprocessor _REENTRANT definition
257 dnl makes function gethostbyaddr_r compiler visible.
258
259 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R], [
260   AC_LINK_IFELSE([
261     AC_LANG_FUNC_LINK_TRY([gethostbyaddr_r])
262   ],[
263     tmp_gethostbyaddr_r="yes"
264   ],[
265     tmp_gethostbyaddr_r="no"
266   ])
267   if test "$tmp_gethostbyaddr_r" = "yes"; then
268     AC_EGREP_CPP([gethostbyaddr_r],[
269 #include <sys/types.h>
270 #include <netdb.h>
271     ],[
272       tmp_gethostbyaddr_r="proto_declared"
273     ],[
274       AC_EGREP_CPP([gethostbyaddr_r],[
275 #define _REENTRANT
276 #include <sys/types.h>
277 #include <netdb.h>
278       ],[
279         tmp_gethostbyaddr_r="proto_needs_reentrant"
280         tmp_need_reentrant="yes"
281       ])
282     ])
283   fi
284 ])
285
286
287 dnl CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
288 dnl -------------------------------------------------
289 dnl Checks if the preprocessor _REENTRANT definition
290 dnl makes function gethostbyname_r compiler visible.
291
292 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R], [
293   AC_LINK_IFELSE([
294     AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
295   ],[
296     tmp_gethostbyname_r="yes"
297   ],[
298     tmp_gethostbyname_r="no"
299   ])
300   if test "$tmp_gethostbyname_r" = "yes"; then
301     AC_EGREP_CPP([gethostbyname_r],[
302 #include <sys/types.h>
303 #include <netdb.h>
304     ],[
305       tmp_gethostbyname_r="proto_declared"
306     ],[
307       AC_EGREP_CPP([gethostbyname_r],[
308 #define _REENTRANT
309 #include <sys/types.h>
310 #include <netdb.h>
311       ],[
312         tmp_gethostbyname_r="proto_needs_reentrant"
313         tmp_need_reentrant="yes"
314       ])
315     ])
316   fi
317 ])
318
319
320 dnl CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
321 dnl -------------------------------------------------
322 dnl Checks if the preprocessor _REENTRANT definition
323 dnl makes function getprotobyname_r compiler visible.
324
325 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R], [
326   AC_LINK_IFELSE([
327     AC_LANG_FUNC_LINK_TRY([getprotobyname_r])
328   ],[
329     tmp_getprotobyname_r="yes"
330   ],[
331     tmp_getprotobyname_r="no"
332   ])
333   if test "$tmp_getprotobyname_r" = "yes"; then
334     AC_EGREP_CPP([getprotobyname_r],[
335 #include <sys/types.h>
336 #include <netdb.h>
337     ],[
338       tmp_getprotobyname_r="proto_declared"
339     ],[
340       AC_EGREP_CPP([getprotobyname_r],[
341 #define _REENTRANT
342 #include <sys/types.h>
343 #include <netdb.h>
344       ],[
345         tmp_getprotobyname_r="proto_needs_reentrant"
346         tmp_need_reentrant="yes"
347       ])
348     ])
349   fi
350 ])
351
352
353 dnl CURL_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
354 dnl -------------------------------------------------
355 dnl Checks if the preprocessor _REENTRANT definition
356 dnl makes function getservbyport_r compiler visible.
357
358 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_GETSERVBYPORT_R], [
359   AC_LINK_IFELSE([
360     AC_LANG_FUNC_LINK_TRY([getservbyport_r])
361   ],[
362     tmp_getservbyport_r="yes"
363   ],[
364     tmp_getservbyport_r="no"
365   ])
366   if test "$tmp_getservbyport_r" = "yes"; then
367     AC_EGREP_CPP([getservbyport_r],[
368 #include <sys/types.h>
369 #include <netdb.h>
370     ],[
371       tmp_getservbyport_r="proto_declared"
372     ],[
373       AC_EGREP_CPP([getservbyport_r],[
374 #define _REENTRANT
375 #include <sys/types.h>
376 #include <netdb.h>
377       ],[
378         tmp_getservbyport_r="proto_needs_reentrant"
379         tmp_need_reentrant="yes"
380       ])
381     ])
382   fi
383 ])
384
385
386 dnl CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R
387 dnl -------------------------------------------------
388 dnl Checks if the preprocessor _REENTRANT definition
389 dnl makes several _r functions compiler visible.
390 dnl Internal macro for CURL_CONFIGURE_REENTRANT.
391
392 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R], [
393   if test "$tmp_need_reentrant" = "no"; then
394     CURL_CHECK_NEED_REENTRANT_GMTIME_R
395   fi
396   if test "$tmp_need_reentrant" = "no"; then
397     CURL_CHECK_NEED_REENTRANT_LOCALTIME_R
398   fi
399   if test "$tmp_need_reentrant" = "no"; then
400     CURL_CHECK_NEED_REENTRANT_STRERROR_R
401   fi
402   if test "$tmp_need_reentrant" = "no"; then
403     CURL_CHECK_NEED_REENTRANT_STRTOK_R
404   fi
405   if test "$tmp_need_reentrant" = "no"; then
406     CURL_CHECK_NEED_REENTRANT_INET_NTOA_R
407   fi
408   if test "$tmp_need_reentrant" = "no"; then
409     CURL_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
410   fi
411   if test "$tmp_need_reentrant" = "no"; then
412     CURL_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
413   fi
414   if test "$tmp_need_reentrant" = "no"; then
415     CURL_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
416   fi
417   if test "$tmp_need_reentrant" = "no"; then
418     CURL_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
419   fi
420 ])
421
422
423 dnl CURL_CHECK_NEED_REENTRANT_SYSTEM
424 dnl -------------------------------------------------
425 dnl Checks if the preprocessor _REENTRANT definition
426 dnl must be unconditionally done for this platform.
427 dnl Internal macro for CURL_CONFIGURE_REENTRANT.
428
429 AC_DEFUN([CURL_CHECK_NEED_REENTRANT_SYSTEM], [
430   case $host_os in
431     solaris*)
432       tmp_need_reentrant="yes"
433       ;;
434     *)
435       tmp_need_reentrant="no"
436       ;;
437   esac
438 ])
439
440
441 dnl CURL_CHECK_NEED_THREAD_SAFE_SYSTEM
442 dnl -------------------------------------------------
443 dnl Checks if the preprocessor _THREAD_SAFE definition
444 dnl must be unconditionally done for this platform.
445 dnl Internal macro for CURL_CONFIGURE_THREAD_SAFE.
446
447 AC_DEFUN([CURL_CHECK_NEED_THREAD_SAFE_SYSTEM], [
448   case $host_os in
449     aix[[123]].* | aix4.[[012]].*)
450       dnl aix 4.2 and older
451       tmp_need_thread_safe="no"
452       ;;
453     aix*)
454       dnl AIX 4.3 and newer
455       tmp_need_thread_safe="yes"
456       ;;
457     *)
458       tmp_need_thread_safe="no"
459       ;;
460   esac
461 ])
462
463
464 dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
465 dnl -------------------------------------------------
466 dnl This macro ensures that configuration tests done
467 dnl after this will execute with preprocessor symbol
468 dnl _REENTRANT defined. This macro also ensures that
469 dnl the generated config file defines NEED_REENTRANT
470 dnl and that in turn curl_setup.h will define _REENTRANT.
471 dnl Internal macro for CURL_CONFIGURE_REENTRANT.
472
473 AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [
474 AC_DEFINE(NEED_REENTRANT, 1,
475   [Define to 1 if _REENTRANT preprocessor symbol must be defined.])
476 cat >>confdefs.h <<_EOF
477 #ifndef _REENTRANT
478 #  define _REENTRANT
479 #endif
480 _EOF
481 ])
482
483
484 dnl CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE
485 dnl -------------------------------------------------
486 dnl This macro ensures that configuration tests done
487 dnl after this will execute with preprocessor symbol
488 dnl _THREAD_SAFE defined. This macro also ensures that
489 dnl the generated config file defines NEED_THREAD_SAFE
490 dnl and that in turn curl_setup.h will define _THREAD_SAFE.
491 dnl Internal macro for CURL_CONFIGURE_THREAD_SAFE.
492
493 AC_DEFUN([CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE], [
494 AC_DEFINE(NEED_THREAD_SAFE, 1,
495   [Define to 1 if _THREAD_SAFE preprocessor symbol must be defined.])
496 cat >>confdefs.h <<_EOF
497 #ifndef _THREAD_SAFE
498 #  define _THREAD_SAFE
499 #endif
500 _EOF
501 ])
502
503
504 dnl CURL_CONFIGURE_REENTRANT
505 dnl -------------------------------------------------
506 dnl This first checks if the preprocessor _REENTRANT
507 dnl symbol is already defined. If it isn't currently
508 dnl defined a set of checks are performed to verify
509 dnl if its definition is required to make visible to
510 dnl the compiler a set of *_r functions. Finally, if
511 dnl _REENTRANT is already defined or needed it takes
512 dnl care of making adjustments necessary to ensure
513 dnl that it is defined equally for further configure
514 dnl tests and generated config file.
515
516 AC_DEFUN([CURL_CONFIGURE_REENTRANT], [
517   AC_PREREQ([2.50])dnl
518   #
519   AC_MSG_CHECKING([if _REENTRANT is already defined])
520   AC_COMPILE_IFELSE([
521     AC_LANG_PROGRAM([[
522     ]],[[
523 #ifdef _REENTRANT
524       int dummy=1;
525 #else
526       force compilation error
527 #endif
528     ]])
529   ],[
530     AC_MSG_RESULT([yes])
531     tmp_reentrant_initially_defined="yes"
532   ],[
533     AC_MSG_RESULT([no])
534     tmp_reentrant_initially_defined="no"
535   ])
536   #
537   if test "$tmp_reentrant_initially_defined" = "no"; then
538     AC_MSG_CHECKING([if _REENTRANT is actually needed])
539     CURL_CHECK_NEED_REENTRANT_SYSTEM
540     if test "$tmp_need_reentrant" = "no"; then
541       CURL_CHECK_NEED_REENTRANT_ERRNO
542     fi
543     if test "$tmp_need_reentrant" = "no"; then
544       CURL_CHECK_NEED_REENTRANT_FUNCTIONS_R
545     fi
546     if test "$tmp_need_reentrant" = "yes"; then
547       AC_MSG_RESULT([yes])
548     else
549       AC_MSG_RESULT([no])
550     fi
551   fi
552   #
553   AC_MSG_CHECKING([if _REENTRANT is onwards defined])
554   if test "$tmp_reentrant_initially_defined" = "yes" ||
555     test "$tmp_need_reentrant" = "yes"; then
556     CURL_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
557     AC_MSG_RESULT([yes])
558   else
559     AC_MSG_RESULT([no])
560   fi
561   #
562 ])
563
564
565 dnl CURL_CONFIGURE_THREAD_SAFE
566 dnl -------------------------------------------------
567 dnl This first checks if the preprocessor _THREAD_SAFE
568 dnl symbol is already defined. If it isn't currently
569 dnl defined a set of checks are performed to verify
570 dnl if its definition is required. Finally, if
571 dnl _THREAD_SAFE is already defined or needed it takes
572 dnl care of making adjustments necessary to ensure
573 dnl that it is defined equally for further configure
574 dnl tests and generated config file.
575
576 AC_DEFUN([CURL_CONFIGURE_THREAD_SAFE], [
577   AC_PREREQ([2.50])dnl
578   #
579   AC_MSG_CHECKING([if _THREAD_SAFE is already defined])
580   AC_COMPILE_IFELSE([
581     AC_LANG_PROGRAM([[
582     ]],[[
583 #ifdef _THREAD_SAFE
584       int dummy=1;
585 #else
586       force compilation error
587 #endif
588     ]])
589   ],[
590     AC_MSG_RESULT([yes])
591     tmp_thread_safe_initially_defined="yes"
592   ],[
593     AC_MSG_RESULT([no])
594     tmp_thread_safe_initially_defined="no"
595   ])
596   #
597   if test "$tmp_thread_safe_initially_defined" = "no"; then
598     AC_MSG_CHECKING([if _THREAD_SAFE is actually needed])
599     CURL_CHECK_NEED_THREAD_SAFE_SYSTEM
600     if test "$tmp_need_thread_safe" = "yes"; then
601       AC_MSG_RESULT([yes])
602     else
603       AC_MSG_RESULT([no])
604     fi
605   fi
606   #
607   AC_MSG_CHECKING([if _THREAD_SAFE is onwards defined])
608   if test "$tmp_thread_safe_initially_defined" = "yes" ||
609     test "$tmp_need_thread_safe" = "yes"; then
610     CURL_CONFIGURE_FROM_NOW_ON_WITH_THREAD_SAFE
611     AC_MSG_RESULT([yes])
612   else
613     AC_MSG_RESULT([no])
614   fi
615   #
616 ])
617