Skip to content

Commit 634d0a9

Browse files
committed
Merge from gnulib
This incorporates: 2017-05-01 New module 'localtime-buffer' 2017-04-30 utimens: Add support for native Windows * admin/merge-gnulib (AVOIDED_MODULES): Add tzset. * configure.ac (tzset): No need for Emacs itself to check now. * lib/gettimeofday.c, lib/time.in.h, lib/time_rz.c, lib/utimens.c: * m4/gettimeofday.m4, m4/time_h.m4, m4/time_rz.m4: Copy from gnulib. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate. * lib/localtime-buffer.c, lib/localtime-buffer.h: * m4/localtime-buffer.m4: New files, copied from gnulib. * src/editfns.c (init_editfns): Assume tzset is callable.
1 parent 16b49e2 commit 634d0a9

15 files changed

+261
-101
lines changed

admin/merge-gnulib

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ AVOIDED_MODULES='
4949
malloc-posix msvc-inval msvc-nothrow
5050
open openat-die opendir raise
5151
save-cwd select setenv sigprocmask stat stdarg stdbool
52-
threadlib unsetenv utime-h
52+
threadlib tzset unsetenv utime utime-h
5353
'
5454

5555
GNULIB_TOOL_FLAGS='

configure.ac

+1-1
Original file line numberDiff line numberDiff line change
@@ -4195,7 +4195,7 @@ AC_CHECK_HEADERS(valgrind/valgrind.h)
41954195

