0348fda1352e4ff473d5cd3f768faf2ef1a733f9
[platform/upstream/c-ares.git] / m4 / reentrant.m4
1
2
3 # serial 1.10
4
5
6 dnl CARES_CHECK_NEED_REENTRANT_GMTIME_R
7 dnl -------------------------------------------------
8 dnl Checks if the preprocessor _REENTRANT definition
9 dnl makes function gmtime_r compiler visible.
10
11 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GMTIME_R], [
12   AC_LINK_IFELSE([
13     AC_LANG_FUNC_LINK_TRY([gmtime_r])
14   ],[
15     tmp_gmtime_r="yes"
16   ],[
17     tmp_gmtime_r="no"
18   ])
19   if test "$tmp_gmtime_r" = "yes"; then
20     AC_EGREP_CPP([gmtime_r],[
21 #include <sys/types.h>
22 #include <time.h>
23     ],[
24       tmp_gmtime_r="proto_declared"
25     ],[
26       AC_EGREP_CPP([gmtime_r],[
27 #define _REENTRANT
28 #include <sys/types.h>
29 #include <time.h>
30       ],[
31         tmp_gmtime_r="proto_needs_reentrant"
32         tmp_need_reentrant="yes"
33       ])
34     ])
35   fi
36 ])
37
38
39 dnl CARES_CHECK_NEED_REENTRANT_LOCALTIME_R
40 dnl -------------------------------------------------
41 dnl Checks if the preprocessor _REENTRANT definition
42 dnl makes function localtime_r compiler visible.
43
44 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_LOCALTIME_R], [
45   AC_LINK_IFELSE([
46     AC_LANG_FUNC_LINK_TRY([localtime_r])
47   ],[
48     tmp_localtime_r="yes"
49   ],[
50     tmp_localtime_r="no"
51   ])
52   if test "$tmp_localtime_r" = "yes"; then
53     AC_EGREP_CPP([localtime_r],[
54 #include <sys/types.h>
55 #include <time.h>
56     ],[
57       tmp_localtime_r="proto_declared"
58     ],[
59       AC_EGREP_CPP([localtime_r],[
60 #define _REENTRANT
61 #include <sys/types.h>
62 #include <time.h>
63       ],[
64         tmp_localtime_r="proto_needs_reentrant"
65         tmp_need_reentrant="yes"
66       ])
67     ])
68   fi
69 ])
70
71
72 dnl CARES_CHECK_NEED_REENTRANT_STRERROR_R
73 dnl -------------------------------------------------
74 dnl Checks if the preprocessor _REENTRANT definition
75 dnl makes function strerror_r compiler visible.
76
77 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_STRERROR_R], [
78   AC_LINK_IFELSE([
79     AC_LANG_FUNC_LINK_TRY([strerror_r])
80   ],[
81     tmp_strerror_r="yes"
82   ],[
83     tmp_strerror_r="no"
84   ])
85   if test "$tmp_strerror_r" = "yes"; then
86     AC_EGREP_CPP([strerror_r],[
87 #include <sys/types.h>
88 #include <string.h>
89     ],[
90       tmp_strerror_r="proto_declared"
91     ],[
92       AC_EGREP_CPP([strerror_r],[
93 #define _REENTRANT
94 #include <sys/types.h>
95 #include <string.h>
96       ],[
97         tmp_strerror_r="proto_needs_reentrant"
98         tmp_need_reentrant="yes"
99       ])
100     ])
101   fi
102 ])
103
104
105 dnl CARES_CHECK_NEED_REENTRANT_STRTOK_R
106 dnl -------------------------------------------------
107 dnl Checks if the preprocessor _REENTRANT definition
108 dnl makes function strtok_r compiler visible.
109
110 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_STRTOK_R], [
111   AC_LINK_IFELSE([
112     AC_LANG_FUNC_LINK_TRY([strtok_r])
113   ],[
114     tmp_strtok_r="yes"
115   ],[
116     tmp_strtok_r="no"
117   ])
118   if test "$tmp_strtok_r" = "yes"; then
119     AC_EGREP_CPP([strtok_r],[
120 #include <sys/types.h>
121 #include <string.h>
122     ],[
123       tmp_strtok_r="proto_declared"
124     ],[
125       AC_EGREP_CPP([strtok_r],[
126 #define _REENTRANT
127 #include <sys/types.h>
128 #include <string.h>
129       ],[
130         tmp_strtok_r="proto_needs_reentrant"
131         tmp_need_reentrant="yes"
132       ])
133     ])
134   fi
135 ])
136
137
138 dnl CARES_CHECK_NEED_REENTRANT_INET_NTOA_R
139 dnl -------------------------------------------------
140 dnl Checks if the preprocessor _REENTRANT definition
141 dnl makes function inet_ntoa_r compiler visible.
142
143 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_INET_NTOA_R], [
144   AC_LINK_IFELSE([
145     AC_LANG_FUNC_LINK_TRY([inet_ntoa_r])
146   ],[
147     tmp_inet_ntoa_r="yes"
148   ],[
149     tmp_inet_ntoa_r="no"
150   ])
151   if test "$tmp_inet_ntoa_r" = "yes"; then
152     AC_EGREP_CPP([inet_ntoa_r],[
153 #include <sys/types.h>
154 #include <sys/socket.h>
155 #include <netinet/in.h>
156 #include <arpa/inet.h>
157     ],[
158       tmp_inet_ntoa_r="proto_declared"
159     ],[
160       AC_EGREP_CPP([inet_ntoa_r],[
161 #define _REENTRANT
162 #include <sys/types.h>
163 #include <sys/socket.h>
164 #include <netinet/in.h>
165 #include <arpa/inet.h>
166       ],[
167         tmp_inet_ntoa_r="proto_needs_reentrant"
168         tmp_need_reentrant="yes"
169       ])
170     ])
171   fi
172 ])
173
174
175 dnl CARES_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
176 dnl -------------------------------------------------
177 dnl Checks if the preprocessor _REENTRANT definition
178 dnl makes function gethostbyaddr_r compiler visible.
179
180 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R], [
181   AC_LINK_IFELSE([
182     AC_LANG_FUNC_LINK_TRY([gethostbyaddr_r])
183   ],[
184     tmp_gethostbyaddr_r="yes"
185   ],[
186     tmp_gethostbyaddr_r="no"
187   ])
188   if test "$tmp_gethostbyaddr_r" = "yes"; then
189     AC_EGREP_CPP([gethostbyaddr_r],[
190 #include <sys/types.h>
191 #include <netdb.h>
192     ],[
193       tmp_gethostbyaddr_r="proto_declared"
194     ],[
195       AC_EGREP_CPP([gethostbyaddr_r],[
196 #define _REENTRANT
197 #include <sys/types.h>
198 #include <netdb.h>
199       ],[
200         tmp_gethostbyaddr_r="proto_needs_reentrant"
201         tmp_need_reentrant="yes"
202       ])
203     ])
204   fi
205 ])
206
207
208 dnl CARES_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
209 dnl -------------------------------------------------
210 dnl Checks if the preprocessor _REENTRANT definition
211 dnl makes function gethostbyname_r compiler visible.
212
213 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R], [
214   AC_LINK_IFELSE([
215     AC_LANG_FUNC_LINK_TRY([gethostbyname_r])
216   ],[
217     tmp_gethostbyname_r="yes"
218   ],[
219     tmp_gethostbyname_r="no"
220   ])
221   if test "$tmp_gethostbyname_r" = "yes"; then
222     AC_EGREP_CPP([gethostbyname_r],[
223 #include <sys/types.h>
224 #include <netdb.h>
225     ],[
226       tmp_gethostbyname_r="proto_declared"
227     ],[
228       AC_EGREP_CPP([gethostbyname_r],[
229 #define _REENTRANT
230 #include <sys/types.h>
231 #include <netdb.h>
232       ],[
233         tmp_gethostbyname_r="proto_needs_reentrant"
234         tmp_need_reentrant="yes"
235       ])
236     ])
237   fi
238 ])
239
240
241 dnl CARES_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
242 dnl -------------------------------------------------
243 dnl Checks if the preprocessor _REENTRANT definition
244 dnl makes function getprotobyname_r compiler visible.
245
246 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R], [
247   AC_LINK_IFELSE([
248     AC_LANG_FUNC_LINK_TRY([getprotobyname_r])
249   ],[
250     tmp_getprotobyname_r="yes"
251   ],[
252     tmp_getprotobyname_r="no"
253   ])
254   if test "$tmp_getprotobyname_r" = "yes"; then
255     AC_EGREP_CPP([getprotobyname_r],[
256 #include <sys/types.h>
257 #include <netdb.h>
258     ],[
259       tmp_getprotobyname_r="proto_declared"
260     ],[
261       AC_EGREP_CPP([getprotobyname_r],[
262 #define _REENTRANT
263 #include <sys/types.h>
264 #include <netdb.h>
265       ],[
266         tmp_getprotobyname_r="proto_needs_reentrant"
267         tmp_need_reentrant="yes"
268       ])
269     ])
270   fi
271 ])
272
273
274 dnl CARES_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
275 dnl -------------------------------------------------
276 dnl Checks if the preprocessor _REENTRANT definition
277 dnl makes function getservbyport_r compiler visible.
278
279 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_GETSERVBYPORT_R], [
280   AC_LINK_IFELSE([
281     AC_LANG_FUNC_LINK_TRY([getservbyport_r])
282   ],[
283     tmp_getservbyport_r="yes"
284   ],[
285     tmp_getservbyport_r="no"
286   ])
287   if test "$tmp_getservbyport_r" = "yes"; then
288     AC_EGREP_CPP([getservbyport_r],[
289 #include <sys/types.h>
290 #include <netdb.h>
291     ],[
292       tmp_getservbyport_r="proto_declared"
293     ],[
294       AC_EGREP_CPP([getservbyport_r],[
295 #define _REENTRANT
296 #include <sys/types.h>
297 #include <netdb.h>
298       ],[
299         tmp_getservbyport_r="proto_needs_reentrant"
300         tmp_need_reentrant="yes"
301       ])
302     ])
303   fi
304 ])
305
306
307 dnl CARES_CHECK_NEED_REENTRANT_FUNCTIONS_R
308 dnl -------------------------------------------------
309 dnl Checks if the preprocessor _REENTRANT definition
310 dnl makes several _r functions compiler visible.
311 dnl Internal macro for CARES_CONFIGURE_REENTRANT.
312
313 AC_DEFUN([CARES_CHECK_NEED_REENTRANT_FUNCTIONS_R], [
314   #
315   tmp_need_reentrant="no"
316   #
317   if test "$tmp_need_reentrant" = "no"; then
318     CARES_CHECK_NEED_REENTRANT_GMTIME_R
319   fi
320   if test "$tmp_need_reentrant" = "no"; then
321     CARES_CHECK_NEED_REENTRANT_LOCALTIME_R
322   fi
323   if test "$tmp_need_reentrant" = "no"; then
324     CARES_CHECK_NEED_REENTRANT_STRERROR_R
325   fi
326   if test "$tmp_need_reentrant" = "no"; then
327     CARES_CHECK_NEED_REENTRANT_STRTOK_R
328   fi
329   if test "$tmp_need_reentrant" = "no"; then
330     CARES_CHECK_NEED_REENTRANT_INET_NTOA_R
331   fi
332   if test "$tmp_need_reentrant" = "no"; then
333     CARES_CHECK_NEED_REENTRANT_GETHOSTBYADDR_R
334   fi
335   if test "$tmp_need_reentrant" = "no"; then
336     CARES_CHECK_NEED_REENTRANT_GETHOSTBYNAME_R
337   fi
338   if test "$tmp_need_reentrant" = "no"; then
339     CARES_CHECK_NEED_REENTRANT_GETPROTOBYNAME_R
340   fi
341   if test "$tmp_need_reentrant" = "no"; then
342     CARES_CHECK_NEED_REENTRANT_GETSERVBYPORT_R
343   fi
344 ])
345
346
347 dnl CARES_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
348 dnl -------------------------------------------------
349 dnl This macro ensures that configuration tests done
350 dnl after this will execute with preprocessor symbol
351 dnl _REENTRANT defined. This macro also ensures that
352 dnl the generated config file defines NEED_REENTRANT
353 dnl and that in turn setup.h will define _REENTRANT.
354 dnl Internal macro for CARES_CONFIGURE_REENTRANT.
355
356 AC_DEFUN([CARES_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT], [
357 AC_DEFINE([NEED_REENTRANT], [1],
358   [Define to 1 if _REENTRANT preprocessor symbol must be defined.])
359 cat >>confdefs.h <<_ACEOF
360 #ifndef _REENTRANT
361 #define _REENTRANT
362 #endif
363 _ACEOF
364 ])
365
366
367 dnl CARES_CONFIGURE_REENTRANT
368 dnl -------------------------------------------------
369 dnl This first checks if the preprocessor _REENTRANT
370 dnl symbol is already defined. If it isn't currently
371 dnl defined a set of checks are performed to verify
372 dnl if its definition is required to make visible to
373 dnl the compiler a set of *_r functions. Finally, if
374 dnl _REENTRANT is already defined or needed it takes
375 dnl care of making adjustments necessary to ensure
376 dnl that it is defined equally for further configure
377 dnl tests and generated config file.
378
379 AC_DEFUN([CARES_CONFIGURE_REENTRANT], [
380   AC_PREREQ([2.57])dnl
381   #
382   AC_MSG_CHECKING([if _REENTRANT is already defined])
383   AC_COMPILE_IFELSE([
384     AC_LANG_PROGRAM([[
385     ]],[[
386 #ifdef _REENTRANT
387       int dummy=1;
388 #else
389       force compilation error
390 #endif
391     ]])
392   ],[
393     AC_MSG_RESULT([yes])
394     tmp_reentrant_initially_defined="yes"
395   ],[
396     AC_MSG_RESULT([no])
397     tmp_reentrant_initially_defined="no"
398   ])
399   #
400   if test "$tmp_reentrant_initially_defined" = "no"; then
401     AC_MSG_CHECKING([if _REENTRANT is actually needed])
402     CARES_CHECK_NEED_REENTRANT_FUNCTIONS_R
403     if test "$tmp_need_reentrant" = "yes"; then
404       AC_MSG_RESULT([yes])
405     else
406       AC_MSG_RESULT([no])
407     fi
408   fi
409   #
410   AC_MSG_CHECKING([if _REENTRANT is onwards defined])
411   if test "$tmp_reentrant_initially_defined" = "yes" ||
412     test "$tmp_need_reentrant" = "yes"; then
413     CARES_CONFIGURE_FROM_NOW_ON_WITH_REENTRANT
414     AC_MSG_RESULT([yes])
415   else
416     AC_MSG_RESULT([no])
417   fi
418   #
419 ])
420