aboutsummaryrefslogtreecommitdiffstats
path: root/m4
diff options
context:
space:
mode:
authorPaul Eggert2012-06-22 14:26:37 -0700
committerPaul Eggert2012-06-22 14:26:37 -0700
commitc8fff8630133fea7c4e279458d10d825e5028c62 (patch)
treef8b8261fdf3596e1306a3d072e13ec572c9e3e65 /m4
parent36cec983d4e680e28e7066fda505910cd549f509 (diff)
downloademacs-c8fff8630133fea7c4e279458d10d825e5028c62.tar.gz
emacs-c8fff8630133fea7c4e279458d10d825e5028c62.zip
Add gnulib files to support higher-resolution time stamps.
Fixes: debbugs:9000
Diffstat (limited to 'm4')
-rw-r--r--m4/clock_time.m431
-rw-r--r--m4/gettime.m413
-rw-r--r--m4/gettimeofday.m4140
-rw-r--r--m4/pselect.m431
-rw-r--r--m4/stat-time.m485
-rw-r--r--m4/sys_select_h.m495
-rw-r--r--m4/sys_socket_h.m4177
-rw-r--r--m4/sys_time_h.m4106
-rw-r--r--m4/timespec.m415
-rw-r--r--m4/utimbuf.m439
-rw-r--r--m4/utimens.m450
-rw-r--r--m4/utimes.m4136
12 files changed, 918 insertions, 0 deletions
diff --git a/m4/clock_time.m4 b/m4/clock_time.m4
new file mode 100644
index 00000000000..0bec0ef860f
--- /dev/null
+++ b/m4/clock_time.m4
@@ -0,0 +1,31 @@
1# clock_time.m4 serial 10
2dnl Copyright (C) 2002-2006, 2009-2012 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7# Check for clock_gettime and clock_settime, and set LIB_CLOCK_GETTIME.
8# For a program named, say foo, you should add a line like the following
9# in the corresponding Makefile.am file:
10# foo_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
11
12AC_DEFUN([gl_CLOCK_TIME],
13[
14 dnl Persuade glibc and Solaris <time.h> to declare these functions.
15 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
16
17 # Solaris 2.5.1 needs -lposix4 to get the clock_gettime function.
18 # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
19
20 # Save and restore LIBS so e.g., -lrt, isn't added to it. Otherwise, *all*
21 # programs in the package would end up linked with that potentially-shared
22 # library, inducing unnecessary run-time overhead.
23 LIB_CLOCK_GETTIME=
24 AC_SUBST([LIB_CLOCK_GETTIME])
25 gl_saved_libs=$LIBS
26 AC_SEARCH_LIBS([clock_gettime], [rt posix4],
27 [test "$ac_cv_search_clock_gettime" = "none required" ||
28 LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime])
29 AC_CHECK_FUNCS([clock_gettime clock_settime])
30 LIBS=$gl_saved_libs
31])
diff --git a/m4/gettime.m4 b/m4/gettime.m4
new file mode 100644
index 00000000000..7d03d1253bf
--- /dev/null
+++ b/m4/gettime.m4
@@ -0,0 +1,13 @@
1# gettime.m4 serial 8
2dnl Copyright (C) 2002, 2004-2006, 2009-2012 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_GETTIME],
8[
9 dnl Prerequisites of lib/gettime.c.
10 AC_REQUIRE([gl_CLOCK_TIME])
11 AC_REQUIRE([gl_TIMESPEC])
12 AC_CHECK_FUNCS_ONCE([gettimeofday nanotime])
13])
diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4
new file mode 100644
index 00000000000..eda97027a92
--- /dev/null
+++ b/m4/gettimeofday.m4
@@ -0,0 +1,140 @@
1# serial 20
2
3# Copyright (C) 2001-2003, 2005, 2007, 2009-2012 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved.
7
8dnl From Jim Meyering.
9
10AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
11[
12 AC_REQUIRE([AC_C_RESTRICT])
13 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
14 AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
15 AC_CHECK_FUNCS_ONCE([gettimeofday])
16
17 gl_gettimeofday_timezone=void
18 if test $ac_cv_func_gettimeofday != yes; then
19 HAVE_GETTIMEOFDAY=0
20 else
21 gl_FUNC_GETTIMEOFDAY_CLOBBER
22 AC_CACHE_CHECK([for gettimeofday with POSIX signature],
23 [gl_cv_func_gettimeofday_posix_signature],
24 [AC_COMPILE_IFELSE(
25 [AC_LANG_PROGRAM(
26 [[#include <sys/time.h>
27 struct timeval c;
28 int gettimeofday (struct timeval *restrict, void *restrict);
29 ]],
30 [[/* glibc uses struct timezone * rather than the POSIX void *
31 if _GNU_SOURCE is defined. However, since the only portable
32 use of gettimeofday uses NULL as the second parameter, and
33 since the glibc definition is actually more typesafe, it is
34 not worth wrapping this to get a compliant signature. */
35 int (*f) (struct timeval *restrict, void *restrict)
36 = gettimeofday;
37 int x = f (&c, 0);
38 return !(x | c.tv_sec | c.tv_usec);
39 ]])],
40 [gl_cv_func_gettimeofday_posix_signature=yes],
41 [AC_COMPILE_IFELSE(
42 [AC_LANG_PROGRAM(
43 [[#include <sys/time.h>
44int gettimeofday (struct timeval *restrict, struct timezone *restrict);
45 ]])],
46 [gl_cv_func_gettimeofday_posix_signature=almost],
47 [gl_cv_func_gettimeofday_posix_signature=no])])])
48 if test $gl_cv_func_gettimeofday_posix_signature = almost; then
49 gl_gettimeofday_timezone='struct timezone'
50 elif test $gl_cv_func_gettimeofday_posix_signature != yes; then
51 REPLACE_GETTIMEOFDAY=1
52 fi
53 dnl If we override 'struct timeval', we also have to override gettimeofday.
54 if test $REPLACE_STRUCT_TIMEVAL = 1; then
55 REPLACE_GETTIMEOFDAY=1
56 fi
57 m4_ifdef([gl_FUNC_TZSET_CLOBBER], [
58 gl_FUNC_TZSET_CLOBBER
59 case "$gl_cv_func_tzset_clobber" in
60 *yes)
61 REPLACE_GETTIMEOFDAY=1
62 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
63 AC_DEFINE([tzset], [rpl_tzset],
64 [Define to rpl_tzset if the wrapper function should be used.])
65 AC_DEFINE([TZSET_CLOBBERS_LOCALTIME], [1],
66 [Define if tzset clobbers localtime's static buffer.])
67 ;;
68 esac
69 ])
70 fi
71 AC_DEFINE_UNQUOTED([GETTIMEOFDAY_TIMEZONE], [$gl_gettimeofday_timezone],
72 [Define this to 'void' or 'struct timezone' to match the system's
73 declaration of the second argument to gettimeofday.])
74])
75
76
77dnl See if gettimeofday clobbers the static buffer that localtime uses
78dnl for its return value. The gettimeofday function from Mac OS X 10.0.4
79dnl (i.e., Darwin 1.3.7) has this problem.
80dnl
81dnl If it does, then arrange to use gettimeofday and localtime only via
82dnl the wrapper functions that work around the problem.
83
84AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
85[
86 AC_REQUIRE([gl_HEADER_SYS_TIME_H])
87 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
88
89 AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer],
90 [gl_cv_func_gettimeofday_clobber],
91 [AC_RUN_IFELSE(
92 [AC_LANG_PROGRAM(
93 [[#include <string.h>
94 #include <sys/time.h>
95 #include <time.h>
96 #include <stdlib.h>
97 ]],
98 [[
99 time_t t = 0;
100 struct tm *lt;
101 struct tm saved_lt;
102 struct timeval tv;
103 lt = localtime (&t);
104 saved_lt = *lt;
105 gettimeofday (&tv, NULL);
106 return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0;
107 ]])],
108 [gl_cv_func_gettimeofday_clobber=no],
109 [gl_cv_func_gettimeofday_clobber=yes],
110 [# When cross-compiling:
111 case "$host_os" in
112 # Guess all is fine on glibc systems.
113 *-gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;;
114 # If we don't know, assume the worst.
115 *) gl_cv_func_gettimeofday_clobber="guessing yes" ;;
116 esac
117 ])])
118
119 case "$gl_cv_func_gettimeofday_clobber" in
120 *yes)
121 REPLACE_GETTIMEOFDAY=1
122 gl_GETTIMEOFDAY_REPLACE_LOCALTIME
123 AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
124 [Define if gettimeofday clobbers the localtime buffer.])
125 ;;
126 esac
127])
128
129AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
130 AC_DEFINE([gmtime], [rpl_gmtime],
131 [Define to rpl_gmtime if the replacement function should be used.])
132 AC_DEFINE([localtime], [rpl_localtime],
133 [Define to rpl_localtime if the replacement function should be used.])
134])
135
136# Prerequisites of lib/gettimeofday.c.
137AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [
138 AC_CHECK_HEADERS([sys/timeb.h])
139 AC_CHECK_FUNCS([_ftime])
140])
diff --git a/m4/pselect.m4 b/m4/pselect.m4
new file mode 100644
index 00000000000..97bf12cd2d6
--- /dev/null
+++ b/m4/pselect.m4
@@ -0,0 +1,31 @@
1# pselect.m4
2dnl Copyright (C) 2011-2012 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_FUNC_PSELECT],
8[
9 AC_REQUIRE([gl_HEADER_SYS_SELECT])
10 AC_REQUIRE([AC_C_RESTRICT])
11 AC_CHECK_FUNCS_ONCE([pselect])
12
13 if test $ac_cv_func_pselect = yes; then
14 AC_CACHE_CHECK([whether signature of pselect conforms to POSIX],
15 gl_cv_sig_pselect,
16 [AC_LINK_IFELSE(
17 [AC_LANG_PROGRAM(
18 [[#include <sys/select.h>
19 ]],
20 [[int (*p) (int, fd_set *, fd_set *, fd_set *restrict,
21 struct timespec const *restrict,
22 sigset_t const *restrict) = pselect;
23 return !p;]])],
24 [gl_cv_sig_pselect=yes],
25 [gl_cv_sig_pselect=no])])
26 fi
27
28 if test $ac_cv_func_pselect = no || test $gl_cv_sig_pselect = no; then
29 REPLACE_PSELECT=1
30 fi
31])
diff --git a/m4/stat-time.m4 b/m4/stat-time.m4
new file mode 100644
index 00000000000..2dbb1f3c752
--- /dev/null
+++ b/m4/stat-time.m4
@@ -0,0 +1,85 @@
1# Checks for stat-related time functions.
2
3# Copyright (C) 1998-1999, 2001, 2003, 2005-2007, 2009-2012 Free Software
4# Foundation, Inc.
5
6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it,
8# with or without modifications, as long as this notice is preserved.
9
10dnl From Paul Eggert.
11
12# st_atim.tv_nsec - Linux, Solaris, Cygwin
13# st_atimespec.tv_nsec - FreeBSD, NetBSD, if ! defined _POSIX_SOURCE
14# st_atimensec - FreeBSD, NetBSD, if defined _POSIX_SOURCE
15# st_atim.st__tim.tv_nsec - UnixWare (at least 2.1.2 through 7.1)
16
17# st_birthtimespec - FreeBSD, NetBSD (hidden on OpenBSD 3.9, anyway)
18# st_birthtim - Cygwin 1.7.0+
19
20AC_DEFUN([gl_STAT_TIME],
21[
22 AC_REQUIRE([AC_C_INLINE])
23 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
24 AC_CHECK_HEADERS_ONCE([sys/time.h])
25
26 AC_CHECK_MEMBERS([struct stat.st_atim.tv_nsec],
27 [AC_CACHE_CHECK([whether struct stat.st_atim is of type struct timespec],
28 [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec],
29 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
30 [[
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #if HAVE_SYS_TIME_H
34 # include <sys/time.h>
35 #endif
36 #include <time.h>
37 struct timespec ts;
38 struct stat st;
39 ]],
40 [[
41 st.st_atim = ts;
42 ]])],
43 [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=yes],
44 [ac_cv_typeof_struct_stat_st_atim_is_struct_timespec=no])])
45 if test $ac_cv_typeof_struct_stat_st_atim_is_struct_timespec = yes; then
46 AC_DEFINE([TYPEOF_STRUCT_STAT_ST_ATIM_IS_STRUCT_TIMESPEC], [1],
47 [Define to 1 if the type of the st_atim member of a struct stat is
48 struct timespec.])
49 fi],
50 [AC_CHECK_MEMBERS([struct stat.st_atimespec.tv_nsec], [],
51 [AC_CHECK_MEMBERS([struct stat.st_atimensec], [],
52 [AC_CHECK_MEMBERS([struct stat.st_atim.st__tim.tv_nsec], [], [],
53 [#include <sys/types.h>
54 #include <sys/stat.h>])],
55 [#include <sys/types.h>
56 #include <sys/stat.h>])],
57 [#include <sys/types.h>
58 #include <sys/stat.h>])],
59 [#include <sys/types.h>
60 #include <sys/stat.h>])
61])
62
63# Check for st_birthtime, a feature from UFS2 (FreeBSD, NetBSD, OpenBSD, etc.)
64# and NTFS (Cygwin).
65# There was a time when this field was named st_createtime (21 June
66# 2002 to 16 July 2002) But that window is very small and applied only
67# to development code, so systems still using that configuration are
68# not supported. See revisions 1.10 and 1.11 of FreeBSD's
69# src/sys/ufs/ufs/dinode.h.
70#
71AC_DEFUN([gl_STAT_BIRTHTIME],
72[
73 AC_REQUIRE([AC_C_INLINE])
74 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
75 AC_CHECK_HEADERS_ONCE([sys/time.h])
76 AC_CHECK_MEMBERS([struct stat.st_birthtimespec.tv_nsec], [],
77 [AC_CHECK_MEMBERS([struct stat.st_birthtimensec], [],
78 [AC_CHECK_MEMBERS([struct stat.st_birthtim.tv_nsec], [], [],
79 [#include <sys/types.h>
80 #include <sys/stat.h>])],
81 [#include <sys/types.h>
82 #include <sys/stat.h>])],
83 [#include <sys/types.h>
84 #include <sys/stat.h>])
85])
diff --git a/m4/sys_select_h.m4 b/m4/sys_select_h.m4
new file mode 100644
index 00000000000..eaf056a79a2
--- /dev/null
+++ b/m4/sys_select_h.m4
@@ -0,0 +1,95 @@
1# sys_select_h.m4 serial 20
2dnl Copyright (C) 2006-2012 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7AC_DEFUN([gl_HEADER_SYS_SELECT],
8[
9 AC_REQUIRE([AC_C_RESTRICT])
10 AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
11 AC_CACHE_CHECK([whether <sys/select.h> is self-contained],
12 [gl_cv_header_sys_select_h_selfcontained],
13 [
14 dnl Test against two bugs:
15 dnl 1. On many platforms, <sys/select.h> assumes prior inclusion of
16 dnl <sys/types.h>.
17 dnl 2. On OSF/1 4.0, <sys/select.h> provides only a forward declaration
18 dnl of 'struct timeval', and no definition of this type.
19 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/select.h>]],
20 [[struct timeval b;]])],
21 [gl_cv_header_sys_select_h_selfcontained=yes],
22 [gl_cv_header_sys_select_h_selfcontained=no])
23 dnl Test against another bug:
24 dnl 3. On Solaris 10, <sys/select.h> provides an FD_ZERO implementation
25 dnl that relies on memset(), but without including <string.h>.
26 if test $gl_cv_header_sys_select_h_selfcontained = yes; then
27 AC_COMPILE_IFELSE(
28 [AC_LANG_PROGRAM([[#include <sys/select.h>]],
29 [[int memset; int bzero;]])
30 ],
31 [AC_LINK_IFELSE(
32 [AC_LANG_PROGRAM([[#include <sys/select.h>]], [[
33 #undef memset
34 #define memset nonexistent_memset
35 extern
36 #ifdef __cplusplus
37 "C"
38 #endif
39 void *memset (void *, int, unsigned long);
40 #undef bzero
41 #define bzero nonexistent_bzero
42 extern
43 #ifdef __cplusplus
44 "C"
45 #endif
46 void bzero (void *, unsigned long);
47 fd_set fds;
48 FD_ZERO (&fds);
49 ]])
50 ],
51 [],
52 [gl_cv_header_sys_select_h_selfcontained=no])
53 ])
54 fi
55 ])
56 dnl <sys/select.h> is always overridden, because of GNULIB_POSIXCHECK.
57 gl_CHECK_NEXT_HEADERS([sys/select.h])
58 if test $ac_cv_header_sys_select_h = yes; then
59 HAVE_SYS_SELECT_H=1
60 else
61 HAVE_SYS_SELECT_H=0
62 fi
63 AC_SUBST([HAVE_SYS_SELECT_H])
64 gl_PREREQ_SYS_H_WINSOCK2
65
66 dnl Check for declarations of anything we want to poison if the
67 dnl corresponding gnulib module is not in use.
68 gl_WARN_ON_USE_PREPARE([[
69/* Some systems require prerequisite headers. */
70#include <sys/types.h>
71#if !(defined __GLIBC__ && !defined __UCLIBC__) && HAVE_SYS_TIME_H
72# include <sys/time.h>
73#endif
74#include <sys/select.h>
75 ]], [pselect select])
76])
77
78AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
79[
80 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
81 AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
82 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
83 dnl Define it also as a C macro, for the benefit of the unit tests.
84 gl_MODULE_INDICATOR_FOR_TESTS([$1])
85])
86
87AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
88[
89 GNULIB_PSELECT=0; AC_SUBST([GNULIB_PSELECT])
90 GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT])
91 dnl Assume proper GNU behavior unless another module says otherwise.
92 HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT])
93 REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT])
94 REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
95])
diff --git a/m4/sys_socket_h.m4 b/m4/sys_socket_h.m4
new file mode 100644
index 00000000000..8d4e7e1ebb4
--- /dev/null
+++ b/m4/sys_socket_h.m4
@@ -0,0 +1,177 @@
1# sys_socket_h.m4 serial 22
2dnl Copyright (C) 2005-2012 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved.
6
7dnl From Simon Josefsson.
8
9AC_DEFUN([gl_HEADER_SYS_SOCKET],
10[
11 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 AC_REQUIRE([AC_C_INLINE])
14
15 dnl On OSF/1, the functions recv(), send(), recvfrom(), sendto() have
16 dnl old-style declarations (with return type 'int' instead of 'ssize_t')
17 dnl unless _POSIX_PII_SOCKET is defined.
18 case "$host_os" in
19 osf*)
20 AC_DEFINE([_POSIX_PII_SOCKET], [1],
21 [Define to 1 in order to get the POSIX compatible declarations
22 of socket functions.])
23 ;;
24 esac
25
26 AC_CACHE_CHECK([whether <sys/socket.h> is self-contained],
27 [gl_cv_header_sys_socket_h_selfcontained],
28 [
29 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]], [[]])],
30 [gl_cv_header_sys_socket_h_selfcontained=yes],
31 [gl_cv_header_sys_socket_h_selfcontained=no])
32 ])
33 if test $gl_cv_header_sys_socket_h_selfcontained = yes; then
34 dnl If the shutdown function exists, <sys/socket.h> should define
35 dnl SHUT_RD, SHUT_WR, SHUT_RDWR.
36 AC_CHECK_FUNCS([shutdown])
37 if test $ac_cv_func_shutdown = yes; then
38 AC_CACHE_CHECK([whether <sys/socket.h> defines the SHUT_* macros],
39 [gl_cv_header_sys_socket_h_shut],
40 [
41 AC_COMPILE_IFELSE(
42 [AC_LANG_PROGRAM([[#include <sys/socket.h>]],
43 [[int a[] = { SHUT_RD, SHUT_WR, SHUT_RDWR };]])],
44 [gl_cv_header_sys_socket_h_shut=yes],
45 [gl_cv_header_sys_socket_h_shut=no])
46 ])
47 if test $gl_cv_header_sys_socket_h_shut = no; then
48 SYS_SOCKET_H='sys/socket.h'
49 fi
50 fi
51 fi
52 # We need to check for ws2tcpip.h now.
53 gl_PREREQ_SYS_H_SOCKET
54 AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
55 /* sys/types.h is not needed according to POSIX, but the
56 sys/socket.h in i386-unknown-freebsd4.10 and
57 powerpc-apple-darwin5.5 required it. */
58#include <sys/types.h>
59#ifdef HAVE_SYS_SOCKET_H
60#include <sys/socket.h>
61#endif
62#ifdef HAVE_WS2TCPIP_H
63#include <ws2tcpip.h>
64#endif
65])
66 if test $ac_cv_type_struct_sockaddr_storage = no; then
67 HAVE_STRUCT_SOCKADDR_STORAGE=0
68 fi
69 if test $ac_cv_type_sa_family_t = no; then
70 HAVE_SA_FAMILY_T=0
71 fi
72 if test $ac_cv_type_struct_sockaddr_storage != no; then
73 AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
74 [],
75 [HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=0],
76 [#include <sys/types.h>
77 #ifdef HAVE_SYS_SOCKET_H
78 #include <sys/socket.h>
79 #endif
80 #ifdef HAVE_WS2TCPIP_H
81 #include <ws2tcpip.h>
82 #endif
83 ])
84 fi
85 if test $HAVE_STRUCT_SOCKADDR_STORAGE = 0 || test $HAVE_SA_FAMILY_T = 0 \
86 || test $HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY = 0; then
87 SYS_SOCKET_H='sys/socket.h'
88 fi
89 gl_PREREQ_SYS_H_WINSOCK2
90
91 dnl Check for declarations of anything we want to poison if the
92 dnl corresponding gnulib module is not in use.
93 gl_WARN_ON_USE_PREPARE([[
94/* Some systems require prerequisite headers. */
95#include <sys/types.h>
96#include <sys/socket.h>
97 ]], [socket connect accept bind getpeername getsockname getsockopt
98 listen recv send recvfrom sendto setsockopt shutdown accept4])
99])
100
101AC_DEFUN([gl_PREREQ_SYS_H_SOCKET],
102[
103 dnl Check prerequisites of the <sys/socket.h> replacement.
104 AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
105 gl_CHECK_NEXT_HEADERS([sys/socket.h])
106 if test $ac_cv_header_sys_socket_h = yes; then
107 HAVE_SYS_SOCKET_H=1
108 HAVE_WS2TCPIP_H=0
109 else
110 HAVE_SYS_SOCKET_H=0
111 if test $ac_cv_header_ws2tcpip_h = yes; then
112 HAVE_WS2TCPIP_H=1
113 else
114 HAVE_WS2TCPIP_H=0
115 fi
116 fi
117 AC_SUBST([HAVE_SYS_SOCKET_H])
118 AC_SUBST([HAVE_WS2TCPIP_H])
119])
120
121# Common prerequisites of the <sys/socket.h> replacement and of the
122# <sys/select.h> replacement.
123# Sets and substitutes HAVE_WINSOCK2_H.
124AC_DEFUN([gl_PREREQ_SYS_H_WINSOCK2],
125[
126 m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
127 m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
128 AC_CHECK_HEADERS_ONCE([sys/socket.h])
129 if test $ac_cv_header_sys_socket_h != yes; then
130 dnl We cannot use AC_CHECK_HEADERS_ONCE here, because that would make
131 dnl the check for those headers unconditional; yet cygwin reports
132 dnl that the headers are present but cannot be compiled (since on
133 dnl cygwin, all socket information should come from sys/socket.h).
134 AC_CHECK_HEADERS([winsock2.h])
135 fi
136 if test "$ac_cv_header_winsock2_h" = yes; then
137 HAVE_WINSOCK2_H=1
138 UNISTD_H_HAVE_WINSOCK2_H=1
139 SYS_IOCTL_H_HAVE_WINSOCK2_H=1
140 else
141 HAVE_WINSOCK2_H=0
142 fi
143 AC_SUBST([HAVE_WINSOCK2_H])
144])
145
146AC_DEFUN([gl_SYS_SOCKET_MODULE_INDICATOR],
147[
148 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
149 AC_REQUIRE([gl_SYS_SOCKET_H_DEFAULTS])
150 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
151 dnl Define it also as a C macro, for the benefit of the unit tests.
152 gl_MODULE_INDICATOR_FOR_TESTS([$1])
153])
154
155AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
156[
157 GNULIB_SOCKET=0; AC_SUBST([GNULIB_SOCKET])
158 GNULIB_CONNECT=0; AC_SUBST([GNULIB_CONNECT])
159 GNULIB_ACCEPT=0; AC_SUBST([GNULIB_ACCEPT])
160 GNULIB_BIND=0; AC_SUBST([GNULIB_BIND])
161 GNULIB_GETPEERNAME=0; AC_SUBST([GNULIB_GETPEERNAME])
162 GNULIB_GETSOCKNAME=0; AC_SUBST([GNULIB_GETSOCKNAME])
163 GNULIB_GETSOCKOPT=0; AC_SUBST([GNULIB_GETSOCKOPT])
164 GNULIB_LISTEN=0; AC_SUBST([GNULIB_LISTEN])
165 GNULIB_RECV=0; AC_SUBST([GNULIB_RECV])
166 GNULIB_SEND=0; AC_SUBST([GNULIB_SEND])
167 GNULIB_RECVFROM=0; AC_SUBST([GNULIB_RECVFROM])
168 GNULIB_SENDTO=0; AC_SUBST([GNULIB_SENDTO])
169 GNULIB_SETSOCKOPT=0; AC_SUBST([GNULIB_SETSOCKOPT])
170 GNULIB_SHUTDOWN=0; AC_SUBST([GNULIB_SHUTDOWN])
171 GNULIB_ACCEPT4=0; AC_SUBST([GNULIB_ACCEPT4])
172 HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
173 HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
174 AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
175 HAVE_SA_FAMILY_T=1; AC_SUBST([HAVE_SA_FAMILY_T])
176 HAVE_ACCEPT4=1; AC_SUBST([HAVE_ACCEPT4])
177])
diff --git a/m4/sys_time_h.m4 b/m4/sys_time_h.m4
new file mode 100644
index 00000000000..26eaf8ea7f3
--- /dev/null
+++ b/m4/sys_time_h.m4
@@ -0,0 +1,106 @@
1# Configure a replacement for <sys/time.h>.
2# serial 8
3
4# Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8
9# Written by Paul Eggert and Martin Lambers.
10
11AC_DEFUN([gl_HEADER_SYS_TIME_H],
12[
13 dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
14 dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
15 dnl statements that occur in other macros.
16 AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
17])
18
19AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
20[
21 AC_REQUIRE([AC_C_RESTRICT])
22 AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
23 AC_CHECK_HEADERS_ONCE([sys/time.h])
24 gl_CHECK_NEXT_HEADERS([sys/time.h])
25
26 if test $ac_cv_header_sys_time_h != yes; then
27 HAVE_SYS_TIME_H=0
28 fi
29
30 dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
31 dnl only. So include that header in the list.
32 gl_PREREQ_SYS_H_WINSOCK2
33 AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
34 [AC_COMPILE_IFELSE(
35 [AC_LANG_PROGRAM(
36 [[#if HAVE_SYS_TIME_H
37 #include <sys/time.h>
38 #endif
39 #include <time.h>
40 #if HAVE_WINSOCK2_H
41 # include <winsock2.h>
42 #endif
43 ]],
44 [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
45 [gl_cv_sys_struct_timeval=yes],
46 [gl_cv_sys_struct_timeval=no])
47 ])
48 if test $gl_cv_sys_struct_timeval != yes; then
49 HAVE_STRUCT_TIMEVAL=0
50 else
51 dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
52 dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
53 dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
54 dnl smaller than the 'time_t' type mandated by POSIX.
55 AC_CACHE_CHECK([for correct struct timeval.tv_sec member],
56 [gl_cv_sys_struct_timeval_tv_sec],
57 [AC_COMPILE_IFELSE(
58 [AC_LANG_PROGRAM(
59 [[#if HAVE_SYS_TIME_H
60 #include <sys/time.h>
61 #endif
62 #include <time.h>
63 #if HAVE_WINSOCK2_H
64 # include <winsock2.h>
65 #endif
66 ]],
67 [[static struct timeval x;
68 typedef int verify_tv_sec_type[sizeof (x.tv_sec) == sizeof (time_t) ? 1 : -1];
69 ]])],
70 [gl_cv_sys_struct_timeval_tv_sec=yes],
71 [gl_cv_sys_struct_timeval_tv_sec=no])
72 ])
73 if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
74 REPLACE_STRUCT_TIMEVAL=1
75 fi
76 fi
77
78 dnl Check for declarations of anything we want to poison if the
79 dnl corresponding gnulib module is not in use.
80 gl_WARN_ON_USE_PREPARE([[
81#if HAVE_SYS_TIME_H
82# include <sys/time.h>
83#endif
84#include <time.h>
85 ]], [gettimeofday])
86])
87
88AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
89[
90 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
91 AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
92 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
93 dnl Define it also as a C macro, for the benefit of the unit tests.
94 gl_MODULE_INDICATOR_FOR_TESTS([$1])
95])
96
97AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
98[
99 GNULIB_GETTIMEOFDAY=0; AC_SUBST([GNULIB_GETTIMEOFDAY])
100 dnl Assume POSIX behavior unless another module says otherwise.
101 HAVE_GETTIMEOFDAY=1; AC_SUBST([HAVE_GETTIMEOFDAY])
102 HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL])
103 HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H])
104 REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY])
105 REPLACE_STRUCT_TIMEVAL=0; AC_SUBST([REPLACE_STRUCT_TIMEVAL])
106])
diff --git a/m4/timespec.m4 b/m4/timespec.m4
new file mode 100644
index 00000000000..597b9c2d1af
--- /dev/null
+++ b/m4/timespec.m4
@@ -0,0 +1,15 @@
1#serial 14
2
3# Copyright (C) 2000-2001, 2003-2007, 2009-2012 Free Software Foundation, Inc.
4
5# This file is free software; the Free Software Foundation
6# gives unlimited permission to copy and/or distribute it,
7# with or without modifications, as long as this notice is preserved.
8
9dnl From Jim Meyering
10
11AC_DEFUN([gl_TIMESPEC],
12[
13 dnl Prerequisites of lib/timespec.h.
14 AC_REQUIRE([AC_C_INLINE])
15])
diff --git a/m4/utimbuf.m4 b/m4/utimbuf.m4
new file mode 100644
index 00000000000..25eb85b326e
--- /dev/null
+++ b/m4/utimbuf.m4
@@ -0,0 +1,39 @@
1# serial 9
2
3# Copyright (C) 1998-2001, 2003-2004, 2007, 2009-2012 Free Software Foundation,
4# Inc.
5#
6# This file is free software; the Free Software Foundation
7# gives unlimited permission to copy and/or distribute it,
8# with or without modifications, as long as this notice is preserved.
9
10dnl From Jim Meyering
11
12dnl Define HAVE_STRUCT_UTIMBUF if 'struct utimbuf' is declared --
13dnl usually in <utime.h>.
14dnl Some systems have utime.h but don't declare the struct anywhere.
15
16AC_DEFUN([gl_CHECK_TYPE_STRUCT_UTIMBUF],
17[
18 AC_CHECK_HEADERS_ONCE([sys/time.h utime.h])
19 AC_CACHE_CHECK([for struct utimbuf], [gl_cv_sys_struct_utimbuf],
20 [AC_COMPILE_IFELSE(
21 [AC_LANG_PROGRAM(
22 [[#if HAVE_SYS_TIME_H
23 #include <sys/time.h>
24 #endif
25 #include <time.h>
26 #ifdef HAVE_UTIME_H
27 #include <utime.h>
28 #endif
29 ]],
30 [[static struct utimbuf x; x.actime = x.modtime;]])],
31 [gl_cv_sys_struct_utimbuf=yes],
32 [gl_cv_sys_struct_utimbuf=no])])
33
34 if test $gl_cv_sys_struct_utimbuf = yes; then
35 AC_DEFINE([HAVE_STRUCT_UTIMBUF], [1],
36 [Define if struct utimbuf is declared -- usually in <utime.h>.
37 Some systems have utime.h but don't declare the struct anywhere. ])
38 fi
39])
diff --git a/m4/utimens.m4 b/m4/utimens.m4
new file mode 100644
index 00000000000..6a8b6ab78c0
--- /dev/null
+++ b/m4/utimens.m4
@@ -0,0 +1,50 @@
1dnl Copyright (C) 2003-2012 Free Software Foundation, Inc.
2dnl This file is free software; the Free Software Foundation
3dnl gives unlimited permission to copy and/or distribute it,
4dnl with or without modifications, as long as this notice is preserved.
5
6dnl serial 7
7
8AC_DEFUN([gl_UTIMENS],
9[
10 dnl Prerequisites of lib/utimens.c.
11 AC_REQUIRE([gl_FUNC_UTIMES])
12 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
13 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_UTIMBUF])
14 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat lutimes])
16
17 if test $ac_cv_func_futimens = no && test $ac_cv_func_futimesat = yes; then
18 dnl FreeBSD 8.0-rc2 mishandles futimesat(fd,NULL,time). It is not
19 dnl standardized, but Solaris implemented it first and uses it as
20 dnl its only means to set fd time.
21 AC_CACHE_CHECK([whether futimesat handles NULL file],
22 [gl_cv_func_futimesat_works],
23 [touch conftest.file
24 AC_RUN_IFELSE([AC_LANG_PROGRAM([[
25#include <stddef.h>
26#include <sys/times.h>
27#include <fcntl.h>
28]], [[ int fd = open ("conftest.file", O_RDWR);
29 if (fd < 0) return 1;
30 if (futimesat (fd, NULL, NULL)) return 2;
31 ]])],
32 [gl_cv_func_futimesat_works=yes],
33 [gl_cv_func_futimesat_works=no],
34 [case "$host_os" in
35 # Guess yes on glibc systems.
36 *-gnu*) gl_cv_func_futimesat_works="guessing yes" ;;
37 # If we don't know, assume the worst.
38 *) gl_cv_func_futimesat_works="guessing no" ;;
39 esac
40 ])
41 rm -f conftest.file])
42 case "$gl_cv_func_futimesat_works" in
43 *yes) ;;
44 *)
45 AC_DEFINE([FUTIMESAT_NULL_BUG], [1],
46 [Define to 1 if futimesat mishandles a NULL file name.])
47 ;;
48 esac
49 fi
50])
diff --git a/m4/utimes.m4 b/m4/utimes.m4
new file mode 100644
index 00000000000..417103a7b72
--- /dev/null
+++ b/m4/utimes.m4
@@ -0,0 +1,136 @@
1# Detect some bugs in glibc's implementation of utimes.
2# serial 3
3
4dnl Copyright (C) 2003-2005, 2009-2012 Free Software Foundation, Inc.
5dnl This file is free software; the Free Software Foundation
6dnl gives unlimited permission to copy and/or distribute it,
7dnl with or without modifications, as long as this notice is preserved.
8
9# See if we need to work around bugs in glibc's implementation of
10# utimes from 2003-07-12 to 2003-09-17.
11# First, there was a bug that would make utimes set mtime
12# and atime to zero (1970-01-01) unconditionally.
13# Then, there was code to round rather than truncate.
14# Then, there was an implementation (sparc64, Linux-2.4.28, glibc-2.3.3)
15# that didn't honor the NULL-means-set-to-current-time semantics.
16# Finally, there was also a version of utimes that failed on read-only
17# files, while utime worked fine (linux-2.2.20, glibc-2.2.5).
18#
19# From Jim Meyering, with suggestions from Paul Eggert.
20
21AC_DEFUN([gl_FUNC_UTIMES],
22[
23 AC_CACHE_CHECK([whether the utimes function works],
24 [gl_cv_func_working_utimes],
25 [
26 AC_RUN_IFELSE([AC_LANG_SOURCE([[
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <sys/time.h>
31#include <time.h>
32#include <unistd.h>
33#include <stdlib.h>
34#include <stdio.h>
35#include <utime.h>
36
37static int
38inorder (time_t a, time_t b, time_t c)
39{
40 return a <= b && b <= c;
41}
42
43int
44main ()
45{
46 int result = 0;
47 char const *file = "conftest.utimes";
48 static struct timeval timeval[2] = {{9, 10}, {999999, 999999}};
49
50 /* Test whether utimes() essentially works. */
51 {
52 struct stat sbuf;
53 FILE *f = fopen (file, "w");
54 if (f == NULL)
55 result |= 1;
56 else if (fclose (f) != 0)
57 result |= 1;
58 else if (utimes (file, timeval) != 0)
59 result |= 2;
60 else if (lstat (file, &sbuf) != 0)
61 result |= 1;
62 else if (!(sbuf.st_atime == timeval[0].tv_sec
63 && sbuf.st_mtime == timeval[1].tv_sec))
64 result |= 4;
65 if (unlink (file) != 0)
66 result |= 1;
67 }
68
69 /* Test whether utimes() with a NULL argument sets the file's timestamp
70 to the current time. Use 'fstat' as well as 'time' to
71 determine the "current" time, to accommodate NFS file systems
72 if there is a time skew between the host and the NFS server. */
73 {
74 int fd = open (file, O_WRONLY|O_CREAT, 0644);
75 if (fd < 0)
76 result |= 1;
77 else
78 {
79 time_t t0, t2;
80 struct stat st0, st1, st2;
81 if (time (&t0) == (time_t) -1)
82 result |= 1;
83 else if (fstat (fd, &st0) != 0)
84 result |= 1;
85 else if (utimes (file, timeval) != 0)
86 result |= 2;
87 else if (utimes (file, NULL) != 0)
88 result |= 8;
89 else if (fstat (fd, &st1) != 0)
90 result |= 1;
91 else if (write (fd, "\n", 1) != 1)
92 result |= 1;
93 else if (fstat (fd, &st2) != 0)
94 result |= 1;
95 else if (time (&t2) == (time_t) -1)
96 result |= 1;
97 else
98 {
99 int m_ok_POSIX = inorder (t0, st1.st_mtime, t2);
100 int m_ok_NFS = inorder (st0.st_mtime, st1.st_mtime, st2.st_mtime);
101 if (! (st1.st_atime == st1.st_mtime))
102 result |= 16;
103 if (! (m_ok_POSIX || m_ok_NFS))
104 result |= 32;
105 }
106 if (close (fd) != 0)
107 result |= 1;
108 }
109 if (unlink (file) != 0)
110 result |= 1;
111 }
112
113 /* Test whether utimes() with a NULL argument works on read-only files. */
114 {
115 int fd = open (file, O_WRONLY|O_CREAT, 0444);
116 if (fd < 0)
117 result |= 1;
118 else if (close (fd) != 0)
119 result |= 1;
120 else if (utimes (file, NULL) != 0)
121 result |= 64;
122 if (unlink (file) != 0)
123 result |= 1;
124 }
125
126 return result;
127}
128 ]])],
129 [gl_cv_func_working_utimes=yes],
130 [gl_cv_func_working_utimes=no],
131 [gl_cv_func_working_utimes=no])])
132
133 if test $gl_cv_func_working_utimes = yes; then
134 AC_DEFINE([HAVE_WORKING_UTIMES], [1], [Define if utimes works properly. ])
135 fi
136])