1 # Macros that test various C library quirks
5 # PGAC_VAR_INT_TIMEZONE
6 # ---------------------
7 # Check if the global variable `timezone' exists. If so, define
9 AC_DEFUN([PGAC_VAR_INT_TIMEZONE],
10 [AC_CACHE_CHECK(for int timezone, pgac_cv_var_int_timezone,
11 [AC_TRY_LINK([#include <time.h>
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,, [Define to 1 if you have the global variable 'int timezone'.])
22 fi])# PGAC_VAR_INT_TIMEZONE
25 # PGAC_STRUCT_TIMEZONE
27 # Figure out how to get the current timezone. If `struct tm' has a
28 # `tm_zone' member, define `HAVE_TM_ZONE'. Also, if the
29 # external array `tzname' is found, define `HAVE_TZNAME'.
30 # This is the same as the standard macro AC_STRUCT_TIMEZONE, except that
31 # tzname[] is checked for regardless of whether we find tm_zone.
32 AC_DEFUN([PGAC_STRUCT_TIMEZONE],
33 [AC_REQUIRE([AC_STRUCT_TM])dnl
34 AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
35 #include <$ac_cv_struct_tm>
37 if test "$ac_cv_member_struct_tm_tm_zone" = yes; then
38 AC_DEFINE(HAVE_TM_ZONE, 1,
39 [Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
40 `HAVE_STRUCT_TM_TM_ZONE' instead.])
42 AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
45 #ifndef tzname /* For SGI. */
46 extern char *tzname[]; /* RS6000 and others reject char **tzname. */
49 [atoi(*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)])
50 if test $ac_cv_var_tzname = yes; then
51 AC_DEFINE(HAVE_TZNAME, 1,
52 [Define to 1 if you have the external array `tzname'.])
54 ])# PGAC_STRUCT_TIMEZONE
57 # PGAC_FUNC_GETTIMEOFDAY_1ARG
58 # ---------------------------
59 # Check if gettimeofday() has only one arguments. (Normal is two.)
60 # If so, define GETTIMEOFDAY_1ARG.
61 AC_DEFUN([PGAC_FUNC_GETTIMEOFDAY_1ARG],
62 [AC_CACHE_CHECK(whether gettimeofday takes only one argument,
63 pgac_cv_func_gettimeofday_1arg,
64 [AC_TRY_COMPILE([#include <sys/time.h>],
67 gettimeofday(tp,tzp);],
68 [pgac_cv_func_gettimeofday_1arg=no],
69 [pgac_cv_func_gettimeofday_1arg=yes])])
70 if test x"$pgac_cv_func_gettimeofday_1arg" = xyes ; then
71 AC_DEFINE(GETTIMEOFDAY_1ARG,, [Define to 1 if gettimeofday() takes only 1 argument.])
73 AH_VERBATIM(GETTIMEOFDAY_1ARG_,
74 [@%:@ifdef GETTIMEOFDAY_1ARG
75 @%:@ define gettimeofday(a,b) gettimeofday(a)
77 ])# PGAC_FUNC_GETTIMEOFDAY_1ARG
80 # PGAC_FUNC_GETPWUID_R_5ARG
81 # ---------------------------
82 # Check if getpwuid_r() takes a fifth argument (later POSIX standard, not draft version)
83 # If so, define GETPWUID_R_5ARG
84 AC_DEFUN([PGAC_FUNC_GETPWUID_R_5ARG],
85 [AC_CACHE_CHECK(whether getpwuid_r takes a fifth argument,
86 pgac_cv_func_getpwuid_r_5arg,
87 [AC_TRY_COMPILE([#include <sys/types.h>
93 struct passwd **result;
94 getpwuid_r(uid, space, buf, bufsize, result);],
95 [pgac_cv_func_getpwuid_r_5arg=yes],
96 [pgac_cv_func_getpwuid_r_5arg=no])])
97 if test x"$pgac_cv_func_getpwuid_r_5arg" = xyes ; then
98 AC_DEFINE(GETPWUID_R_5ARG,, [Define to 1 if getpwuid_r() takes a 5th argument.])
100 ])# PGAC_FUNC_GETPWUID_R_5ARG
103 # PGAC_FUNC_STRERROR_R_INT
104 # ---------------------------
105 # Check if strerror_r() returns an int (SUSv3) rather than a char * (GNU libc)
106 # If so, define STRERROR_R_INT
107 AC_DEFUN([PGAC_FUNC_STRERROR_R_INT],
108 [AC_CACHE_CHECK(whether strerror_r returns int,
109 pgac_cv_func_strerror_r_int,
110 [AC_TRY_COMPILE([#include <string.h>],
112 int strerror_r(int, char *, size_t);
114 /* Older AIX has 'int' for the third argument so we don't test the args. */
117 [pgac_cv_func_strerror_r_int=yes],
118 [pgac_cv_func_strerror_r_int=no])])
119 if test x"$pgac_cv_func_strerror_r_int" = xyes ; then
120 AC_DEFINE(STRERROR_R_INT,, [Define to 1 if strerror_r() returns a int.])
122 ])# PGAC_FUNC_STRERROR_R_INT
127 # Check if `union semun' exists. Define HAVE_UNION_SEMUN if so.
128 # If it doesn't then one could define it as
129 # union semun { int val; struct semid_ds *buf; unsigned short *array; }
130 AC_DEFUN([PGAC_UNION_SEMUN],
131 [AC_CHECK_TYPES([union semun], [], [],
132 [#include <sys/types.h>
134 #include <sys/sem.h>])])# PGAC_UNION_SEMUN
137 # PGAC_STRUCT_SOCKADDR_UN
138 # -----------------------
139 # If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
140 # (Requires test for <sys/un.h>!)
141 AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
142 [AC_CHECK_TYPES([struct sockaddr_un], [AC_DEFINE(HAVE_UNIX_SOCKETS, 1, [Define to 1 if you have unix sockets.])], [],
143 [#include <sys/types.h>
147 ])])# PGAC_STRUCT_SOCKADDR_UN
150 # PGAC_STRUCT_SOCKADDR_STORAGE
151 # ----------------------------
152 # If `struct sockaddr_storage' exists, define HAVE_STRUCT_SOCKADDR_STORAGE.
153 # If it is missing then one could define it.
154 AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE],
155 [AC_CHECK_TYPES([struct sockaddr_storage], [], [],
156 [#include <sys/types.h>
157 #ifdef HAVE_SYS_SOCKET_H
158 #include <sys/socket.h>
160 ])])# PGAC_STRUCT_SOCKADDR_STORAGE
162 # PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
163 # --------------------------------------
164 # Check the members of `struct sockaddr_storage'. We need to know about
165 # ss_family and ss_len. (Some platforms follow RFC 2553 and call them
166 # __ss_family and __ss_len.) We also check struct sockaddr's sa_len;
167 # if we have to define our own `struct sockaddr_storage', this tells us
168 # whether we need to provide an ss_len field.
169 AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS],
170 [AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family,
171 struct sockaddr_storage.__ss_family,
172 struct sockaddr_storage.ss_len,
173 struct sockaddr_storage.__ss_len,
174 struct sockaddr.sa_len], [], [],
175 [#include <sys/types.h>
176 #ifdef HAVE_SYS_SOCKET_H
177 #include <sys/socket.h>
179 ])])# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
182 # PGAC_STRUCT_ADDRINFO
183 # -----------------------
184 # If `struct addrinfo' exists, define HAVE_STRUCT_ADDRINFO.
185 AC_DEFUN([PGAC_STRUCT_ADDRINFO],
186 [AC_CHECK_TYPES([struct addrinfo], [], [],
187 [#include <sys/types.h>
188 #include <sys/socket.h>
190 ])])# PGAC_STRUCT_ADDRINFO
193 # PGAC_FUNC_POSIX_SIGNALS
194 # -----------------------
195 # Check to see if the machine has the POSIX signal interface. Define
196 # HAVE_POSIX_SIGNALS if so. Also set the output variable HAVE_POSIX_SIGNALS
199 # Note that this test only compiles a test program, it doesn't check
200 # whether the routines actually work. If that becomes a problem, make
202 AC_DEFUN([PGAC_FUNC_POSIX_SIGNALS],
203 [AC_CACHE_CHECK(for POSIX signal interface, pgac_cv_func_posix_signals,
204 [AC_TRY_LINK([#include <signal.h>
206 [struct sigaction act, oact;
207 sigemptyset(&act.sa_mask);
208 act.sa_flags = SA_RESTART;
209 sigaction(0, &act, &oact);],
210 [pgac_cv_func_posix_signals=yes],
211 [pgac_cv_func_posix_signals=no])])
212 if test x"$pgac_cv_func_posix_signals" = xyes ; then
213 AC_DEFINE(HAVE_POSIX_SIGNALS,, [Define to 1 if you have the POSIX signal interface.])
215 HAVE_POSIX_SIGNALS=$pgac_cv_func_posix_signals
216 AC_SUBST(HAVE_POSIX_SIGNALS)])# PGAC_FUNC_POSIX_SIGNALS
219 # PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
220 # ---------------------------------------
221 # Determine which format snprintf uses for long long int. We handle
222 # %lld, %qd, %I64d. The result is in shell variable
223 # LONG_LONG_INT_FORMAT.
225 # MinGW uses '%I64d', though gcc throws an warning with -Wall,
226 # while '%lld' doesn't generate a warning, but doesn't work.
228 AC_DEFUN([PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT],
229 [AC_MSG_CHECKING([snprintf format for long long int])
230 AC_CACHE_VAL(pgac_cv_snprintf_long_long_int_format,
231 [for pgac_format in '%lld' '%qd' '%I64d'; do
232 AC_TRY_RUN([#include <stdio.h>
233 typedef long long int ac_int64;
234 #define INT64_FORMAT "$pgac_format"
236 ac_int64 a = 20000001;
237 ac_int64 b = 40000005;
239 int does_int64_snprintf_work()
244 if (sizeof(ac_int64) != 8)
245 return 0; /* doesn't look like the right size */
248 snprintf(buf, 100, INT64_FORMAT, c);
249 if (strcmp(buf, "800000140000005") != 0)
250 return 0; /* either multiply or snprintf is busted */
254 exit(! does_int64_snprintf_work());
256 [pgac_cv_snprintf_long_long_int_format=$pgac_format; break],
258 [pgac_cv_snprintf_long_long_int_format=cross; break])
259 done])dnl AC_CACHE_VAL
261 LONG_LONG_INT_FORMAT=''
263 case $pgac_cv_snprintf_long_long_int_format in
264 cross) AC_MSG_RESULT([cannot test (not on host machine)]);;
265 ?*) AC_MSG_RESULT([$pgac_cv_snprintf_long_long_int_format])
266 LONG_LONG_INT_FORMAT=$pgac_cv_snprintf_long_long_int_format;;
267 *) AC_MSG_RESULT(none);;
268 esac])# PGAC_FUNC_SNPRINTF_LONG_LONG_INT_FORMAT
271 # PGAC_FUNC_PRINTF_ARG_CONTROL
272 # ---------------------------------------
273 # Determine if printf supports %1$ argument selection, e.g. %5$ selects
274 # the fifth argument after the printf print string.
275 # This is not in the C99 standard, but in the Single Unix Specification (SUS).
276 # It is used in our language translation strings.
278 AC_DEFUN([PGAC_FUNC_PRINTF_ARG_CONTROL],
279 [AC_MSG_CHECKING([whether printf supports argument control])
280 AC_CACHE_VAL(pgac_cv_printf_arg_control,
281 [AC_TRY_RUN([#include <stdio.h>
288 /* can it swap arguments? */
289 snprintf(buf, 100, "%2\$d %1\$d", 3, 4);
290 if (strcmp(buf, "4 3") != 0)
294 [pgac_cv_printf_arg_control=yes],
295 [pgac_cv_printf_arg_control=no],
296 [pgac_cv_printf_arg_control=cross])
298 AC_MSG_RESULT([$pgac_cv_printf_arg_control])
299 ])# PGAC_FUNC_PRINTF_ARG_CONTROL