r18053: the sig_atomic_t test needs to be in libreplace for getpass.c to
[bbaumbach/samba-autobuild/.git] / source4 / lib / replace / config.m4
1 AC_CHECK_HEADERS([stdint.h inttypes.h])
2 AC_CHECK_TYPE(uint_t, unsigned int)
3 AC_CHECK_TYPE(uint8_t, unsigned char)
4 AC_CHECK_TYPE(int8_t, char)
5 AC_CHECK_TYPE(int16_t, short)
6 AC_CHECK_TYPE(uint16_t, unsigned short)
7 AC_CHECK_TYPE(int32_t, long)
8 AC_CHECK_TYPE(intptr_t, unsigned long long)
9 AC_CHECK_TYPE(uint32_t, unsigned long)
10 AC_CHECK_TYPE(ssize_t, int)
11
12 AC_CHECK_HEADERS(stdbool.h)
13
14 AC_CHECK_TYPE(bool, 
15 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
16 [
17 AC_INCLUDES_DEFAULT
18 #ifdef HAVE_STDBOOL_H
19 #include <stdbool.h>
20 #endif]
21 )
22
23
24 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
25 AC_TRY_RUN([
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <netinet/in.h>
29 #ifdef HAVE_ARPA_INET_H
30 #include <arpa/inet.h>
31 #endif
32 main() { struct in_addr ip; ip.s_addr = 0x12345678;
33 if (strcmp(inet_ntoa(ip),"18.52.86.120") &&
34     strcmp(inet_ntoa(ip),"120.86.52.18")) { exit(0); } 
35 exit(1);}],
36            samba_cv_REPLACE_INET_NTOA=yes,samba_cv_REPLACE_INET_NTOA=no,samba_cv_REPLACE_INET_NTOA=cross)])
37 if test x"$samba_cv_REPLACE_INET_NTOA" = x"yes"; then
38     AC_DEFINE(REPLACE_INET_NTOA,1,[Whether inet_ntoa should be replaced])
39 fi
40
41 dnl Provided by replace.c:
42 AC_TRY_COMPILE([
43 #include <sys/types.h>
44 #if STDC_HEADERS
45 #include <stdlib.h>
46 #include <stddef.h>
47 #endif
48 #include <sys/socket.h>], 
49 [socklen_t foo;],,
50 [AC_DEFINE(socklen_t, int,[Socket length type])])
51
52 AC_CHECK_HEADERS(sys/syslog.h syslog.h)
53 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
54 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
55 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
56 AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp)
57 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
58 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
59 AC_HAVE_DECL(errno, [#include <errno.h>])
60
61 AC_CACHE_CHECK([for secure mkstemp],samba_cv_HAVE_SECURE_MKSTEMP,[
62 AC_TRY_RUN([#include <stdlib.h>
63 #include <sys/types.h>
64 #include <sys/stat.h>
65 #include <unistd.h>
66 main() { 
67   struct stat st;
68   char tpl[20]="/tmp/test.XXXXXX"; 
69   int fd = mkstemp(tpl); 
70   if (fd == -1) exit(1);
71   unlink(tpl);
72   if (fstat(fd, &st) != 0) exit(1);
73   if ((st.st_mode & 0777) != 0600) exit(1);
74   exit(0);
75 }],
76 samba_cv_HAVE_SECURE_MKSTEMP=yes,
77 samba_cv_HAVE_SECURE_MKSTEMP=no,
78 samba_cv_HAVE_SECURE_MKSTEMP=cross)])
79 if test x"$samba_cv_HAVE_SECURE_MKSTEMP" = x"yes"; then
80     AC_DEFINE(HAVE_SECURE_MKSTEMP,1,[Whether mkstemp is secure])
81 fi
82
83 dnl Provided by snprintf.c:
84 AC_HAVE_DECL(asprintf, [#include <stdio.h>])
85 AC_HAVE_DECL(vasprintf, [#include <stdio.h>])
86 AC_HAVE_DECL(vsnprintf, [#include <stdio.h>])
87 AC_HAVE_DECL(snprintf, [#include <stdio.h>])
88 AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf)
89 AC_CHECK_HEADERS(strings.h)
90
91 AC_CACHE_CHECK([for C99 vsnprintf],samba_cv_HAVE_C99_VSNPRINTF,[
92 AC_TRY_RUN([
93 #include <sys/types.h>
94 #include <stdio.h>
95 #include <stdarg.h>
96 #include <stdlib.h>
97 void foo(const char *format, ...) { 
98        va_list ap;
99        int len;
100        char buf[20];
101        long long l = 1234567890;
102        l *= 100;
103
104        va_start(ap, format);
105        len = vsnprintf(buf, 0, format, ap);
106        va_end(ap);
107        if (len != 5) exit(1);
108
109        va_start(ap, format);
110        len = vsnprintf(0, 0, format, ap);
111        va_end(ap);
112        if (len != 5) exit(2);
113
114        if (snprintf(buf, 3, "hello") != 5 || strcmp(buf, "he") != 0) exit(3);
115
116        if (snprintf(buf, 20, "%lld", l) != 12 || strcmp(buf, "123456789000") != 0) exit(4);
117        if (snprintf(buf, 20, "%zu", 123456789) != 9 || strcmp(buf, "123456789") != 0) exit(5);
118        if (snprintf(buf, 20, "%2\$d %1\$d", 3, 4) != 3 || strcmp(buf, "4 3") != 0) exit(6);
119        if (snprintf(buf, 20, "%s", 0) < 3) exit(7);
120
121        exit(0);
122 }
123 main() { foo("hello"); }
124 ],
125 samba_cv_HAVE_C99_VSNPRINTF=yes,samba_cv_HAVE_C99_VSNPRINTF=no,samba_cv_HAVE_C99_VSNPRINTF=cross)])
126 if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
127     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
128 fi
129
130 dnl Provided by dlfcn.c:
131 AC_SEARCH_LIBS_EXT(dlopen, [dl], DL_LIBS)
132 SMB_EXT_LIB(DL,[${DL_LIBS}],[${DL_CFLAGS}],[${DL_CPPFLAGS}],[${DL_LDFLAGS}])
133 SAVE_LIBS="$LIBS"
134 LIBS="$LIBS $DL_LIBS"
135 AC_CHECK_HEADERS(dlfcn.h)
136 AC_CHECK_FUNCS(dlopen dlsym dlerror dlclose)
137 LIBS="$SAVE_LIBS"
138
139 AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
140                            [AC_MSG_ERROR([Required function not found])])
141
142 sinclude(lib/replace/getpass.m4)
143
144 dnl VA_COPY
145 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
146 AC_TRY_LINK([#include <stdarg.h>
147 va_list ap1,ap2;], [va_copy(ap1,ap2);],
148 samba_cv_HAVE_VA_COPY=yes,samba_cv_HAVE_VA_COPY=no)])
149 if test x"$samba_cv_HAVE_VA_COPY" = x"yes"; then
150     AC_DEFINE(HAVE_VA_COPY,1,[Whether va_copy() is available])
151 fi
152
153 if test x"$samba_cv_HAVE_VA_COPY" != x"yes"; then
154 AC_CACHE_CHECK([for __va_copy],samba_cv_HAVE___VA_COPY,[
155 AC_TRY_LINK([#include <stdarg.h>
156 va_list ap1,ap2;], [__va_copy(ap1,ap2);],
157 samba_cv_HAVE___VA_COPY=yes,samba_cv_HAVE___VA_COPY=no)])
158 if test x"$samba_cv_HAVE___VA_COPY" = x"yes"; then
159     AC_DEFINE(HAVE___VA_COPY,1,[Whether __va_copy() is available])
160 fi
161 fi
162
163 dnl __FUNCTION__ macro
164 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
165 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
166 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
167 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
168     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
169 else
170     dnl __func__ macro
171     AC_CACHE_CHECK([for __func__ macro],samba_cv_HAVE_func_MACRO,[
172     AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __func__);],
173     samba_cv_HAVE_func_MACRO=yes,samba_cv_HAVE_func_MACRO=no)])
174     if test x"$samba_cv_HAVE_func_MACRO" = x"yes"; then
175        AC_DEFINE(HAVE_func_MACRO,1,[Whether there is a __func__ macro])
176     fi
177 fi
178
179 AC_CHECK_HEADERS([sys/param.h limits.h])
180
181 AC_CHECK_TYPE(comparison_fn_t, 
182 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
183
184 AC_CHECK_FUNCS(timegm strnlen setenv)
185 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
186
187 AC_TRY_CPP([
188 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
189 eprintf("bla", "bar");
190 ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
191
192 # Check prerequisites
193 AC_CHECK_FUNCS([memset printf syslog], [], 
194                            [ AC_MSG_ERROR([Required function not found])])
195
196 AC_CACHE_CHECK([for sig_atomic_t type],samba_cv_sig_atomic_t, [
197     AC_TRY_COMPILE([
198 #include <sys/types.h>
199 #if STDC_HEADERS
200 #include <stdlib.h>
201 #include <stddef.h>
202 #endif
203 #include <signal.h>],[sig_atomic_t i = 0],
204         samba_cv_sig_atomic_t=yes,samba_cv_sig_atomic_t=no)])
205 if test x"$samba_cv_sig_atomic_t" = x"yes"; then
206    AC_DEFINE(HAVE_SIG_ATOMIC_T_TYPE,1,[Whether we have the atomic_t variable type])
207 fi