1 AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
3 echo "LIBREPLACE_BROKEN_CHECKS: START"
5 dnl find the libreplace sources. This is meant to work both for
6 dnl libreplace standalone builds, and builds of packages using libreplace
8 for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../libreplace" "$srcdir/../replace"; do
9 if test -f "$d/replace.c"; then
11 AC_SUBST(libreplacedir)
15 LIBREPLACEOBJ="replace.o"
16 AC_SUBST(LIBREPLACEOBJ)
18 LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
27 AC_CHECK_TYPE(ino_t,unsigned)
28 AC_CHECK_TYPE(loff_t,off_t)
29 AC_CHECK_TYPE(offset_t,loff_t)
33 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
35 AC_CHECK_HEADERS(stdbool.h sys/select.h)
37 AC_CHECK_HEADERS(sys/epoll.h)
38 AC_CHECK_FUNCS(epoll_create)
41 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
50 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
58 AC_CACHE_CHECK([for working mmap],samba_cv_HAVE_MMAP,[
59 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
60 samba_cv_HAVE_MMAP=yes,samba_cv_HAVE_MMAP=no,samba_cv_HAVE_MMAP=cross)])
61 if test x"$samba_cv_HAVE_MMAP" = x"yes"; then
62 AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
66 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
70 #include <sys/types.h>
71 #include <netinet/in.h>
72 #ifdef HAVE_ARPA_INET_H
73 #include <arpa/inet.h>
75 main() { struct in_addr ip; ip.s_addr = 0x12345678;
76 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
77 strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); }
79 samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
80 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
81 AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
84 dnl Provided by replace.c:
86 #include <sys/types.h>
91 #include <sys/socket.h>],
93 [AC_DEFINE(socklen_t, int,[Socket length type])])
95 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
96 AC_CHECK_HEADERS(sys/time.h time.h)
97 AC_CHECK_HEADERS(sys/socket.h netinet/in.h)
98 AC_CHECK_HEADERS(stdarg.h vararg.h)
99 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
100 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
101 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
102 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
103 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
104 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
105 AC_HAVE_DECL(errno, [#include <errno.h>])
107 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
108 AC_TRY_RUN([#include <stdlib.h>
109 #include <sys/types.h>
110 #include <sys/stat.h>
114 char tpl[20]="/tmp/test.XXXXXX";
115 int fd = mkstemp(tpl);
116 if (fd == -1) exit(1);
118 if (fstat(fd, &st) != 0) exit(1);
119 if ((st.st_mode & 0777) != 0600) exit(1);
122 samba_cv_HAVE_SECURE_MKSTEMP=yes,
123 samba_cv_HAVE_SECURE_MKSTEMP=no,
124 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
125 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
126 AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
129 dnl Provided by snprintf.c:
130 AC_CHECK_HEADERS(stdio.h strings.h)
131 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
132 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
134 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
136 #include <sys/types.h>
140 void foo(const char *format, ...) {
144 long long l = 1234567890;
147 va_start(ap, format);
148 len = vsnprintf(buf, 0, format, ap);
150 if (len != 5) exit(1);
152 va_start(ap, format);
153 len = vsnprintf(0, 0, format, ap);
155 if (len != 5) exit(2);
157 if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
159 if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
160 if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
161 if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
162 if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
166 main() { foo("hello"); }
168 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
169 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
170 AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
174 LIBREPLACE_C99_STRUCT_INIT(c99_struct_initialization=yes,
175 c99_struct_initialization=no)
178 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
179 AC_TRY_LINK([#include <stdarg.h>
180 va_list ap1,ap2;], [va_copy(ap1,ap2);],
181 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
182 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
183 AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
186 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
187 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
188 AC_TRY_LINK([#include <stdarg.h>
189 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
190 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
191 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
192 AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
196 dnl __FUNCTION__ macro
197 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
198 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
199 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
200 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
201 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
204 AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
205 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
206 samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
207 if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
208 AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
212 AC_CHECK_HEADERS([sys/param.h limits.h])
214 AC_CHECK_TYPE(comparison_fn_t,
215 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
217 AC_CHECK_FUNCS(strnlen setenv)
218 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
220 # this test disabled as we don't actually need __VA_ARGS__ yet
222 # #define eprintf(...) fprintf(stderr, __VA_ARGS__)
223 # eprintf("bla", "bar");
224 # ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
226 # Check prerequisites
227 AC_CHECK_FUNCS([memset printf syslog], [],
228 [ AC_MSG_ERROR([Required function not found])])
230 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
232 #include <sys/types.h>
237 #include <signal.h>],[sig_atomic_t i = 0],
238 samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
239 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
240 AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
244 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],samba_cv_HAVE_OPEN_O_DIRECT,[
250 [int fd = open("/dev/null", O_DIRECT);],
251 samba_cv_HAVE_OPEN_O_DIRECT=yes,samba_cv_HAVE_OPEN_O_DIRECT=no)])
252 if test x"$samba_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
253 AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
257 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
258 dnl Check whether the compiler can generate precompiled headers
260 if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
261 precompiled_headers=yes
263 precompiled_headers=no
265 AC_SUBST(precompiled_headers)
268 dnl Check if the C compiler understands volatile (it should, being ANSI).
269 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
270 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
271 samba_cv_volatile=yes,samba_cv_volatile=no)])
272 if test x"$samba_cv_volatile" = x"yes"; then
273 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
276 m4_include(system/config.m4)
279 m4_include(getpass.m4)
281 m4_include(timegm.m4)
282 m4_include(repdir.m4)
284 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
285 [AC_MSG_ERROR([Required function not found])])
287 echo "LIBREPLACE_BROKEN_CHECKS: END"
288 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
290 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
292 #LIBREPLACE_ALL_CHECKS: START"
294 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
296 #LIBREPLACE_ALL_CHECKS: END"
298 m4_define(AC_LIBREPLACE_ALL_CHECKS,
300 AC__LIBREPLACE_ALL_CHECKS_START
301 AC_LIBREPLACE_CC_CHECKS
302 AC_LIBREPLACE_BROKEN_CHECKS
303 AC__LIBREPLACE_ALL_CHECKS_END
306 AC_LIBREPLACE_ALL_CHECKS