OSDN Git Service

Minor editing for README-SSI.
[pg-rex/syncrep.git] / 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_TRY_LINK([#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,, [Define to 1 if you have the global variable 'int timezone'.])
22 fi])# PGAC_VAR_INT_TIMEZONE
23
24
25 # PGAC_STRUCT_TIMEZONE
26 # ------------------
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>
36 ])
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.])
41 fi
42 AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
43 [AC_TRY_LINK(
44 [#include <time.h>
45 #ifndef tzname /* For SGI.  */
46 extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
47 #endif
48 ],
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'.])
53 fi
54 ])# PGAC_STRUCT_TIMEZONE
55
56
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>],
65 [struct timeval *tp;
66 struct timezone *tzp;
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.])
72 fi
73 AH_VERBATIM(GETTIMEOFDAY_1ARG_,
74 [@%:@ifdef GETTIMEOFDAY_1ARG
75 @%:@ define gettimeofday(a,b) gettimeofday(a)
76 @%:@endif])dnl
77 ])# PGAC_FUNC_GETTIMEOFDAY_1ARG
78
79
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>
88 #include <pwd.h>],
89 [uid_t uid;
90 struct passwd *space;
91 char *buf;
92 size_t bufsize;
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.])
99 fi
100 ])# PGAC_FUNC_GETPWUID_R_5ARG
101
102
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>],
111 [#ifndef _AIX
112 int strerror_r(int, char *, size_t);
113 #else
114 /* Older AIX has 'int' for the third argument so we don't test the args. */
115 int strerror_r();
116 #endif],
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.])
121 fi
122 ])# PGAC_FUNC_STRERROR_R_INT
123
124
125 # PGAC_UNION_SEMUN
126 # ----------------
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>
133 #include <sys/ipc.h>
134 #include <sys/sem.h>])])# PGAC_UNION_SEMUN
135
136
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>
144 #ifdef HAVE_SYS_UN_H
145 #include <sys/un.h>
146 #endif
147 ])])# PGAC_STRUCT_SOCKADDR_UN
148
149
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>
159 #endif
160 ])])# PGAC_STRUCT_SOCKADDR_STORAGE
161
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>
178 #endif
179 ])])# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
180
181
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>
189 #include <netdb.h>
190 ])])# PGAC_STRUCT_ADDRINFO
191
192
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
197 # to yes or no.
198 #
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
201 # a fancier check.
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>
205 ],
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.])
214 fi
215 HAVE_POSIX_SIGNALS=$pgac_cv_func_posix_signals
216 AC_SUBST(HAVE_POSIX_SIGNALS)])# PGAC_FUNC_POSIX_SIGNALS
217
218
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.
224 #
225 # MinGW uses '%I64d', though gcc throws an warning with -Wall,
226 # while '%lld' doesn't generate a warning, but doesn't work.
227 #
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"
235
236 ac_int64 a = 20000001;
237 ac_int64 b = 40000005;
238
239 int does_int64_snprintf_work()
240 {
241   ac_int64 c;
242   char buf[100];
243
244   if (sizeof(ac_int64) != 8)
245     return 0;                   /* doesn't look like the right size */
246
247   c = a * b;
248   snprintf(buf, 100, INT64_FORMAT, c);
249   if (strcmp(buf, "800000140000005") != 0)
250     return 0;                   /* either multiply or snprintf is busted */
251   return 1;
252 }
253 main() {
254   exit(! does_int64_snprintf_work());
255 }],
256 [pgac_cv_snprintf_long_long_int_format=$pgac_format; break],
257 [],
258 [pgac_cv_snprintf_long_long_int_format=cross; break])
259 done])dnl AC_CACHE_VAL
260
261 LONG_LONG_INT_FORMAT=''
262
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
269
270
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.
277 #
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>
282 #include <string.h>
283
284 int main()
285 {
286   char buf[100];
287
288   /* can it swap arguments? */
289   snprintf(buf, 100, "%2\$d %1\$d", 3, 4);
290   if (strcmp(buf, "4 3") != 0)
291     return 1;
292   return 0;
293 }],
294 [pgac_cv_printf_arg_control=yes],
295 [pgac_cv_printf_arg_control=no],
296 [pgac_cv_printf_arg_control=cross])
297 ])dnl AC_CACHE_VAL
298 AC_MSG_RESULT([$pgac_cv_printf_arg_control])
299 ])# PGAC_FUNC_PRINTF_ARG_CONTROL
300
301
302 # PGAC_TYPE_LOCALE_T
303 # ------------------
304 # Check for the locale_t type and find the right header file.  Mac OS
305 # X needs xlocale.h; standard is locale.h, but glibc also has an
306 # xlocale.h file that we should not use.
307 #
308 AC_DEFUN([PGAC_TYPE_LOCALE_T],
309 [AC_CACHE_CHECK([for locale_t], pgac_cv_type_locale_t,
310 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
311 [#include <locale.h>
312 locale_t x;],
313 [])],
314 [pgac_cv_type_locale_t=yes],
315 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
316 [#include <xlocale.h>
317 locale_t x;],
318 [])],
319 [pgac_cv_type_locale_t='yes (in xlocale.h)'],
320 [pgac_cv_type_locale_t=no])])])
321 if test "$pgac_cv_type_locale_t" != no; then
322   AC_DEFINE(HAVE_LOCALE_T, 1,
323             [Define to 1 if the system has the type `locale_t'.])
324 fi
325 if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
326   AC_DEFINE(LOCALE_T_IN_XLOCALE, 1,
327             [Define to 1 if `locale_t' requires <xlocale.h>.])
328 fi])])# PGAC_HEADER_XLOCALE