1 # Copyright (c) 2013 Holger Weiss <holger@weiss.in-berlin.de>
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are met:
7 # 1. Redistributions of source code must retain the above copyright notice, this
8 # list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright notice,
11 # this list of conditions and the following disclaimer in the documentation
12 # and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Define HAVE_STDARG_H to 1 if <stdarg.h> is available.
28 AC_DEFUN([HW_HEADER_STDARG_H],
30 AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used.
31 AC_CHECK_HEADERS_ONCE([stdarg.h])
32 ])# HW_HEADER_STDARG_H
36 # Define HAVE_VARARGS_H to 1 if <varargs.h> is available.
37 AC_DEFUN([HW_HEADER_VARARGS_H],
39 AC_PREREQ([2.60])dnl Older releases should work if AC_CHECK_HEADERS is used.
40 AC_CHECK_HEADERS_ONCE([varargs.h])
41 ])# HW_HEADER_VARARGS_H
45 # Set $hw_cv_func_va_copy to "yes" or "no". Define HAVE_VA_COPY to 1 if
46 # $hw_cv_func_va_copy is set to "yes". Note that it's "unspecified whether
47 # va_copy and va_end are macros or identifiers declared with external linkage."
48 # (C99: 7.15.1, 1) Therefore, the presence of va_copy(3) cannot simply "be
49 # tested with #ifdef", as suggested by the Autoconf manual (5.5.1).
50 AC_DEFUN([HW_FUNC_VA_COPY],
52 AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H.
53 AC_REQUIRE([HW_HEADER_VARARGS_H])dnl Our check evaluates HAVE_VARARGS_H.
54 AC_CACHE_CHECK([for va_copy],
63 [[va_list ap, aq; va_copy(aq, ap);]])],
64 [hw_cv_func_va_copy=yes],
65 [hw_cv_func_va_copy=no],
66 [hw_cv_func_va_copy=no])])
67 AS_IF([test "$hw_cv_func_va_copy" = yes],
68 [AC_DEFINE([HAVE_VA_COPY], [1],
69 [Define to 1 if you have the `va_copy' function or macro.])])
74 # Set $hw_cv_func___va_copy to "yes" or "no". Define HAVE___VA_COPY to 1 if
75 # $hw_cv_func___va_copy is set to "yes".
76 AC_DEFUN([HW_FUNC___VA_COPY],
78 AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H.
79 AC_REQUIRE([HW_HEADER_VARARGS_H])dnl Our check evaluates HAVE_VARARGS_H.
80 AC_CACHE_CHECK([for __va_copy],
81 [hw_cv_func___va_copy],
89 [[va_list ap, aq; __va_copy(aq, ap);]])],
90 [hw_cv_func___va_copy=yes],
91 [hw_cv_func___va_copy=no],
92 [hw_cv_func___va_copy=no])])
93 AS_IF([test "$hw_cv_func___va_copy" = yes],
94 [AC_DEFINE([HAVE___VA_COPY], [1],
95 [Define to 1 if you have the `__va_copy' function or macro.])])
100 # Set $hw_cv_func_vsnprintf and $hw_cv_func_vsnprintf_c99 to "yes" or "no",
101 # respectively. Define HAVE_VSNPRINTF to 1 only if $hw_cv_func_vsnprintf_c99
102 # is set to "yes". Otherwise, define vsnprintf to rpl_vsnprintf and make sure
103 # the replacement function will be built.
104 AC_DEFUN([HW_FUNC_VSNPRINTF],
106 AC_PREREQ([2.60])dnl 2.59 should work if some AC_TYPE_* macros are replaced.
107 AC_REQUIRE([HW_HEADER_STDARG_H])dnl Our check evaluates HAVE_STDARG_H.
108 AC_CHECK_FUNC([vsnprintf],
109 [hw_cv_func_vsnprintf=yes],
110 [hw_cv_func_vsnprintf=no])
111 AS_IF([test "$hw_cv_func_vsnprintf" = yes],
112 [AC_CACHE_CHECK([whether vsnprintf is C99-compliant],
113 [hw_cv_func_vsnprintf_c99],
120 static int testprintf(char *buf, size_t size, const char *fmt, ...)
125 result = vsnprintf(buf, size, fmt, ap);
130 if (testprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 ||
131 testprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 ||
132 buf[0] != 'T' || buf[3] != '\0')
134 [hw_cv_func_vsnprintf_c99=yes],
135 [hw_cv_func_vsnprintf_c99=no],
136 [hw_cv_func_vsnprintf_c99=no])])],
137 [hw_cv_func_vsnprintf_c99=no])
138 AS_IF([test "$hw_cv_func_vsnprintf_c99" = yes],
139 [AC_DEFINE([HAVE_VSNPRINTF], [1],
140 [Define to 1 if you have a C99-compliant `vsnprintf' function.])],
141 [AC_DEFINE([vsnprintf], [rpl_vsnprintf],
142 [Define to rpl_vsnprintf if the replacement function should be used.])
143 AC_CHECK_HEADERS([inttypes.h locale.h stddef.h stdint.h])
144 AC_CHECK_MEMBERS([struct lconv.decimal_point, struct lconv.thousands_sep],
145 [], [], [[#include <locale.h>]])
147 AC_TYPE_LONG_LONG_INT
148 AC_TYPE_UNSIGNED_LONG_LONG_INT
153 AC_CHECK_TYPES([ptrdiff_t])
154 AC_CHECK_FUNCS([localeconv])
155 _HW_FUNC_XPRINTF_REPLACE])
156 ])# HW_FUNC_VSNPRINTF
160 # Set $hw_cv_func_snprintf and $hw_cv_func_snprintf_c99 to "yes" or "no",
161 # respectively. Define HAVE_SNPRINTF to 1 only if $hw_cv_func_snprintf_c99
162 # is set to "yes". Otherwise, define snprintf to rpl_snprintf and make sure
163 # the replacement function will be built.
164 AC_DEFUN([HW_FUNC_SNPRINTF],
166 AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl Our snprintf(3) calls vsnprintf(3).
167 AC_CHECK_FUNC([snprintf],
168 [hw_cv_func_snprintf=yes],
169 [hw_cv_func_snprintf=no])
170 AS_IF([test "$hw_cv_func_snprintf" = yes],
171 [AC_CACHE_CHECK([whether snprintf is C99-compliant],
172 [hw_cv_func_snprintf_c99],
174 [AC_LANG_PROGRAM([[#include <stdio.h>]],
176 if (snprintf(buf, 4, "The answer is %27.2g.", 42.0) != 42 ||
177 snprintf(buf, 0, "No, it's %32zu.", (size_t)42) != 42 ||
178 buf[0] != 'T' || buf[3] != '\0')
180 [hw_cv_func_snprintf_c99=yes],
181 [hw_cv_func_snprintf_c99=no],
182 [hw_cv_func_snprintf_c99=no])])],
183 [hw_cv_func_snprintf_c99=no])
184 AS_IF([test "$hw_cv_func_snprintf_c99" = yes],
185 [AC_DEFINE([HAVE_SNPRINTF], [1],
186 [Define to 1 if you have a C99-compliant `snprintf' function.])],
187 [AC_DEFINE([snprintf], [rpl_snprintf],
188 [Define to rpl_snprintf if the replacement function should be used.])
189 _HW_FUNC_XPRINTF_REPLACE])
194 # Set $hw_cv_func_vasprintf to "yes" or "no". Define HAVE_VASPRINTF to 1 if
195 # $hw_cv_func_vasprintf is set to "yes". Otherwise, define vasprintf to
196 # rpl_vasprintf and make sure the replacement function will be built.
197 AC_DEFUN([HW_FUNC_VASPRINTF],
199 AC_REQUIRE([HW_FUNC_VSNPRINTF])dnl Our vasprintf(3) calls vsnprintf(3).
200 AC_CHECK_FUNCS([vasprintf],
201 [hw_cv_func_vasprintf=yes],
202 [hw_cv_func_vasprintf=no])
203 AS_IF([test "$hw_cv_func_vasprintf" = no],
204 [AC_DEFINE([vasprintf], [rpl_vasprintf],
205 [Define to rpl_vasprintf if the replacement function should be used.])
206 AC_CHECK_HEADERS([stdlib.h])
208 AS_IF([test "$hw_cv_func_va_copy" = no],
210 _HW_FUNC_XPRINTF_REPLACE])
211 ])# HW_FUNC_VASPRINTF
215 # Set $hw_cv_func_asprintf to "yes" or "no". Define HAVE_ASPRINTF to 1 if
216 # $hw_cv_func_asprintf is set to "yes". Otherwise, define asprintf to
217 # rpl_asprintf and make sure the replacement function will be built.
218 AC_DEFUN([HW_FUNC_ASPRINTF],
220 AC_REQUIRE([HW_FUNC_VASPRINTF])dnl Our asprintf(3) calls vasprintf(3).
221 AC_CHECK_FUNCS([asprintf],
222 [hw_cv_func_asprintf=yes],
223 [hw_cv_func_asprintf=no])
224 AS_IF([test "$hw_cv_func_asprintf" = no],
225 [AC_DEFINE([asprintf], [rpl_asprintf],
226 [Define to rpl_asprintf if the replacement function should be used.])
227 _HW_FUNC_XPRINTF_REPLACE])
230 # _HW_FUNC_XPRINTF_REPLACE
231 # ------------------------
232 # Arrange for building xprintf.c. Must be called if one or more of the
233 # functions provided by xprintf.c are needed.
234 AC_DEFUN([_HW_FUNC_XPRINTF_REPLACE],
236 AS_IF([test "x$_hw_cv_func_xprintf_replace_done" != xyes],
240 _hw_cv_func_xprintf_replace_done=yes])
241 ])# _HW_FUNC_XPRINTF_REPLACE
243 dnl vim:set joinspaces textwidth=80: