aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2017-04-30 14:52:10 -0700
committerPaul Eggert2017-04-30 14:53:17 -0700
commitb6aa3446df5e715fd74f010afad75c3c8589a9a1 (patch)
tree3b5377b3651ef95a0a77becaa7ee7ccba7b37168
parent3ad9d5c347739bb6c5450ed443ffa1608a94394c (diff)
downloademacs-b6aa3446df5e715fd74f010afad75c3c8589a9a1.tar.gz
emacs-b6aa3446df5e715fd74f010afad75c3c8589a9a1.zip
Merge from gnulib
This incorporates: 2017-04-30 strftime-fixes: New module 2017-04-30 mktime: Work around TZ problem on native Windows 2017-04-30 ctime, localtime: New modules 2017-04-30 gettimeofday: Provide higher resolution on native Windows 2017-04-29 utime-h: Modernize handling of 'struct utimbuf' 2017-04-29 Make use of module 'utime-h' 2017-04-30 Fix a few typos * admin/merge-gnulib (AVOIDED_MODULES): Avoid utime-h, too. * lib/gettimeofday.c, lib/mktime.c, lib/time.in.h, lib/utimens.c: * m4/gettimeofday.m4, m4/include_next.m4, m4/mktime.m4: * m4/strftime.m4, m4/time_h.m4, m4/timegm.m4, m4/utimens.m4: Copy from gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
-rwxr-xr-xadmin/merge-gnulib2
-rw-r--r--lib/gettimeofday.c62
-rw-r--r--lib/gnulib.mk.in12
-rw-r--r--lib/mktime.c47
-rw-r--r--lib/time.in.h37
-rw-r--r--lib/utimens.c15
-rw-r--r--m4/gettimeofday.m47
-rw-r--r--m4/gnulib-comp.m43
-rw-r--r--m4/include_next.m45
-rw-r--r--m4/mktime.m459
-rw-r--r--m4/strftime.m48
-rw-r--r--m4/time_h.m47
-rw-r--r--m4/timegm.m46
-rw-r--r--m4/utimens.m43
14 files changed, 204 insertions, 69 deletions
diff --git a/admin/merge-gnulib b/admin/merge-gnulib
index 1f0e55f5860..c2ab3571fee 100755
--- a/admin/merge-gnulib
+++ b/admin/merge-gnulib
@@ -49,7 +49,7 @@ AVOIDED_MODULES='
49 malloc-posix msvc-inval msvc-nothrow 49 malloc-posix msvc-inval msvc-nothrow
50 open openat-die opendir raise 50 open openat-die opendir raise
51 save-cwd select setenv sigprocmask stat stdarg stdbool 51 save-cwd select setenv sigprocmask stat stdarg stdbool
52 threadlib unsetenv 52 threadlib unsetenv utime-h
53' 53'
54 54
55GNULIB_TOOL_FLAGS=' 55GNULIB_TOOL_FLAGS='
diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c
index 18dcbda4db5..86f1a8c1d28 100644
--- a/lib/gettimeofday.c
+++ b/lib/gettimeofday.c
@@ -24,8 +24,9 @@
24 24
25#include <time.h> 25#include <time.h>
26 26
27#if HAVE_SYS_TIMEB_H 27#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
28# include <sys/timeb.h> 28# define WINDOWS_NATIVE
29# include <windows.h>
29#endif 30#endif
30 31
31#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME 32#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
@@ -92,6 +93,28 @@ rpl_tzset (void)
92 tzset (); 93 tzset ();
93 *localtime_buffer_addr = save; 94 *localtime_buffer_addr = save;
94} 95}
96
97#endif
98
99#ifdef WINDOWS_NATIVE
100
101/* GetSystemTimePreciseAsFileTime was introduced only in Windows 8. */
102typedef void (WINAPI * GetSystemTimePreciseAsFileTimeFuncType) (FILETIME *lpTime);
103static GetSystemTimePreciseAsFileTimeFuncType GetSystemTimePreciseAsFileTimeFunc = NULL;
104static BOOL initialized = FALSE;
105
106static void
107initialize (void)
108{
109 HMODULE kernel32 = LoadLibrary ("kernel32.dll");
110 if (kernel32 != NULL)
111 {
112 GetSystemTimePreciseAsFileTimeFunc =
113 (GetSystemTimePreciseAsFileTimeFuncType) GetProcAddress (kernel32, "GetSystemTimePreciseAsFileTime");
114 }
115 initialized = TRUE;
116}
117
95#endif 118#endif
96 119
97/* This is a wrapper for gettimeofday. It is used only on systems 120/* This is a wrapper for gettimeofday. It is used only on systems
@@ -130,12 +153,35 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz)
130 153
131#else 154#else
132 155
133# if HAVE__FTIME 156# ifdef WINDOWS_NATIVE
134 157
135 struct _timeb timebuf; 158 /* On native Windows, there are two ways to get the current time:
136 _ftime (&timebuf); 159 GetSystemTimeAsFileTime
137 tv->tv_sec = timebuf.time; 160 <https://msdn.microsoft.com/en-us/library/ms724397.aspx>
138 tv->tv_usec = timebuf.millitm * 1000; 161 or
162 GetSystemTimePreciseAsFileTime
163 <https://msdn.microsoft.com/en-us/library/hh706895.aspx>. */
164 FILETIME current_time;
165
166 if (!initialized)
167 initialize ();
168 if (GetSystemTimePreciseAsFileTimeFunc != NULL)
169 GetSystemTimePreciseAsFileTimeFunc (&current_time);
170 else
171 GetSystemTimeAsFileTime (&current_time);
172
173 /* Convert from FILETIME to 'struct timeval'. */
174 /* FILETIME: <https://msdn.microsoft.com/en-us/library/ms724284.aspx> */
175 ULONGLONG since_1601 =
176 ((ULONGLONG) current_time.dwHighDateTime << 32)
177 | (ULONGLONG) current_time.dwLowDateTime;
178 /* Between 1601-01-01 and 1970-01-01 there were 280 normal years and 89 leap
179 years, in total 134774 days. */
180 ULONGLONG since_1970 =
181 since_1601 - (ULONGLONG) 134774 * (ULONGLONG) 86400 * (ULONGLONG) 10000000;
182 ULONGLONG microseconds_since_1970 = since_1970 / (ULONGLONG) 10;
183 tv->tv_sec = microseconds_since_1970 / (ULONGLONG) 1000000;
184 tv->tv_usec = microseconds_since_1970 % (ULONGLONG) 1000000;
139 185
140# else 186# else
141 187
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index af26648c0e0..59cdbdb847a 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -21,7 +21,7 @@
21# the same distribution terms as the rest of that program. 21# the same distribution terms as the rest of that program.
22# 22#
23# Generated by gnulib-tool. 23# Generated by gnulib-tool.
24# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=close --avoid=dup --avoid=fchdir --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=setenv --avoid=sigprocmask --avoid=stat --avoid=stdarg --avoid=stdbool --avoid=threadlib --avoid=unsetenv --gnu-make --makefile-name=gnulib.mk.in --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt binary-io byteswap c-ctype c-strcase careadlinkat close-stream count-leading-zeros count-one-bits count-trailing-zeros crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl fcntl-h fdatasync fdopendir filemode filevercmp flexmember fstatat fsync getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog ignore-value intprops largefile lstat manywarnings memrchr mkostemp mktime pipe2 pselect pthread_sigmask putenv qcopy-acl readlink readlinkat sig2str socklen stat-time std-gnu11 stdalign stddef stdio stpcpy strftime strtoimax strtoumax symlink sys_stat sys_time time time_r time_rz timegm timer-time timespec-add timespec-sub update-copyright utimens vla warnings 24# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --avoid=close --avoid=dup --avoid=fchdir --avoid=fstat --avoid=malloc-posix --avoid=msvc-inval --avoid=msvc-nothrow --avoid=open --avoid=openat-die --avoid=opendir --avoid=raise --avoid=save-cwd --avoid=select --avoid=setenv --avoid=sigprocmask --avoid=stat --avoid=stdarg --avoid=stdbool --avoid=threadlib --avoid=unsetenv --avoid=utime-h --gnu-make --makefile-name=gnulib.mk.in --conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca-opt binary-io byteswap c-ctype c-strcase careadlinkat close-stream count-leading-zeros count-one-bits count-trailing-zeros crypto/md5 crypto/sha1 crypto/sha256 crypto/sha512 dtoastr dtotimespec dup2 environ execinfo faccessat fcntl fcntl-h fdatasync fdopendir filemode filevercmp flexmember fstatat fsync getloadavg getopt-gnu gettime gettimeofday gitlog-to-changelog ignore-value intprops largefile lstat manywarnings memrchr mkostemp mktime pipe2 pselect pthread_sigmask putenv qcopy-acl readlink readlinkat sig2str socklen stat-time std-gnu11 stdalign stddef stdio stpcpy strftime strtoimax strtoumax symlink sys_stat sys_time time time_r time_rz timegm timer-time timespec-add timespec-sub update-copyright utimens vla warnings
25 25
26 26
27MOSTLYCLEANFILES += core *.stackdump 27MOSTLYCLEANFILES += core *.stackdump
@@ -117,6 +117,7 @@ GNULIB_CHDIR = @GNULIB_CHDIR@
117GNULIB_CHOWN = @GNULIB_CHOWN@ 117GNULIB_CHOWN = @GNULIB_CHOWN@
118GNULIB_CLOSE = @GNULIB_CLOSE@ 118GNULIB_CLOSE = @GNULIB_CLOSE@
119GNULIB_CLOSEDIR = @GNULIB_CLOSEDIR@ 119GNULIB_CLOSEDIR = @GNULIB_CLOSEDIR@
120GNULIB_CTIME = @GNULIB_CTIME@
120GNULIB_DIRFD = @GNULIB_DIRFD@ 121GNULIB_DIRFD = @GNULIB_DIRFD@
121GNULIB_DPRINTF = @GNULIB_DPRINTF@ 122GNULIB_DPRINTF = @GNULIB_DPRINTF@
122GNULIB_DUP = @GNULIB_DUP@ 123GNULIB_DUP = @GNULIB_DUP@
@@ -183,6 +184,7 @@ GNULIB_LCHMOD = @GNULIB_LCHMOD@
183GNULIB_LCHOWN = @GNULIB_LCHOWN@ 184GNULIB_LCHOWN = @GNULIB_LCHOWN@
184GNULIB_LINK = @GNULIB_LINK@ 185GNULIB_LINK = @GNULIB_LINK@
185GNULIB_LINKAT = @GNULIB_LINKAT@ 186GNULIB_LINKAT = @GNULIB_LINKAT@
187GNULIB_LOCALTIME = @GNULIB_LOCALTIME@
186GNULIB_LSEEK = @GNULIB_LSEEK@ 188GNULIB_LSEEK = @GNULIB_LSEEK@
187GNULIB_LSTAT = @GNULIB_LSTAT@ 189GNULIB_LSTAT = @GNULIB_LSTAT@
188GNULIB_MALLOC_POSIX = @GNULIB_MALLOC_POSIX@ 190GNULIB_MALLOC_POSIX = @GNULIB_MALLOC_POSIX@
@@ -281,6 +283,7 @@ GNULIB_STRCHRNUL = @GNULIB_STRCHRNUL@
281GNULIB_STRDUP = @GNULIB_STRDUP@ 283GNULIB_STRDUP = @GNULIB_STRDUP@
282GNULIB_STRERROR = @GNULIB_STRERROR@ 284GNULIB_STRERROR = @GNULIB_STRERROR@
283GNULIB_STRERROR_R = @GNULIB_STRERROR_R@ 285GNULIB_STRERROR_R = @GNULIB_STRERROR_R@
286GNULIB_STRFTIME = @GNULIB_STRFTIME@
284GNULIB_STRNCAT = @GNULIB_STRNCAT@ 287GNULIB_STRNCAT = @GNULIB_STRNCAT@
285GNULIB_STRNDUP = @GNULIB_STRNDUP@ 288GNULIB_STRNDUP = @GNULIB_STRNDUP@
286GNULIB_STRNLEN = @GNULIB_STRNLEN@ 289GNULIB_STRNLEN = @GNULIB_STRNLEN@
@@ -669,6 +672,7 @@ REPLACE_CANONICALIZE_FILE_NAME = @REPLACE_CANONICALIZE_FILE_NAME@
669REPLACE_CHOWN = @REPLACE_CHOWN@ 672REPLACE_CHOWN = @REPLACE_CHOWN@
670REPLACE_CLOSE = @REPLACE_CLOSE@ 673REPLACE_CLOSE = @REPLACE_CLOSE@
671REPLACE_CLOSEDIR = @REPLACE_CLOSEDIR@ 674REPLACE_CLOSEDIR = @REPLACE_CLOSEDIR@
675REPLACE_CTIME = @REPLACE_CTIME@
672REPLACE_DIRFD = @REPLACE_DIRFD@ 676REPLACE_DIRFD = @REPLACE_DIRFD@
673REPLACE_DPRINTF = @REPLACE_DPRINTF@ 677REPLACE_DPRINTF = @REPLACE_DPRINTF@
674REPLACE_DUP = @REPLACE_DUP@ 678REPLACE_DUP = @REPLACE_DUP@
@@ -760,6 +764,7 @@ REPLACE_STRCHRNUL = @REPLACE_STRCHRNUL@
760REPLACE_STRDUP = @REPLACE_STRDUP@ 764REPLACE_STRDUP = @REPLACE_STRDUP@
761REPLACE_STRERROR = @REPLACE_STRERROR@ 765REPLACE_STRERROR = @REPLACE_STRERROR@
762REPLACE_STRERROR_R = @REPLACE_STRERROR_R@ 766REPLACE_STRERROR_R = @REPLACE_STRERROR_R@
767REPLACE_STRFTIME = @REPLACE_STRFTIME@
763REPLACE_STRNCAT = @REPLACE_STRNCAT@ 768REPLACE_STRNCAT = @REPLACE_STRNCAT@
764REPLACE_STRNDUP = @REPLACE_STRNDUP@ 769REPLACE_STRNDUP = @REPLACE_STRNDUP@
765REPLACE_STRNLEN = @REPLACE_STRNLEN@ 770REPLACE_STRNLEN = @REPLACE_STRNLEN@
@@ -2701,9 +2706,12 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
2701 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ 2706 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
2702 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \ 2707 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
2703 -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \ 2708 -e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
2709 -e 's/@''GNULIB_CTIME''@/$(GNULIB_CTIME)/g' \
2704 -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \ 2710 -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
2711 -e 's/@''GNULIB_LOCALTIME''@/$(GNULIB_LOCALTIME)/g' \
2705 -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \ 2712 -e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
2706 -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \ 2713 -e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
2714 -e 's/@''GNULIB_STRFTIME''@/$(GNULIB_STRFTIME)/g' \
2707 -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ 2715 -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \
2708 -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \ 2716 -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
2709 -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \ 2717 -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
@@ -2713,11 +2721,13 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
2713 -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ 2721 -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
2714 -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ 2722 -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
2715 -e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \ 2723 -e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \
2724 -e 's|@''REPLACE_CTIME''@|$(REPLACE_CTIME)|g' \
2716 -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \ 2725 -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
2717 -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \ 2726 -e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \
2718 -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \ 2727 -e 's|@''REPLACE_LOCALTIME_R''@|$(REPLACE_LOCALTIME_R)|g' \
2719 -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \ 2728 -e 's|@''REPLACE_MKTIME''@|$(REPLACE_MKTIME)|g' \
2720 -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ 2729 -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
2730 -e 's|@''REPLACE_STRFTIME''@|$(REPLACE_STRFTIME)|g' \
2721 -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ 2731 -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
2722 -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ 2732 -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \
2723 -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ 2733 -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
diff --git a/lib/mktime.c b/lib/mktime.c
index 998882f5860..06d5916e910 100644
--- a/lib/mktime.c
+++ b/lib/mktime.c
@@ -23,6 +23,19 @@
23# define DEBUG_MKTIME 0 23# define DEBUG_MKTIME 0
24#endif 24#endif
25 25
26/* The following macros influence what gets defined when this file is compiled:
27
28 Macro/expression Which gnulib module This compilation unit
29 should define
30
31 NEED_MKTIME_WORKING mktime rpl_mktime
32 || NEED_MKTIME_WINDOWS
33
34 NEED_MKTIME_INTERNAL mktime-internal mktime_internal
35
36 DEBUG_MKTIME (defined manually) my_mktime, main
37 */
38
26#if !defined _LIBC && !DEBUG_MKTIME 39#if !defined _LIBC && !DEBUG_MKTIME
27# include <config.h> 40# include <config.h>
28#endif 41#endif
@@ -51,6 +64,13 @@
51# define mktime my_mktime 64# define mktime my_mktime
52#endif 65#endif
53 66
67#if NEED_MKTIME_WINDOWS /* on native Windows */
68# include <stdlib.h>
69# include <string.h>
70#endif
71
72#if NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL || DEBUG_MKTIME
73
54/* A signed type that can represent an integer number of years 74/* A signed type that can represent an integer number of years
55 multiplied by three times the number of seconds in a year. It is 75 multiplied by three times the number of seconds in a year. It is
56 needed when converting a tm_year value times the number of seconds 76 needed when converting a tm_year value times the number of seconds
@@ -458,25 +478,46 @@ __mktime_internal (struct tm *tp,
458 return t; 478 return t;
459} 479}
460 480
481#endif /* NEED_MKTIME_WORKING || NEED_MKTIME_INTERNAL || DEBUG_MKTIME */
482
483#if NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS || DEBUG_MKTIME
461 484
485# if NEED_MKTIME_WORKING || DEBUG_MKTIME
462static mktime_offset_t localtime_offset; 486static mktime_offset_t localtime_offset;
487# endif
463 488
464/* Convert *TP to a time_t value. */ 489/* Convert *TP to a time_t value. */
465time_t 490time_t
466mktime (struct tm *tp) 491mktime (struct tm *tp)
467{ 492{
468#ifdef _LIBC 493# if NEED_MKTIME_WINDOWS
494 /* If the environment variable TZ has been set by Cygwin, neutralize it.
495 The Microsoft CRT interprets TZ differently than Cygwin and produces
496 incorrect results if TZ has the syntax used by Cygwin. */
497 const char *tz = getenv ("TZ");
498 if (tz != NULL && strchr (tz, '/') != NULL)
499 _putenv ("TZ=");
500# endif
501
502# if NEED_MKTIME_WORKING || DEBUG_MKTIME
503# ifdef _LIBC
469 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the 504 /* POSIX.1 8.1.1 requires that whenever mktime() is called, the
470 time zone names contained in the external variable 'tzname' shall 505 time zone names contained in the external variable 'tzname' shall
471 be set as if the tzset() function had been called. */ 506 be set as if the tzset() function had been called. */
472 __tzset (); 507 __tzset ();
473#elif HAVE_TZSET 508# elif HAVE_TZSET
474 tzset (); 509 tzset ();
475#endif 510# endif
476 511
477 return __mktime_internal (tp, __localtime_r, &localtime_offset); 512 return __mktime_internal (tp, __localtime_r, &localtime_offset);
513# else
514# undef mktime
515 return mktime (tp);
516# endif
478} 517}
479 518
519#endif /* NEED_MKTIME_WORKING || NEED_MKTIME_WINDOWS || DEBUG_MKTIME */
520
480#ifdef weak_alias 521#ifdef weak_alias
481weak_alias (mktime, timelocal) 522weak_alias (mktime, timelocal)
482#endif 523#endif
diff --git a/lib/time.in.h b/lib/time.in.h
index fef89807f8a..d2a0302f464 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -187,7 +187,7 @@ _GL_CXXALIASWARN (gmtime_r);
187/* Convert TIMER to RESULT, assuming local time and UTC respectively. See 187/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
188 <http://www.opengroup.org/susv3xsh/localtime.html> and 188 <http://www.opengroup.org/susv3xsh/localtime.html> and
189 <http://www.opengroup.org/susv3xsh/gmtime.html>. */ 189 <http://www.opengroup.org/susv3xsh/gmtime.html>. */
190# if @GNULIB_GETTIMEOFDAY@ 190# if @GNULIB_LOCALTIME@ || @GNULIB_GETTIMEOFDAY@
191# if @REPLACE_LOCALTIME@ 191# if @REPLACE_LOCALTIME@
192# if !(defined __cplusplus && defined GNULIB_NAMESPACE) 192# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
193# undef localtime 193# undef localtime
@@ -233,6 +233,41 @@ _GL_CXXALIAS_SYS (strptime, char *, (char const *restrict __buf,
233_GL_CXXALIASWARN (strptime); 233_GL_CXXALIASWARN (strptime);
234# endif 234# endif
235 235
236/* Convert *TP to a date and time string. See
237 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime.html>. */
238# if @GNULIB_CTIME@
239# if @REPLACE_CTIME@
240# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
241# define ctime rpl_ctime
242# endif
243_GL_FUNCDECL_RPL (ctime, char *, (time_t const *__tp)
244 _GL_ARG_NONNULL ((1)));
245_GL_CXXALIAS_RPL (ctime, char *, (time_t const *__tp));
246# else
247_GL_CXXALIAS_SYS (ctime, char *, (time_t const *__tp));
248# endif
249_GL_CXXALIASWARN (ctime);
250# endif
251
252/* Convert *TP to a date and time string. See
253 <http://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html>. */
254# if @GNULIB_STRFTIME@
255# if @REPLACE_STRFTIME@
256# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
257# define strftime rpl_strftime
258# endif
259_GL_FUNCDECL_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
260 const char *__fmt, const struct tm *__tp)
261 _GL_ARG_NONNULL ((1, 3, 4)));
262_GL_CXXALIAS_RPL (strftime, size_t, (char *__buf, size_t __bufsize,
263 const char *__fmt, const struct tm *__tp));
264# else
265_GL_CXXALIAS_SYS (strftime, size_t, (char *__buf, size_t __bufsize,
266 const char *__fmt, const struct tm *__tp));
267# endif
268_GL_CXXALIASWARN (strftime);
269# endif
270
236# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@ 271# if defined _GNU_SOURCE && @GNULIB_TIME_RZ@ && ! @HAVE_TIMEZONE_T@
237typedef struct tm_zone *timezone_t; 272typedef struct tm_zone *timezone_t;
238_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name)); 273_GL_FUNCDECL_SYS (tzalloc, timezone_t, (char const *__name));
diff --git a/lib/utimens.c b/lib/utimens.c
index 3643668c3a5..3b451193350 100644
--- a/lib/utimens.c
+++ b/lib/utimens.c
@@ -30,24 +30,11 @@
30#include <sys/stat.h> 30#include <sys/stat.h>
31#include <sys/time.h> 31#include <sys/time.h>
32#include <unistd.h> 32#include <unistd.h>
33#include <utime.h>
33 34
34#include "stat-time.h" 35#include "stat-time.h"
35#include "timespec.h" 36#include "timespec.h"
36 37
37#if HAVE_UTIME_H
38# include <utime.h>
39#endif
40
41/* Some systems (even some that do have <utime.h>) don't declare this
42 structure anywhere. */
43#ifndef HAVE_STRUCT_UTIMBUF
44struct utimbuf
45{
46 long actime;
47 long modtime;
48};
49#endif
50
51/* Avoid recursion with rpl_futimens or rpl_utimensat. */ 38/* Avoid recursion with rpl_futimens or rpl_utimensat. */
52#undef futimens 39#undef futimens
53#undef utimensat 40#undef utimensat
diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4
index 4f501e5bf91..742b6c9e10e 100644
--- a/m4/gettimeofday.m4
+++ b/m4/gettimeofday.m4
@@ -1,4 +1,4 @@
1# serial 21 1# serial 22
2 2
3# Copyright (C) 2001-2003, 2005, 2007, 2009-2017 Free Software Foundation, Inc. 3# Copyright (C) 2001-2003, 2005, 2007, 2009-2017 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation 4# This file is free software; the Free Software Foundation
@@ -132,7 +132,4 @@ AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
132]) 132])
133 133
134# Prerequisites of lib/gettimeofday.c. 134# Prerequisites of lib/gettimeofday.c.
135AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [ 135AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:])
136 AC_CHECK_HEADERS([sys/timeb.h])
137 AC_CHECK_FUNCS([_ftime])
138])
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 7dbfb9ae70d..136762430e0 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -516,7 +516,7 @@ AC_DEFUN([gl_INIT],
516 { 516 {
517 if ! $gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31; then 517 if ! $gl_gnulib_enabled_5264294aa0a5557541b53c8c741f7f31; then
518 gl_FUNC_MKTIME_INTERNAL 518 gl_FUNC_MKTIME_INTERNAL
519 if test $REPLACE_MKTIME = 1; then 519 if test $WANT_MKTIME_INTERNAL = 1; then
520 AC_LIBOBJ([mktime]) 520 AC_LIBOBJ([mktime])
521 gl_PREREQ_MKTIME 521 gl_PREREQ_MKTIME
522 fi 522 fi
@@ -1051,7 +1051,6 @@ AC_DEFUN([gl_FILE_LIST], [
1051 m4/timespec.m4 1051 m4/timespec.m4
1052 m4/tm_gmtoff.m4 1052 m4/tm_gmtoff.m4
1053 m4/unistd_h.m4 1053 m4/unistd_h.m4
1054 m4/utimbuf.m4
1055 m4/utimens.m4 1054 m4/utimens.m4
1056 m4/utimes.m4 1055 m4/utimes.m4
1057 m4/vararrays.m4 1056 m4/vararrays.m4
diff --git a/m4/include_next.m4 b/m4/include_next.m4
index e687e232a27..068f6f60a41 100644
--- a/m4/include_next.m4
+++ b/m4/include_next.m4
@@ -1,4 +1,4 @@
1# include_next.m4 serial 23 1# include_next.m4 serial 24
2dnl Copyright (C) 2006-2017 Free Software Foundation, Inc. 2dnl Copyright (C) 2006-2017 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -6,7 +6,8 @@ dnl with or without modifications, as long as this notice is preserved.
6 6
7dnl From Paul Eggert and Derek Price. 7dnl From Paul Eggert and Derek Price.
8 8
9dnl Sets INCLUDE_NEXT and PRAGMA_SYSTEM_HEADER. 9dnl Sets INCLUDE_NEXT, INCLUDE_NEXT_AS_FIRST_DIRECTIVE, PRAGMA_SYSTEM_HEADER,
10dnl and PRAGMA_COLUMNS.
10dnl 11dnl
11dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to 12dnl INCLUDE_NEXT expands to 'include_next' if the compiler supports it, or to
12dnl 'include' otherwise. 13dnl 'include' otherwise.
diff --git a/m4/mktime.m4 b/m4/mktime.m4
index d594ddc58be..31da65e8b2d 100644
--- a/m4/mktime.m4
+++ b/m4/mktime.m4
@@ -1,4 +1,4 @@
1# serial 27 1# serial 28
2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2017 Free Software Foundation, 2dnl Copyright (C) 2002-2003, 2005-2007, 2009-2017 Free Software Foundation,
3dnl Inc. 3dnl Inc.
4dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
@@ -21,9 +21,9 @@ AC_DEFUN([gl_TIME_T_IS_SIGNED],
21 fi 21 fi
22]) 22])
23 23
24AC_DEFUN([gl_FUNC_MKTIME], 24dnl Test whether mktime works. Set gl_cv_func_working_mktime.
25AC_DEFUN([gl_FUNC_MKTIME_WORKS],
25[ 26[
26 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
27 AC_REQUIRE([gl_TIME_T_IS_SIGNED]) 27 AC_REQUIRE([gl_TIME_T_IS_SIGNED])
28 28
29 dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained 29 dnl We don't use AC_FUNC_MKTIME any more, because it is no longer maintained
@@ -239,29 +239,50 @@ main ()
239}]])], 239}]])],
240 [gl_cv_func_working_mktime=yes], 240 [gl_cv_func_working_mktime=yes],
241 [gl_cv_func_working_mktime=no], 241 [gl_cv_func_working_mktime=no],
242 [gl_cv_func_working_mktime=no]) 242 [gl_cv_func_working_mktime="guessing no"])
243 ]) 243 ])
244])
245
246dnl Main macro of module 'mktime'.
247AC_DEFUN([gl_FUNC_MKTIME],
248[
249 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
250 AC_REQUIRE([AC_CANONICAL_HOST])
251 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
244 252
245 if test $gl_cv_func_working_mktime = no; then 253 REPLACE_MKTIME=0
254 if test "$gl_cv_func_working_mktime" != yes; then
246 REPLACE_MKTIME=1 255 REPLACE_MKTIME=1
247 else 256 AC_DEFINE([NEED_MKTIME_WORKING], [1],
248 REPLACE_MKTIME=0 257 [Define if the compilation of mktime.c should define 'mktime'
258 with the algorithmic workarounds.])
249 fi 259 fi
260 case "$host_os" in
261 mingw*)
262 REPLACE_MKTIME=1
263 AC_DEFINE([NEED_MKTIME_WINDOWS], [1],
264 [Define if the compilation of mktime.c should define 'mktime'
265 with the native Windows TZ workaround.])
266 ;;
267 esac
250]) 268])
251 269
270dnl Main macro of module 'mktime-internal'.
252AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [ 271AC_DEFUN([gl_FUNC_MKTIME_INTERNAL], [
253 AC_REQUIRE([gl_FUNC_MKTIME]) 272 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
254 if test $REPLACE_MKTIME = 0; then 273
255 dnl BeOS has __mktime_internal in libc, but other platforms don't. 274 WANT_MKTIME_INTERNAL=0
256 AC_CHECK_FUNC([__mktime_internal], 275 dnl BeOS has __mktime_internal in libc, but other platforms don't.
257 [AC_DEFINE([mktime_internal], [__mktime_internal], 276 AC_CHECK_FUNC([__mktime_internal],
258 [Define to the real name of the mktime_internal function.]) 277 [AC_DEFINE([mktime_internal], [__mktime_internal],
259 ], 278 [Define to the real name of the mktime_internal function.])
260 [dnl mktime works but it doesn't export __mktime_internal, 279 ],
261 dnl so we need to substitute our own mktime implementation. 280 [dnl mktime works but it doesn't export __mktime_internal,
262 REPLACE_MKTIME=1 281 dnl so we need to substitute our own mktime implementation.
263 ]) 282 WANT_MKTIME_INTERNAL=1
264 fi 283 AC_DEFINE([NEED_MKTIME_INTERNAL], [1],
284 [Define if the compilation of mktime.c should define 'mktime_internal'.])
285 ])
265]) 286])
266 287
267# Prerequisites of lib/mktime.c. 288# Prerequisites of lib/mktime.c.
diff --git a/m4/strftime.m4 b/m4/strftime.m4
index 3a5db9b4e3c..d2dac9e2328 100644
--- a/m4/strftime.m4
+++ b/m4/strftime.m4
@@ -1,4 +1,4 @@
1# serial 33 1# serial 34
2 2
3# Copyright (C) 1996-1997, 1999-2007, 2009-2017 Free Software Foundation, Inc. 3# Copyright (C) 1996-1997, 1999-2007, 2009-2017 Free Software Foundation, Inc.
4# 4#
@@ -10,12 +10,6 @@
10 10
11AC_DEFUN([gl_FUNC_GNU_STRFTIME], 11AC_DEFUN([gl_FUNC_GNU_STRFTIME],
12[ 12[
13 gl_FUNC_STRFTIME
14])
15
16# These are the prerequisite macros for GNU's strftime.c replacement.
17AC_DEFUN([gl_FUNC_STRFTIME],
18[
19 # This defines (or not) HAVE_TZNAME and HAVE_TM_ZONE. 13 # This defines (or not) HAVE_TZNAME and HAVE_TM_ZONE.
20 AC_REQUIRE([AC_STRUCT_TIMEZONE]) 14 AC_REQUIRE([AC_STRUCT_TIMEZONE])
21 15
diff --git a/m4/time_h.m4 b/m4/time_h.m4
index b92567875cb..e0f663ec711 100644
--- a/m4/time_h.m4
+++ b/m4/time_h.m4
@@ -2,7 +2,7 @@
2 2
3# Copyright (C) 2000-2001, 2003-2007, 2009-2017 Free Software Foundation, Inc. 3# Copyright (C) 2000-2001, 2003-2007, 2009-2017 Free Software Foundation, Inc.
4 4
5# serial 9 5# serial 10
6 6
7# This file is free software; the Free Software Foundation 7# This file is free software; the Free Software Foundation
8# gives unlimited permission to copy and/or distribute it, 8# gives unlimited permission to copy and/or distribute it,
@@ -104,8 +104,11 @@ AC_DEFUN([gl_TIME_MODULE_INDICATOR],
104 104
105AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], 105AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
106[ 106[
107 GNULIB_CTIME=0; AC_SUBST([GNULIB_CTIME])
107 GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME]) 108 GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
109 GNULIB_LOCALTIME=0; AC_SUBST([GNULIB_LOCALTIME])
108 GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP]) 110 GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
111 GNULIB_STRFTIME=0; AC_SUBST([GNULIB_STRFTIME])
109 GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) 112 GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
110 GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM]) 113 GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
111 GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R]) 114 GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
@@ -118,9 +121,11 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
118 dnl If another module says to replace or to not replace, do that. 121 dnl If another module says to replace or to not replace, do that.
119 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; 122 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
120 dnl this lets maintainers check for portability. 123 dnl this lets maintainers check for portability.
124 REPLACE_CTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_CTIME])
121 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) 125 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
122 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) 126 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
123 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) 127 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
128 REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME])
124 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) 129 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
125 130
126 dnl Hack so that the time module doesn't depend on the sys_time module. 131 dnl Hack so that the time module doesn't depend on the sys_time module.
diff --git a/m4/timegm.m4 b/m4/timegm.m4
index 510e25ab4b0..1f18552e9f5 100644
--- a/m4/timegm.m4
+++ b/m4/timegm.m4
@@ -1,4 +1,4 @@
1# timegm.m4 serial 11 1# timegm.m4 serial 12
2dnl Copyright (C) 2003, 2007, 2009-2017 Free Software Foundation, Inc. 2dnl Copyright (C) 2003, 2007, 2009-2017 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -7,11 +7,11 @@ dnl with or without modifications, as long as this notice is preserved.
7AC_DEFUN([gl_FUNC_TIMEGM], 7AC_DEFUN([gl_FUNC_TIMEGM],
8[ 8[
9 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) 9 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
10 AC_REQUIRE([gl_FUNC_MKTIME]) 10 AC_REQUIRE([gl_FUNC_MKTIME_WORKS])
11 REPLACE_TIMEGM=0 11 REPLACE_TIMEGM=0
12 AC_CHECK_FUNCS_ONCE([timegm]) 12 AC_CHECK_FUNCS_ONCE([timegm])
13 if test $ac_cv_func_timegm = yes; then 13 if test $ac_cv_func_timegm = yes; then
14 if test $gl_cv_func_working_mktime = no; then 14 if test "$gl_cv_func_working_mktime" != yes; then
15 # Assume that timegm is buggy if mktime is. 15 # Assume that timegm is buggy if mktime is.
16 REPLACE_TIMEGM=1 16 REPLACE_TIMEGM=1
17 fi 17 fi
diff --git a/m4/utimens.m4 b/m4/utimens.m4
index c58e93caaae..f3feab38da3 100644
--- a/m4/utimens.m4
+++ b/m4/utimens.m4
@@ -3,14 +3,13 @@ dnl This file is free software; the Free Software Foundation
3dnl gives unlimited permission to copy and/or distribute it, 3dnl gives unlimited permission to copy and/or distribute it,
4dnl with or without modifications, as long as this notice is preserved. 4dnl with or without modifications, as long as this notice is preserved.
5 5
6dnl serial 7 6dnl serial 8
7 7
8AC_DEFUN([gl_UTIMENS], 8AC_DEFUN([gl_UTIMENS],
9[ 9[
10 dnl Prerequisites of lib/utimens.c. 10 dnl Prerequisites of lib/utimens.c.
11 AC_REQUIRE([gl_FUNC_UTIMES]) 11 AC_REQUIRE([gl_FUNC_UTIMES])
12 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) 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 13 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
15 AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat lutimes]) 14 AC_CHECK_FUNCS_ONCE([futimes futimesat futimens utimensat lutimes])
16 15