]> granicus.if.org Git - postgresql/blob - config/c-library.m4
Let compiler handle size calculation of bool types.
[postgresql] / config / c-library.m4
1 # Macros that test various C library quirks
2 # config/c-library.m4
3
4
5 # PGAC_VAR_INT_TIMEZONE
6 # ---------------------
7 # Check if the global variable `timezone' exists. If so, define
8 # HAVE_INT_TIMEZONE.
9 AC_DEFUN([PGAC_VAR_INT_TIMEZONE],
10 [AC_CACHE_CHECK(for int timezone, pgac_cv_var_int_timezone,
11 [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>
12 int res;],
13   [#ifndef __CYGWIN__
14 res = timezone / 60;
15 #else
16 res = _timezone / 60;
17 #endif])],
18   [pgac_cv_var_int_timezone=yes],
19   [pgac_cv_var_int_timezone=no])])
20 if test x"$pgac_cv_var_int_timezone" = xyes ; then
21   AC_DEFINE(HAVE_INT_TIMEZONE, 1,
22             [Define to 1 if you have the global variable 'int timezone'.])
23 fi])# PGAC_VAR_INT_TIMEZONE
24
25
26 # PGAC_STRUCT_TIMEZONE
27 # ------------------
28 # Figure out how to get the current timezone.  If `struct tm' has a
29 # `tm_zone' member, define `HAVE_TM_ZONE'.  Also, if the
30 # external array `tzname' is found, define `HAVE_TZNAME'.
31 # This is the same as the standard macro AC_STRUCT_TIMEZONE, except that
32 # tzname[] is checked for regardless of whether we find tm_zone.
33 AC_DEFUN([PGAC_STRUCT_TIMEZONE],
34 [AC_REQUIRE([AC_STRUCT_TM])dnl
35 AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
36 #include <$ac_cv_struct_tm>
37 ])
38 if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
39   AC_DEFINE(HAVE_TM_ZONE, 1,
40             [Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
41              `HAVE_STRUCT_TM_TM_ZONE' instead.])
42 fi
43 AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
44 [AC_LINK_IFELSE([AC_LANG_PROGRAM(
45 [[#include <time.h>
46 #ifndef tzname /* For SGI.  */
47 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
48 #endif
49 ]],
50 [atoi(*tzname);])], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)])
51 if test $ac_cv_var_tzname = yes; then
52     AC_DEFINE(HAVE_TZNAME, 1,
53               [Define to 1 if you have the external array `tzname'.])
54 fi
55 ])# PGAC_STRUCT_TIMEZONE
56
57
58 # PGAC_FUNC_GETTIMEOFDAY_1ARG
59 # ---------------------------
60 # Check if gettimeofday() has only one arguments. (Normal is two.)
61 # If so, define GETTIMEOFDAY_1ARG.
62 AC_DEFUN([PGAC_FUNC_GETTIMEOFDAY_1ARG],
63 [AC_CACHE_CHECK(whether gettimeofday takes only one argument,
64 pgac_cv_func_gettimeofday_1arg,
65 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/time.h>],
66 [struct timeval *tp;
67 struct timezone *tzp;
68 gettimeofday(tp,tzp);])],
69 [pgac_cv_func_gettimeofday_1arg=no],
70 [pgac_cv_func_gettimeofday_1arg=yes])])
71 if test x"$pgac_cv_func_gettimeofday_1arg" = xyes ; then
72   AC_DEFINE(GETTIMEOFDAY_1ARG, 1,
73             [Define to 1 if gettimeofday() takes only 1 argument.])
74 fi
75 AH_VERBATIM(GETTIMEOFDAY_1ARG_,
76 [@%:@ifdef GETTIMEOFDAY_1ARG
77 @%:@ define gettimeofday(a,b) gettimeofday(a)
78 @%:@endif])dnl
79 ])# PGAC_FUNC_GETTIMEOFDAY_1ARG
80
81
82 # PGAC_FUNC_STRERROR_R_INT
83 # ---------------------------
84 # Check if strerror_r() returns an int (SUSv3) rather than a char * (GNU libc)
85 # If so, define STRERROR_R_INT
86 AC_DEFUN([PGAC_FUNC_STRERROR_R_INT],
87 [AC_CACHE_CHECK(whether strerror_r returns int,
88 pgac_cv_func_strerror_r_int,
89 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <string.h>],
90 [#ifndef _AIX
91 int strerror_r(int, char *, size_t);
92 #else
93 /* Older AIX has 'int' for the third argument so we don't test the args. */
94 int strerror_r();
95 #endif])],
96 [pgac_cv_func_strerror_r_int=yes],
97 [pgac_cv_func_strerror_r_int=no])])
98 if test x"$pgac_cv_func_strerror_r_int" = xyes ; then
99   AC_DEFINE(STRERROR_R_INT, 1,
100             [Define to 1 if strerror_r() returns a int.])
101 fi
102 ])# PGAC_FUNC_STRERROR_R_INT
103
104
105 # PGAC_UNION_SEMUN
106 # ----------------
107 # Check if `union semun' exists. Define HAVE_UNION_SEMUN if so.
108 # If it doesn't then one could define it as
109 # union semun { int val; struct semid_ds *buf; unsigned short *array; }
110 AC_DEFUN([PGAC_UNION_SEMUN],
111 [AC_CHECK_TYPES([union semun], [], [],
112 [#include <sys/types.h>
113 #include <sys/ipc.h>
114 #include <sys/sem.h>])])# PGAC_UNION_SEMUN
115
116
117 # PGAC_STRUCT_SOCKADDR_UN
118 # -----------------------
119 # If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
120 # (Requires test for <sys/un.h>!)
121 AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
122 [AC_CHECK_TYPE([struct sockaddr_un], [AC_DEFINE(HAVE_UNIX_SOCKETS, 1, [Define to 1 if you have unix sockets.])], [],
123 [#include <sys/types.h>
124 #ifdef HAVE_SYS_UN_H
125 #include <sys/un.h>
126 #endif
127 ])])# PGAC_STRUCT_SOCKADDR_UN
128
129
130 # PGAC_STRUCT_SOCKADDR_STORAGE
131 # ----------------------------
132 # If `struct sockaddr_storage' exists, define HAVE_STRUCT_SOCKADDR_STORAGE.
133 # If it is missing then one could define it.
134 AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE],
135 [AC_CHECK_TYPES([struct sockaddr_storage], [], [],
136 [#include <sys/types.h>
137 #ifdef HAVE_SYS_SOCKET_H
138 #include <sys/socket.h>
139 #endif
140 ])])# PGAC_STRUCT_SOCKADDR_STORAGE
141
142 # PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
143 # --------------------------------------
144 # Check the members of `struct sockaddr_storage'.  We need to know about
145 # ss_family and ss_len.  (Some platforms follow RFC 2553 and call them
146 # __ss_family and __ss_len.)  We also check struct sockaddr's sa_len;
147 # if we have to define our own `struct sockaddr_storage', this tells us
148 # whether we need to provide an ss_len field.
149 AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS],
150 [AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family,
151                    struct sockaddr_storage.__ss_family,
152                    struct sockaddr_storage.ss_len,
153                    struct sockaddr_storage.__ss_len,
154                    struct sockaddr.sa_len], [], [],
155 [#include <sys/types.h>
156 #ifdef HAVE_SYS_SOCKET_H
157 #include <sys/socket.h>
158 #endif
159 ])])# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
160
161
162 # PGAC_STRUCT_ADDRINFO
163 # -----------------------
164 # If `struct addrinfo' exists, define HAVE_STRUCT_ADDRINFO.
165 AC_DEFUN([PGAC_STRUCT_ADDRINFO],
166 [AC_CHECK_TYPES([struct addrinfo], [], [],
167 [#include <sys/types.h>
168 #include <sys/socket.h>
169 #include <netdb.h>
170 ])])# PGAC_STRUCT_ADDRINFO
171
172
173 # PGAC_FUNC_SNPRINTF_LONG_LONG_INT_MODIFIER
174 # ---------------------------------------
175 # Determine which length modifier snprintf uses for long long int.  We
176 # handle ll, q, and I64.  The result is in shell variable
177 # LONG_LONG_INT_MODIFIER.
178 #
179 # MinGW uses '%I64d', though gcc throws an warning with -Wall,
180 # while '%lld' doesn't generate a warning, but doesn't work.
181 #
182 AC_DEFUN([PGAC_FUNC_SNPRINTF_LONG_LONG_INT_MODIFIER],
183 [AC_MSG_CHECKING([snprintf length modifier for long long int])
184 AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_modifier,
185 [for pgac_modifier in 'll' 'q' 'I64'; do
186 AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
187 typedef long long int ac_int64;
188 #define INT64_FORMAT "%${pgac_modifier}d"
189
190 ac_int64 a = 20000001;
191 ac_int64 b = 40000005;
192
193 int does_int64_snprintf_work()
194 {
195   ac_int64 c;
196   char buf[100];
197
198   if (sizeof(ac_int64) != 8)
199     return 0;                   /* doesn't look like the right size */
200
201   c = a * b;
202   snprintf(buf, 100, INT64_FORMAT, c);
203   if (strcmp(buf, "800000140000005") != 0)
204     return 0;                   /* either multiply or snprintf is busted */
205   return 1;
206 }
207 main() {
208   exit(! does_int64_snprintf_work());
209 }]])],
210 [pgac_cv_snprintf_long_long_int_modifier=$pgac_modifier; break],
211 [],
212 [pgac_cv_snprintf_long_long_int_modifier=cross; break])
213 done])dnl AC_CACHE_VAL
214
215 LONG_LONG_INT_MODIFIER=''
216
217 case $pgac_cv_snprintf_long_long_int_modifier in
218   cross) AC_MSG_RESULT([cannot test (not on host machine)]);;
219   ?*)    AC_MSG_RESULT([$pgac_cv_snprintf_long_long_int_modifier])
220          LONG_LONG_INT_MODIFIER=$pgac_cv_snprintf_long_long_int_modifier;;
221   *)     AC_MSG_RESULT(none);;
222 esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_MODIFIER
223
224
225 # PGAC_FUNC_SNPRINTF_ARG_CONTROL
226 # ---------------------------------------
227 # Determine if snprintf supports %1$ argument selection, e.g. %5$ selects
228 # the fifth argument after the printf format string.
229 # This is not in the C99 standard, but in the Single Unix Specification (SUS).
230 # It is used in our language translation strings.
231 #
232 AC_DEFUN([PGAC_FUNC_SNPRINTF_ARG_CONTROL],
233 [AC_MSG_CHECKING([whether snprintf supports argument control])
234 AC_CACHE_VAL(pgac_cv_snprintf_arg_control,
235 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
236 #include <string.h>
237
238 int main()
239 {
240   char buf[100];
241
242   /* can it swap arguments? */
243   snprintf(buf, 100, "%2\$d %1\$d", 3, 4);
244   if (strcmp(buf, "4 3") != 0)
245     return 1;
246   return 0;
247 }]])],
248 [pgac_cv_snprintf_arg_control=yes],
249 [pgac_cv_snprintf_arg_control=no],
250 [pgac_cv_snprintf_arg_control=cross])
251 ])dnl AC_CACHE_VAL
252 AC_MSG_RESULT([$pgac_cv_snprintf_arg_control])
253 ])# PGAC_FUNC_SNPRINTF_ARG_CONTROL
254
255 # PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
256 # ---------------------------------------
257 # Determine if snprintf supports the z length modifier for printing
258 # size_t-sized variables. That's supported by C99 and POSIX but not
259 # all platforms play ball, so we must test whether it's working.
260 #
261 AC_DEFUN([PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT],
262 [AC_MSG_CHECKING([whether snprintf supports the %z modifier])
263 AC_CACHE_VAL(pgac_cv_snprintf_size_t_support,
264 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
265 #include <string.h>
266
267 int main()
268 {
269   char bufz[100];
270   char buf64[100];
271
272   /*
273    * Print the largest unsigned number fitting in a size_t using both %zu
274    * and the previously-determined format for 64-bit integers.  Note that
275    * we don't run this code unless we know snprintf handles 64-bit ints.
276    */
277   bufz[0] = '\0';  /* in case snprintf fails to emit anything */
278   snprintf(bufz, sizeof(bufz), "%zu", ~((size_t) 0));
279   snprintf(buf64, sizeof(buf64), "%" INT64_MODIFIER "u",
280     (unsigned PG_INT64_TYPE) ~((size_t) 0));
281   if (strcmp(bufz, buf64) != 0)
282     return 1;
283   return 0;
284 }]])],
285 [pgac_cv_snprintf_size_t_support=yes],
286 [pgac_cv_snprintf_size_t_support=no],
287 [pgac_cv_snprintf_size_t_support=cross])
288 ])dnl AC_CACHE_VAL
289 AC_MSG_RESULT([$pgac_cv_snprintf_size_t_support])
290 ])# PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
291
292
293 # PGAC_TYPE_LOCALE_T
294 # ------------------
295 # Check for the locale_t type and find the right header file.  Mac OS
296 # X needs xlocale.h; standard is locale.h, but glibc also has an
297 # xlocale.h file that we should not use.
298 #
299 AC_DEFUN([PGAC_TYPE_LOCALE_T],
300 [AC_CACHE_CHECK([for locale_t], pgac_cv_type_locale_t,
301 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
302 [#include <locale.h>
303 locale_t x;],
304 [])],
305 [pgac_cv_type_locale_t=yes],
306 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
307 [#include <xlocale.h>
308 locale_t x;],
309 [])],
310 [pgac_cv_type_locale_t='yes (in xlocale.h)'],
311 [pgac_cv_type_locale_t=no])])])
312 if test "$pgac_cv_type_locale_t" != no; then
313   AC_DEFINE(HAVE_LOCALE_T, 1,
314             [Define to 1 if the system has the type `locale_t'.])
315 fi
316 if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
317   AC_DEFINE(LOCALE_T_IN_XLOCALE, 1,
318             [Define to 1 if `locale_t' requires <xlocale.h>.])
319 fi])])# PGAC_HEADER_XLOCALE