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.
9AC_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>
12int res;],
13  [#ifndef __CYGWIN__
14res = timezone / 60;
15#else
16res = _timezone / 60;
17#endif])],
18  [pgac_cv_var_int_timezone=yes],
19  [pgac_cv_var_int_timezone=no])])
20if 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'.])
23fi])# 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.
33AC_DEFUN([PGAC_STRUCT_TIMEZONE],
34[AC_REQUIRE([AC_STRUCT_TM])dnl
35AC_CHECK_MEMBERS([struct tm.tm_zone],,,[#include <sys/types.h>
36#include <$ac_cv_struct_tm>
37])
38if 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.])
42fi
43AC_CACHE_CHECK(for tzname, ac_cv_var_tzname,
44[AC_LINK_IFELSE([AC_LANG_PROGRAM(
45[[#include <stdlib.h>
46#include <time.h>
47#ifndef tzname /* For SGI.  */
48extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
49#endif
50]],
51[atoi(*tzname);])], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)])
52if test $ac_cv_var_tzname = yes; then
53    AC_DEFINE(HAVE_TZNAME, 1,
54              [Define to 1 if you have the external array `tzname'.])
55fi
56])# PGAC_STRUCT_TIMEZONE
57
58
59# PGAC_FUNC_GETTIMEOFDAY_1ARG
60# ---------------------------
61# Check if gettimeofday() has only one arguments. (Normal is two.)
62# If so, define GETTIMEOFDAY_1ARG.
63AC_DEFUN([PGAC_FUNC_GETTIMEOFDAY_1ARG],
64[AC_CACHE_CHECK(whether gettimeofday takes only one argument,
65pgac_cv_func_gettimeofday_1arg,
66[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/time.h>],
67[struct timeval *tp;
68struct timezone *tzp;
69gettimeofday(tp,tzp);])],
70[pgac_cv_func_gettimeofday_1arg=no],
71[pgac_cv_func_gettimeofday_1arg=yes])])
72if test x"$pgac_cv_func_gettimeofday_1arg" = xyes ; then
73  AC_DEFINE(GETTIMEOFDAY_1ARG, 1,
74            [Define to 1 if gettimeofday() takes only 1 argument.])
75fi
76AH_VERBATIM(GETTIMEOFDAY_1ARG_,
77[@%:@ifdef GETTIMEOFDAY_1ARG
78@%:@ define gettimeofday(a,b) gettimeofday(a)
79@%:@endif])dnl
80])# PGAC_FUNC_GETTIMEOFDAY_1ARG
81
82
83# PGAC_FUNC_STRERROR_R_INT
84# ---------------------------
85# Check if strerror_r() returns int (POSIX) rather than char * (GNU libc).
86# If so, define STRERROR_R_INT.
87# The result is uncertain if strerror_r() isn't provided,
88# but we don't much care.
89AC_DEFUN([PGAC_FUNC_STRERROR_R_INT],
90[AC_CACHE_CHECK(whether strerror_r returns int,
91pgac_cv_func_strerror_r_int,
92[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <string.h>],
93[[char buf[100];
94  switch (strerror_r(1, buf, sizeof(buf)))
95  { case 0: break; default: break; }
96]])],
97[pgac_cv_func_strerror_r_int=yes],
98[pgac_cv_func_strerror_r_int=no])])
99if test x"$pgac_cv_func_strerror_r_int" = xyes ; then
100  AC_DEFINE(STRERROR_R_INT, 1,
101            [Define to 1 if strerror_r() returns int.])
102fi
103])# PGAC_FUNC_STRERROR_R_INT
104
105
106# PGAC_UNION_SEMUN
107# ----------------
108# Check if `union semun' exists. Define HAVE_UNION_SEMUN if so.
109# If it doesn't then one could define it as
110# union semun { int val; struct semid_ds *buf; unsigned short *array; }
111AC_DEFUN([PGAC_UNION_SEMUN],
112[AC_CHECK_TYPES([union semun], [], [],
113[#include <sys/types.h>
114#ifdef HAVE_SYS_IPC_H
115#include <sys/ipc.h>
116#endif
117#ifdef HAVE_SYS_SEM_H
118#include <sys/sem.h>
119#endif])])# PGAC_UNION_SEMUN
120
121
122# PGAC_STRUCT_SOCKADDR_UN
123# -----------------------
124# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS.
125# (Requires test for <sys/un.h>!)
126AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN],
127[AC_CHECK_TYPE([struct sockaddr_un], [AC_DEFINE(HAVE_UNIX_SOCKETS, 1, [Define to 1 if you have unix sockets.])], [],
128[#include <sys/types.h>
129#ifdef HAVE_SYS_UN_H
130#include <sys/un.h>
131#endif
132])])# PGAC_STRUCT_SOCKADDR_UN
133
134
135# PGAC_STRUCT_SOCKADDR_STORAGE
136# ----------------------------
137# If `struct sockaddr_storage' exists, define HAVE_STRUCT_SOCKADDR_STORAGE.
138# If it is missing then one could define it.
139AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE],
140[AC_CHECK_TYPES([struct sockaddr_storage], [], [],
141[#include <sys/types.h>
142#include <sys/socket.h>
143])])# PGAC_STRUCT_SOCKADDR_STORAGE
144
145# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
146# --------------------------------------
147# Check the members of `struct sockaddr_storage'.  We need to know about
148# ss_family and ss_len.  (Some platforms follow RFC 2553 and call them
149# __ss_family and __ss_len.)  We also check struct sockaddr's sa_len;
150# if we have to define our own `struct sockaddr_storage', this tells us
151# whether we need to provide an ss_len field.
152AC_DEFUN([PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS],
153[AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family,
154		   struct sockaddr_storage.__ss_family,
155		   struct sockaddr_storage.ss_len,
156		   struct sockaddr_storage.__ss_len,
157		   struct sockaddr.sa_len], [], [],
158[#include <sys/types.h>
159#include <sys/socket.h>
160])])# PGAC_STRUCT_SOCKADDR_STORAGE_MEMBERS
161
162
163# PGAC_STRUCT_ADDRINFO
164# -----------------------
165# If `struct addrinfo' exists, define HAVE_STRUCT_ADDRINFO.
166AC_DEFUN([PGAC_STRUCT_ADDRINFO],
167[AC_CHECK_TYPES([struct addrinfo], [], [],
168[#include <sys/types.h>
169#include <sys/socket.h>
170#include <netdb.h>
171])])# PGAC_STRUCT_ADDRINFO
172
173
174# PGAC_FUNC_SNPRINTF_ARG_CONTROL
175# ---------------------------------------
176# Determine if snprintf supports %1$ argument selection, e.g. %5$ selects
177# the fifth argument after the printf format string.
178# This is not in the C99 standard, but in the Single Unix Specification (SUS).
179# It is used in our language translation strings.
180#
181AC_DEFUN([PGAC_FUNC_SNPRINTF_ARG_CONTROL],
182[AC_MSG_CHECKING([whether snprintf supports argument control])
183AC_CACHE_VAL(pgac_cv_snprintf_arg_control,
184[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
185#include <string.h>
186
187int main()
188{
189  char buf[100];
190
191  /* can it swap arguments? */
192  snprintf(buf, 100, "%2\$d %1\$d", 3, 4);
193  if (strcmp(buf, "4 3") != 0)
194    return 1;
195  return 0;
196}]])],
197[pgac_cv_snprintf_arg_control=yes],
198[pgac_cv_snprintf_arg_control=no],
199[pgac_cv_snprintf_arg_control=cross])
200])dnl AC_CACHE_VAL
201AC_MSG_RESULT([$pgac_cv_snprintf_arg_control])
202])# PGAC_FUNC_SNPRINTF_ARG_CONTROL
203
204# PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
205# ---------------------------------------
206# Determine if snprintf supports the z length modifier for printing
207# size_t-sized variables. That's supported by C99 and POSIX but not
208# all platforms play ball, so we must test whether it's working.
209#
210AC_DEFUN([PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT],
211[AC_MSG_CHECKING([whether snprintf supports the %z modifier])
212AC_CACHE_VAL(pgac_cv_snprintf_size_t_support,
213[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdio.h>
214#include <string.h>
215
216int main()
217{
218  char bufz[100];
219  char buf64[100];
220
221  /*
222   * Print the largest unsigned number fitting in a size_t using both %zu
223   * and the previously-determined format for 64-bit integers.  Note that
224   * we don't run this code unless we know snprintf handles 64-bit ints.
225   */
226  bufz[0] = '\0';  /* in case snprintf fails to emit anything */
227  snprintf(bufz, sizeof(bufz), "%zu", ~((size_t) 0));
228  snprintf(buf64, sizeof(buf64), "%" INT64_MODIFIER "u",
229    (unsigned PG_INT64_TYPE) ~((size_t) 0));
230  if (strcmp(bufz, buf64) != 0)
231    return 1;
232  return 0;
233}]])],
234[pgac_cv_snprintf_size_t_support=yes],
235[pgac_cv_snprintf_size_t_support=no],
236[pgac_cv_snprintf_size_t_support=cross])
237])dnl AC_CACHE_VAL
238AC_MSG_RESULT([$pgac_cv_snprintf_size_t_support])
239])# PGAC_FUNC_SNPRINTF_SIZE_T_SUPPORT
240
241
242# PGAC_TYPE_LOCALE_T
243# ------------------
244# Check for the locale_t type and find the right header file.  macOS
245# needs xlocale.h; standard is locale.h, but glibc also has an
246# xlocale.h file that we should not use.
247#
248AC_DEFUN([PGAC_TYPE_LOCALE_T],
249[AC_CACHE_CHECK([for locale_t], pgac_cv_type_locale_t,
250[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
251[#include <locale.h>
252locale_t x;],
253[])],
254[pgac_cv_type_locale_t=yes],
255[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
256[#include <xlocale.h>
257locale_t x;],
258[])],
259[pgac_cv_type_locale_t='yes (in xlocale.h)'],
260[pgac_cv_type_locale_t=no])])])
261if test "$pgac_cv_type_locale_t" != no; then
262  AC_DEFINE(HAVE_LOCALE_T, 1,
263            [Define to 1 if the system has the type `locale_t'.])
264fi
265if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
266  AC_DEFINE(LOCALE_T_IN_XLOCALE, 1,
267            [Define to 1 if `locale_t' requires <xlocale.h>.])
268fi])# PGAC_TYPE_LOCALE_T
269
270
271# PGAC_FUNC_WCSTOMBS_L
272# --------------------
273# Try to find a declaration for wcstombs_l().  It might be in stdlib.h
274# (following the POSIX requirement for wcstombs()), or in locale.h, or in
275# xlocale.h.  If it's in the latter, define WCSTOMBS_L_IN_XLOCALE.
276#
277AC_DEFUN([PGAC_FUNC_WCSTOMBS_L],
278[AC_CACHE_CHECK([for wcstombs_l declaration], pgac_cv_func_wcstombs_l,
279[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
280[#include <stdlib.h>
281#include <locale.h>],
282[#ifndef wcstombs_l
283(void) wcstombs_l;
284#endif])],
285[pgac_cv_func_wcstombs_l='yes'],
286[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
287[#include <stdlib.h>
288#include <locale.h>
289#include <xlocale.h>],
290[#ifndef wcstombs_l
291(void) wcstombs_l;
292#endif])],
293[pgac_cv_func_wcstombs_l='yes (in xlocale.h)'],
294[pgac_cv_func_wcstombs_l='no'])])])
295if test "$pgac_cv_func_wcstombs_l" = 'yes (in xlocale.h)'; then
296  AC_DEFINE(WCSTOMBS_L_IN_XLOCALE, 1,
297            [Define to 1 if `wcstombs_l' requires <xlocale.h>.])
298fi])# PGAC_FUNC_WCSTOMBS_L
299