41964196
AC_CHECK_MEMBERS([struct unipair.unicode], [], [], [[#include <linux/kd.h>]])
41974197

4198-
AC_CHECK_FUNCS_ONCE([sbrk tzset])
4198+
AC_CHECK_FUNCS_ONCE([sbrk])
41994199

42004200
ok_so_far=yes
42014201
AC_CHECK_FUNC(socket, , ok_so_far=no)

lib/gettimeofday.c

+6-67
Original file line numberDiff line numberDiff line change
@@ -29,72 +29,7 @@
2929
# include <windows.h>
3030
#endif
3131

32-
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
33-
34-
/* Work around the bug in some systems whereby gettimeofday clobbers
35-
the static buffer that localtime uses for its return value. The
36-
gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
37-
this problem. The tzset replacement is necessary for at least
38-
Solaris 2.5, 2.5.1, and 2.6. */
39-
40-
static struct tm tm_zero_buffer;
41-
static struct tm *localtime_buffer_addr = &tm_zero_buffer;
42-
43-
# undef localtime
44-
extern struct tm *localtime (time_t const *);
45-
46-
# undef gmtime
47-
extern struct tm *gmtime (time_t const *);
48-
49-
/* This is a wrapper for localtime. It is used only on systems for which
50-
gettimeofday clobbers the static buffer used for localtime's result.
51-
52-
On the first call, record the address of the static buffer that
53-
localtime uses for its result. */
54-
55-
struct tm *
56-
rpl_localtime (time_t const *timep)
57-
{
58-
struct tm *tm = localtime (timep);
59-
60-
if (localtime_buffer_addr == &tm_zero_buffer)
61-
localtime_buffer_addr = tm;
62-
63-
return tm;
64-
}
65-
66-
/* Same as above, since gmtime and localtime use the same buffer. */
67-
struct tm *
68-
rpl_gmtime (time_t const *timep)
69-
{
70-
struct tm *tm = gmtime (timep);
71-
72-
if (localtime_buffer_addr == &tm_zero_buffer)
73-
localtime_buffer_addr = tm;
74-
75-
return tm;
76-
}
77-
78-
#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
79-
80-
#if TZSET_CLOBBERS_LOCALTIME
81-
82-
# undef tzset
83-
extern void tzset (void);
84-
85-
/* This is a wrapper for tzset, for systems on which tzset may clobber
86-
the static buffer used for localtime's result. */
87-
void
88-
rpl_tzset (void)
89-
{
90-
/* Save and restore the contents of the buffer used for localtime's
91-
result around the call to tzset. */
92-
struct tm save = *localtime_buffer_addr;
93-
tzset ();
94-
*localtime_buffer_addr = save;
95-
}
96-
97-
#endif
32+
#include "localtime-buffer.h"
9833

9934
#ifdef WINDOWS_NATIVE
10035

@@ -119,7 +54,11 @@ initialize (void)
11954

12055
/* This is a wrapper for gettimeofday. It is used only on systems
12156
that lack this function, or whose implementation of this function
122-
causes problems. */
57+
causes problems.
58+
Work around the bug in some systems whereby gettimeofday clobbers
59+
the static buffer that localtime uses for its return value. The
60+
gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
61+
this problem. */
12362

12463
int
12564
gettimeofday (struct timeval *restrict tv, void *restrict tz)

lib/gnulib.mk.in

+21-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# the same distribution terms as the rest of that program.
2222
#
2323
# 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 --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
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=tzset --avoid=unsetenv --avoid=utime --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
2525

2626

2727
MOSTLYCLEANFILES += core *.stackdump
@@ -307,6 +307,7 @@ GNULIB_TIME_R = @GNULIB_TIME_R@
307307
GNULIB_TIME_RZ = @GNULIB_TIME_RZ@
308308
GNULIB_TMPFILE = @GNULIB_TMPFILE@
309309
GNULIB_TTYNAME_R = @GNULIB_TTYNAME_R@
310+
GNULIB_TZSET = @GNULIB_TZSET@
310311
GNULIB_UNISTD_H_NONBLOCKING = @GNULIB_UNISTD_H_NONBLOCKING@
311312
GNULIB_UNISTD_H_SIGPIPE = @GNULIB_UNISTD_H_SIGPIPE@
312313
GNULIB_UNLINK = @GNULIB_UNLINK@
@@ -504,6 +505,7 @@ HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@
504505
HAVE_TIMEGM = @HAVE_TIMEGM@
505506
HAVE_TIMEZONE_T = @HAVE_TIMEZONE_T@
506507
HAVE_TYPE_VOLATILE_SIG_ATOMIC_T = @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
508+
HAVE_TZSET = @HAVE_TZSET@
507509
HAVE_UNISTD_H = @HAVE_UNISTD_H@
508510
HAVE_UNLINKAT = @HAVE_UNLINKAT@
509511
HAVE_UNLOCKPT = @HAVE_UNLOCKPT@
@@ -780,6 +782,7 @@ REPLACE_SYMLINKAT = @REPLACE_SYMLINKAT@
780782
REPLACE_TIMEGM = @REPLACE_TIMEGM@
781783
REPLACE_TMPFILE = @REPLACE_TMPFILE@
782784
REPLACE_TTYNAME_R = @REPLACE_TTYNAME_R@
785+
REPLACE_TZSET = @REPLACE_TZSET@
783786
REPLACE_UNLINK = @REPLACE_UNLINK@
784787
REPLACE_UNLINKAT = @REPLACE_UNLINKAT@
785788
REPLACE_UNSETENV = @REPLACE_UNSETENV@
@@ -879,6 +882,7 @@ gamedir = @gamedir@
879882
gamegroup = @gamegroup@
880883
gameuser = @gameuser@
881884
gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7 = @gl_GNULIB_ENABLED_03e0aaad4cb89ca757653bd367a6ccb7@
885+
gl_GNULIB_ENABLED_2049e887c7e5308faad27b3f894bb8c9 = @gl_GNULIB_ENABLED_2049e887c7e5308faad27b3f894bb8c9@
882886
gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b = @gl_GNULIB_ENABLED_260941c0e5dc67ec9e87d1fb321c300b@
883887
gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31 = @gl_GNULIB_ENABLED_5264294aa0a5557541b53c8c741f7f31@
884888
gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c = @gl_GNULIB_ENABLED_6099e9737f757db36c47fa9d9f02e88c@
@@ -1700,6 +1704,19 @@ EXTRA_DIST += limits.in.h
17001704
endif
17011705
## end gnulib module limits-h
17021706

1707+
## begin gnulib module localtime-buffer
1708+
ifeq (,$(OMIT_GNULIB_MODULE_localtime-buffer))
1709+
1710+
ifneq (,$(gl_GNULIB_ENABLED_2049e887c7e5308faad27b3f894bb8c9))
1711+
1712+
endif
1713+
EXTRA_DIST += localtime-buffer.c localtime-buffer.h
1714+
1715+
EXTRA_libgnu_a_SOURCES += localtime-buffer.c
1716+
1717+
endif
1718+
## end gnulib module localtime-buffer
1719+
17031720
## begin gnulib module lstat
17041721
ifeq (,$(OMIT_GNULIB_MODULE_lstat))
17051722

@@ -2707,7 +2724,6 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
27072724
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
27082725
-e 's|@''NEXT_TIME_H''@|$(NEXT_TIME_H)|g' \
27092726
-e 's/@''GNULIB_CTIME''@/$(GNULIB_CTIME)/g' \
2710-
-e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
27112727
-e 's/@''GNULIB_LOCALTIME''@/$(GNULIB_LOCALTIME)/g' \
27122728
-e 's/@''GNULIB_MKTIME''@/$(GNULIB_MKTIME)/g' \
27132729
-e 's/@''GNULIB_NANOSLEEP''@/$(GNULIB_NANOSLEEP)/g' \
@@ -2716,11 +2732,13 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
27162732
-e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \
27172733
-e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \
27182734
-e 's/@''GNULIB_TIME_RZ''@/$(GNULIB_TIME_RZ)/g' \
2735+
-e 's/@''GNULIB_TZSET''@/$(GNULIB_TZSET)/g' \
27192736
-e 's|@''HAVE_DECL_LOCALTIME_R''@|$(HAVE_DECL_LOCALTIME_R)|g' \
27202737
-e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \
27212738
-e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \
27222739
-e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \
27232740
-e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \
2741+
-e 's|@''HAVE_TZSET''@|$(HAVE_TZSET)|g' \
27242742
-e 's|@''REPLACE_CTIME''@|$(REPLACE_CTIME)|g' \
27252743
-e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \
27262744
-e 's|@''REPLACE_LOCALTIME''@|$(REPLACE_LOCALTIME)|g' \
@@ -2729,6 +2747,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $(
27292747
-e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \
27302748
-e 's|@''REPLACE_STRFTIME''@|$(REPLACE_STRFTIME)|g' \
27312749
-e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \
2750+
-e 's|@''REPLACE_TZSET''@|$(REPLACE_TZSET)|g' \
27322751
-e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \
27332752
-e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \
27342753
-e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \

lib/localtime-buffer.c

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* Provide access to the last buffer returned by localtime() or gmtime().
2+
3+
Copyright (C) 2001-2003, 2005-2007, 2009-2017 Free Software Foundation, Inc.
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 3, or (at your option)
8+
any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, see <http://www.gnu.org/licenses/>. */
17+
18+
/* written by Jim Meyering */
19+
20+
#include <config.h>
21+
22+
/* Specification. */
23+
#include "localtime-buffer.h"
24+
25+
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
26+
27+
static struct tm tm_zero_buffer;
28+
struct tm *localtime_buffer_addr = &tm_zero_buffer;
29+
30+
/* This is a wrapper for localtime.
31+
32+
On the first call, record the address of the static buffer that
33+
localtime uses for its result. */
34+
35+
struct tm *
36+
rpl_localtime (time_t const *timep)
37+
{
38+
struct tm *tm = localtime (timep);
39+
40+
if (localtime_buffer_addr == &tm_zero_buffer)
41+
localtime_buffer_addr = tm;
42+
43+
return tm;
44+
}
45+
46+
/* Same as above, since gmtime and localtime use the same buffer. */
47+
struct tm *
48+
rpl_gmtime (time_t const *timep)
49+
{
50+
struct tm *tm = gmtime (timep);
51+
52+
if (localtime_buffer_addr == &tm_zero_buffer)
53+
localtime_buffer_addr = tm;
54+
55+
return tm;
56+
}
57+
58+
#endif

lib/localtime-buffer.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Provide access to the last buffer returned by localtime() or gmtime().
2+
3+
Copyright (C) 2001-2003, 2005-2007, 2009-2017 Free Software Foundation, Inc.
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; either version 3, or (at your option)
8+
any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program; if not, see <http://www.gnu.org/licenses/>. */
17+
18+
/* written by Jim Meyering */
19+
20+
#include <time.h>
21+
22+
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
23+
24+
/* The address of the last buffer returned by localtime() or gmtime(). */
25+
extern struct tm *localtime_buffer_addr;
26+
27+
#endif

lib/time.in.h

+20-2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ _GL_CXXALIAS_SYS (nanosleep, int,
120120
_GL_CXXALIASWARN (nanosleep);
121121
# endif
122122

123+
/* Initialize time conversion information. */
124+
# if @GNULIB_TZSET@
125+
# if @REPLACE_TZSET@
126+
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
127+
# undef tzset
128+
# define tzset rpl_tzset
129+
# endif
130+
_GL_FUNCDECL_RPL (tzset, void, (void));
131+
_GL_CXXALIAS_RPL (tzset, void, (void));
132+
# else
133+
# if ! @HAVE_TZSET@
134+
_GL_FUNCDECL_SYS (tzset, void, (void));
135+
# endif
136+
_GL_CXXALIAS_SYS (tzset, void, (void));
137+
# endif
138+
_GL_CXXALIASWARN (tzset);
139+
# endif
140+
123141
/* Return the 'time_t' representation of TP and normalize TP. */
124142
# if @GNULIB_MKTIME@
125143
# if @REPLACE_MKTIME@
@@ -187,7 +205,7 @@ _GL_CXXALIASWARN (gmtime_r);
187205
/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
188206
<http://www.opengroup.org/susv3xsh/localtime.html> and
189207
<http://www.opengroup.org/susv3xsh/gmtime.html>. */
190-
# if @GNULIB_LOCALTIME@ || @GNULIB_GETTIMEOFDAY@
208+
# if @GNULIB_LOCALTIME@ || @REPLACE_LOCALTIME@
191209
# if @REPLACE_LOCALTIME@
192210
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
193211
# undef localtime
@@ -202,7 +220,7 @@ _GL_CXXALIAS_SYS (localtime, struct tm *, (time_t const *__timer));
202220
_GL_CXXALIASWARN (localtime);
203221
# endif
204222

205-
# if @GNULIB_GETTIMEOFDAY@
223+
# if 0 || @REPLACE_GMTIME@
206224
# if @REPLACE_GMTIME@
207225
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
208226
# undef gmtime

lib/time_rz.c

-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
# define SIZE_MAX ((size_t) -1)
4141
#endif
4242

43-
#if !HAVE_TZSET
44-
static void tzset (void) { }
45-
#endif
46-
4743
/* The approximate size to use for small allocation requests. This is
4844
the largest "small" request for the GNU C library malloc. */
4945
enum { DEFAULT_MXFAST = 64 * sizeof (size_t) / 4 };

0 commit comments

Comments
 (0)