s4-torture: remove unchecked read from smb2 create
[Samba/vl.git] / lib / replace / libreplace.m4
blobd644e5062e567869ca492cd916b69ca6a99d6398
1 AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
3 echo "LIBREPLACE_LOCATION_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
7 libreplacedir=""
8 libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
9 for d in $libreplacepaths; do
10         if test -f "$d/replace.c"; then
11                 libreplacedir="$d"              
12                 AC_SUBST(libreplacedir)
13                 break;
14         fi
15 done
16 if test x"$libreplacedir" = "x"; then
17         AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
19 LIBREPLACEOBJ="$libreplacedir/replace.o"
20 AC_SUBST(LIBREPLACEOBJ)
22 AC_CANONICAL_BUILD
23 AC_CANONICAL_HOST
24 AC_CANONICAL_TARGET
26 echo "LIBREPLACE_LOCATION_CHECKS: END"
27 ]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
30 AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
32 echo "LIBREPLACE_BROKEN_CHECKS: START"
34 dnl find the libreplace sources. This is meant to work both for 
35 dnl libreplace standalone builds, and builds of packages using libreplace
36 libreplacedir=""
37 libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace $srcdir/../lib/replace $srcdir/../../../lib/replace"
38 for d in $libreplacepaths; do
39         if test -f "$d/replace.c"; then
40                 libreplacedir="$d"              
41                 AC_SUBST(libreplacedir)
42                 break;
43         fi
44 done
45 if test x"$libreplacedir" = "x"; then
46         AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
49 LIBREPLACEOBJ="$libreplacedir/replace.o"
50 AC_SUBST(LIBREPLACEOBJ)
52 LIBREPLACEOBJ="${LIBREPLACEOBJ} $libreplacedir/snprintf.o"
54 AC_TYPE_UID_T
55 AC_TYPE_MODE_T
56 AC_TYPE_OFF_T
57 AC_TYPE_SIZE_T
58 AC_TYPE_PID_T
59 AC_STRUCT_ST_RDEV
60 AC_CHECK_TYPE(ino_t,unsigned)
61 AC_CHECK_TYPE(loff_t,off_t)
62 AC_CHECK_TYPE(offset_t,loff_t)
64 AC_FUNC_MEMCMP
66 AC_CHECK_FUNCS([pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp utime utimes])
68 AC_CHECK_HEADERS(stdbool.h stdint.h sys/select.h)
69 AC_CHECK_HEADERS(setjmp.h utime.h)
71 LIBREPLACE_PROVIDE_HEADER([stdint.h])
72 LIBREPLACE_PROVIDE_HEADER([stdbool.h])
74 AC_CHECK_TYPE(bool, 
75 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
77 AC_INCLUDES_DEFAULT
78 #ifdef HAVE_STDBOOL_H
79 #include <stdbool.h>
80 #endif]
83 AC_CHECK_TYPE(_Bool, 
84 [AC_DEFINE(HAVE__Bool, 1, [Whether the _Bool type is available])],,
86 AC_INCLUDES_DEFAULT
87 #ifdef HAVE_STDBOOL_H
88 #include <stdbool.h>
89 #endif]
92 AC_CHECK_HEADERS(linux/types.h)
94 AC_CACHE_CHECK([for working mmap],libreplace_cv_HAVE_MMAP,[
95 AC_TRY_RUN([#include "$libreplacedir/test/shared_mmap.c"],
96            libreplace_cv_HAVE_MMAP=yes,libreplace_cv_HAVE_MMAP=no,libreplace_cv_HAVE_MMAP=cross)])
97 if test x"$libreplace_cv_HAVE_MMAP" = x"yes"; then
98     AC_DEFINE(HAVE_MMAP,1,[Whether mmap works])
101 AC_CACHE_CHECK([for working mremap],libreplace_cv_HAVE_MREMAP,[
102 AC_TRY_RUN([#include "$libreplacedir/test/shared_mremap.c"],
103            libreplace_cv_HAVE_MREMAP=yes,libreplace_cv_HAVE_MREMAP=no,libreplace_cv_HAVE_MREMAP=cross)])
104 if test x"$libreplace_cv_HAVE_MREMAP" = x"yes"; then
105     AC_DEFINE(HAVE_MREMAP,1,[Whether mremap works])
109 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
110 AC_CHECK_HEADERS(sys/time.h time.h)
111 AC_CHECK_HEADERS(stdarg.h vararg.h)
112 AC_CHECK_HEADERS(sys/mount.h mntent.h)
113 AC_CHECK_HEADERS(stropts.h)
114 AC_CHECK_HEADERS(unix.h)
116 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror strerror_r)
117 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
118 AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
119 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
120 AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
121 AC_CHECK_FUNCS(fdatasync,,[
122         # if we didn't find it, look in librt (Solaris hides it there...)
123         AC_CHECK_LIB(rt, fdatasync,
124                 [libreplace_cv_HAVE_FDATASYNC_IN_LIBRT=yes
125                 AC_DEFINE(HAVE_FDATASYNC, 1, Define to 1 if there is support for fdatasync)])
127 AC_HAVE_DECL(fdatasync, [#include <unistd.h>])
128 AC_CHECK_FUNCS(clock_gettime,libreplace_cv_have_clock_gettime=yes,[
129         AC_CHECK_LIB(rt, clock_gettime,
130                 [libreplace_cv_HAVE_CLOCK_GETTIME_IN_LIBRT=yes
131                 libreplace_cv_have_clock_gettime=yes
132                 AC_DEFINE(HAVE_CLOCK_GETTIME, 1, Define to 1 if there is support for clock_gettime)])
134 AC_CHECK_FUNCS(get_current_dir_name)
135 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
136 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
137 AC_HAVE_DECL(errno, [#include <errno.h>])
139 AC_CACHE_CHECK([for secure mkstemp],libreplace_cv_HAVE_SECURE_MKSTEMP,[
140 AC_TRY_RUN([#include <stdlib.h>
141 #include <sys/types.h>
142 #include <sys/stat.h>
143 #include <unistd.h>
144 main() { 
145   struct stat st;
146   char tpl[20]="/tmp/test.XXXXXX"; 
147   int fd = mkstemp(tpl); 
148   if (fd == -1) exit(1);
149   unlink(tpl);
150   if (fstat(fd, &st) != 0) exit(1);
151   if ((st.st_mode & 0777) != 0600) exit(1);
152   exit(0);
154 libreplace_cv_HAVE_SECURE_MKSTEMP=yes,
155 libreplace_cv_HAVE_SECURE_MKSTEMP=no,
156 libreplace_cv_HAVE_SECURE_MKSTEMP=cross)])
157 if test x"$libreplace_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
158     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
161 dnl Provided by snprintf.c:
162 AC_CHECK_HEADERS(stdio.h strings.h)
163 AC_CHECK_DECLS([snprintf, vsnprintf, asprintf, vasprintf])
164 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
166 AC_CACHE_CHECK([for C99 vsnprintf],libreplace_cv_HAVE_C99_VSNPRINTF,[
167 AC_TRY_RUN([
168 #include <sys/types.h>
169 #include <stdio.h>
170 #include <stdarg.h>
171 #include <stdlib.h>
172 void foo(const char *format, ...) { 
173        va_list ap;
174        int len;
175        char buf[20];
176        long long l = 1234567890;
177        l *= 100;
179        va_start(ap, format);
180        len = vsnprintf(buf, 0, format, ap);
181        va_end(ap);
182        if (len != 5) exit(1);
184        va_start(ap, format);
185        len = vsnprintf(0, 0, format, ap);
186        va_end(ap);
187        if (len != 5) exit(2);
189        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
191        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
192        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
193        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
194        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
196        exit(0);
198 main() { foo("hello"); }
200 libreplace_cv_HAVE_C99_VSNPRINTF=yes,libreplace_cv_HAVE_C99_VSNPRINTF=no,libreplace_cv_HAVE_C99_VSNPRINTF=cross)])
201 if test x"$libreplace_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
202     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
206 dnl VA_COPY
207 AC_CACHE_CHECK([for va_copy],libreplace_cv_HAVE_VA_COPY,[
208 AC_TRY_LINK([#include <stdarg.h>
209 va_list ap1,ap2;], [va_copy(ap1,ap2);],
210 libreplace_cv_HAVE_VA_COPY=yes,libreplace_cv_HAVE_VA_COPY=no)])
211 if test x"$libreplace_cv_HAVE_VA_COPY" = x"yes"; then
212     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
215 if test x"$libreplace_cv_HAVE_VA_COPY" != x"yes"; then
216 AC_CACHE_CHECK([for __va_copy],libreplace_cv_HAVE___VA_COPY,[
217 AC_TRY_LINK([#include <stdarg.h>
218 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
219 libreplace_cv_HAVE___VA_COPY=yes,libreplace_cv_HAVE___VA_COPY=no)])
220 if test x"$libreplace_cv_HAVE___VA_COPY" = x"yes"; then
221     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
225 dnl __FUNCTION__ macro
226 AC_CACHE_CHECK([for __FUNCTION__ macro],libreplace_cv_HAVE_FUNCTION_MACRO,[
227 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
228 libreplace_cv_HAVE_FUNCTION_MACRO=yes,libreplace_cv_HAVE_FUNCTION_MACRO=no)])
229 if test x"$libreplace_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
230     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
231 else
232     dnl __func__ macro
233     AC_CACHE_CHECK([for __func__ macro],libreplace_cv_HAVE_func_MACRO,[
234     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
235     libreplace_cv_HAVE_func_MACRO=yes,libreplace_cv_HAVE_func_MACRO=no)])
236     if test x"$libreplace_cv_HAVE_func_MACRO" = x"yes"; then
237        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
238     fi
241 AC_CHECK_HEADERS([sys/param.h limits.h])
243 AC_CHECK_TYPE(comparison_fn_t, 
244 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
246 AC_HAVE_DECL(setenv, [#include <stdlib.h>])
247 AC_CHECK_FUNCS(setenv unsetenv)
248 AC_HAVE_DECL(environ, [#include <unistd.h>])
250 AC_CHECK_FUNCS(strnlen)
251 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
253 AC_CHECK_FUNCS(memmem)
255 # this test disabled as we don't actually need __VA_ARGS__ yet
256 AC_TRY_CPP([
257 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
258 eprintf("bla", "bar");
259 ], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
262 AC_CACHE_CHECK([for sig_atomic_t type],libreplace_cv_sig_atomic_t, [
263     AC_TRY_COMPILE([
264 #include <sys/types.h>
265 #if STDC_HEADERS
266 #include <stdlib.h>
267 #include <stddef.h>
268 #endif
269 #include <signal.h>],[sig_atomic_t i = 0],
270         libreplace_cv_sig_atomic_t=yes,libreplace_cv_sig_atomic_t=no)])
271 if test x"$libreplace_cv_sig_atomic_t" = x"yes"; then
272    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
276 AC_CACHE_CHECK([for O_DIRECT flag to open(2)],libreplace_cv_HAVE_OPEN_O_DIRECT,[
277 AC_TRY_COMPILE([
278 #include <unistd.h>
279 #ifdef HAVE_FCNTL_H
280 #include <fcntl.h>
281 #endif],
282 [int fd = open("/dev/null", O_DIRECT);],
283 libreplace_cv_HAVE_OPEN_O_DIRECT=yes,libreplace_cv_HAVE_OPEN_O_DIRECT=no)])
284 if test x"$libreplace_cv_HAVE_OPEN_O_DIRECT" = x"yes"; then
285     AC_DEFINE(HAVE_OPEN_O_DIRECT,1,[Whether the open(2) accepts O_DIRECT])
289 dnl Check if the C compiler understands volatile (it should, being ANSI).
290 AC_CACHE_CHECK([that the C compiler understands volatile],libreplace_cv_volatile, [
291         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
292                 libreplace_cv_volatile=yes,libreplace_cv_volatile=no)])
293 if test x"$libreplace_cv_volatile" = x"yes"; then
294         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
297 m4_include(system/config.m4)
299 m4_include(dlfcn.m4)
300 m4_include(getpass.m4)
301 m4_include(strptime.m4)
302 m4_include(win32.m4)
303 m4_include(timegm.m4)
304 m4_include(repdir.m4)
305 m4_include(crypt.m4)
307 if test x$libreplace_cv_have_clock_gettime = xyes ; then
308         SMB_CHECK_CLOCK_ID(CLOCK_MONOTONIC)
309         SMB_CHECK_CLOCK_ID(CLOCK_PROCESS_CPUTIME_ID)
310         SMB_CHECK_CLOCK_ID(CLOCK_REALTIME)
313 AC_CACHE_CHECK([for struct timespec type],libreplace_cv_struct_timespec, [
314     AC_TRY_COMPILE([
315 #include <sys/types.h>
316 #if STDC_HEADERS
317 #include <stdlib.h>
318 #include <stddef.h>
319 #endif
320 #if TIME_WITH_SYS_TIME
321 # include <sys/time.h>
322 # include <time.h>
323 #else
324 # if HAVE_SYS_TIME_H
325 #  include <sys/time.h>
326 # else
327 #  include <time.h>
328 # endif
329 #endif
330 ],[struct timespec ts;],
331         libreplace_cv_struct_timespec=yes,libreplace_cv_struct_timespec=no)])
332 if test x"$libreplace_cv_struct_timespec" = x"yes"; then
333    AC_DEFINE(HAVE_STRUCT_TIMESPEC,1,[Whether we have struct timespec])
336 AC_CHECK_FUNCS([printf memset memcpy],,[AC_MSG_ERROR([Required function not found])])
338 echo "LIBREPLACE_BROKEN_CHECKS: END"
339 ]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
341 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
343 #LIBREPLACE_ALL_CHECKS: START"
345 AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
347 #LIBREPLACE_ALL_CHECKS: END"
349 m4_define(AC_LIBREPLACE_ALL_CHECKS,
351 AC__LIBREPLACE_ALL_CHECKS_START
352 AC_LIBREPLACE_LOCATION_CHECKS
353 AC_LIBREPLACE_CC_CHECKS
354 AC_LIBREPLACE_BROKEN_CHECKS
355 AC__LIBREPLACE_ALL_CHECKS_END
356 CFLAGS="$CFLAGS -I$libreplacedir"
359 m4_include(libreplace_cc.m4)
360 m4_include(libreplace_ld.m4)
361 m4_include(libreplace_network.m4)
362 m4_include(libreplace_macros.m4)
365 dnl SMB_CHECK_CLOCK_ID(clockid)
366 dnl Test whether the specified clock_gettime clock ID is available. If it
367 dnl is, we define HAVE_clockid
368 AC_DEFUN([SMB_CHECK_CLOCK_ID],
370     AC_MSG_CHECKING(for $1)
371     AC_TRY_LINK([
372 #if TIME_WITH_SYS_TIME
373 # include <sys/time.h>
374 # include <time.h>
375 #else
376 # if HAVE_SYS_TIME_H
377 #  include <sys/time.h>
378 # else
379 #  include <time.h>
380 # endif
381 #endif
382     ],
383     [
384 clockid_t clk = $1;
385     ],
386     [
387         AC_MSG_RESULT(yes)
388         AC_DEFINE(HAVE_$1, 1,
389             [Whether the clock_gettime clock ID $1 is available])
390     ],
391     [
392         AC_MSG_RESULT(no)
393     ])
395 m4_ifndef([AC_USE_SYSTEM_EXTENSIONS],[m4_include(autoconf-2.60.m4)])