From a6fbda46c278750dec50b0b41a9a88026944dcb9 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 26 Jul 2020 13:46:35 +0200 Subject: [PATCH] gettimeofday: Remove workaround for Mac OS X 10.0. * m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY_CLOBBER): Remove macro. (gl_FUNC_GETTIMEOFDAY): Don't invoke it. * lib/gettimeofday.c: Don't include localtime-buffer.h. (gettimeofday): Don't test GETTIMEOFDAY_CLOBBERS_LOCALTIME. * lib/localtime.c: Don't test GETTIMEOFDAY_CLOBBERS_LOCALTIME. * modules/gettimeofday (Depends-on): Remove localtime-buffer. * modules/localtime-buffer: Remove file. * lib/localtime-buffer.h: Remove file. * lib/localtime-buffer.c: Remove file. * m4/localtime-buffer.m4: Remove file. * MODULES.html.sh (Date and time ): Remove localtime-buffer. --- ChangeLog | 15 ++++++++++ MODULES.html.sh | 1 - lib/gettimeofday.c | 11 -------- lib/localtime-buffer.c | 60 --------------------------------------- lib/localtime-buffer.h | 27 ------------------ lib/localtime.c | 15 ++++------ m4/gettimeofday.m4 | 61 +--------------------------------------- m4/localtime-buffer.m4 | 21 -------------- modules/gettimeofday | 1 - modules/localtime-buffer | 25 ---------------- 10 files changed, 21 insertions(+), 216 deletions(-) delete mode 100644 lib/localtime-buffer.c delete mode 100644 lib/localtime-buffer.h delete mode 100644 m4/localtime-buffer.m4 delete mode 100644 modules/localtime-buffer diff --git a/ChangeLog b/ChangeLog index a62ab5bee8..208af62c0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2020-07-26 Bruno Haible + + gettimeofday: Remove workaround for Mac OS X 10.0. + * m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY_CLOBBER): Remove macro. + (gl_FUNC_GETTIMEOFDAY): Don't invoke it. + * lib/gettimeofday.c: Don't include localtime-buffer.h. + (gettimeofday): Don't test GETTIMEOFDAY_CLOBBERS_LOCALTIME. + * lib/localtime.c: Don't test GETTIMEOFDAY_CLOBBERS_LOCALTIME. + * modules/gettimeofday (Depends-on): Remove localtime-buffer. + * modules/localtime-buffer: Remove file. + * lib/localtime-buffer.h: Remove file. + * lib/localtime-buffer.c: Remove file. + * m4/localtime-buffer.m4: Remove file. + * MODULES.html.sh (Date and time ): Remove localtime-buffer. + 2020-07-26 Bruno Haible tzset: Remove workaround for Solaris 2.6. diff --git a/MODULES.html.sh b/MODULES.html.sh index 43a6dba4ad..11a4a77468 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1727,7 +1727,6 @@ func_all_modules () func_begin_table func_module fprintftime - func_module localtime-buffer func_module nstrftime func_module strftime-fixes func_module time_rz diff --git a/lib/gettimeofday.c b/lib/gettimeofday.c index 305ab984e0..8b758a1061 100644 --- a/lib/gettimeofday.c +++ b/lib/gettimeofday.c @@ -29,8 +29,6 @@ # include #endif -#include "localtime-buffer.h" - #ifdef WINDOWS_NATIVE /* Don't assume that UNICODE is not defined. */ @@ -123,11 +121,6 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz) #else # if HAVE_GETTIMEOFDAY -# if GETTIMEOFDAY_CLOBBERS_LOCALTIME - /* Save and restore the contents of the buffer used for localtime's - result around the call to gettimeofday. */ - struct tm save = *localtime_buffer_addr; -# endif # if defined timeval /* 'struct timeval' overridden by gnulib? */ # undef timeval @@ -142,10 +135,6 @@ gettimeofday (struct timeval *restrict tv, void *restrict tz) int result = gettimeofday (tv, (struct timezone *) tz); # endif -# if GETTIMEOFDAY_CLOBBERS_LOCALTIME - *localtime_buffer_addr = save; -# endif - return result; # else diff --git a/lib/localtime-buffer.c b/lib/localtime-buffer.c deleted file mode 100644 index 91b073edd5..0000000000 --- a/lib/localtime-buffer.c +++ /dev/null @@ -1,60 +0,0 @@ -/* Provide access to the last buffer returned by localtime() or gmtime(). - - Copyright (C) 2001-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . */ - -/* written by Jim Meyering */ - -#include - -/* Specification. */ -#include "localtime-buffer.h" - -#if GETTIMEOFDAY_CLOBBERS_LOCALTIME - -static struct tm tm_zero_buffer; -struct tm *localtime_buffer_addr = &tm_zero_buffer; - -/* This is a wrapper for localtime. - - On the first call, record the address of the static buffer that - localtime uses for its result. */ - -struct tm * -rpl_localtime (time_t const *timep) -#undef localtime -{ - struct tm *tm = localtime (timep); - - if (localtime_buffer_addr == &tm_zero_buffer) - localtime_buffer_addr = tm; - - return tm; -} - -/* Same as above, since gmtime and localtime use the same buffer. */ -struct tm * -rpl_gmtime (time_t const *timep) -#undef gmtime -{ - struct tm *tm = gmtime (timep); - - if (localtime_buffer_addr == &tm_zero_buffer) - localtime_buffer_addr = tm; - - return tm; -} - -#endif diff --git a/lib/localtime-buffer.h b/lib/localtime-buffer.h deleted file mode 100644 index 9939d81cf6..0000000000 --- a/lib/localtime-buffer.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Provide access to the last buffer returned by localtime() or gmtime(). - - Copyright (C) 2001-2003, 2005-2007, 2009-2020 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . */ - -/* written by Jim Meyering */ - -#include - -#if GETTIMEOFDAY_CLOBBERS_LOCALTIME - -/* The address of the last buffer returned by localtime() or gmtime(). */ -extern struct tm *localtime_buffer_addr; - -#endif diff --git a/lib/localtime.c b/lib/localtime.c index 9070993941..f5e676750d 100644 --- a/lib/localtime.c +++ b/lib/localtime.c @@ -19,18 +19,15 @@ /* Specification. */ #include -/* Keep consistent with localtime-buffer.c! */ -#if !GETTIMEOFDAY_CLOBBERS_LOCALTIME +#include +#include -# include -# include - -# undef localtime +#undef localtime struct tm * rpl_localtime (const time_t *tp) { -# if defined _WIN32 && ! defined __CYGWIN__ +#if defined _WIN32 && ! defined __CYGWIN__ /* Rectify the value of the environment variable TZ. There are four possible kinds of such values: - Traditional US time zone names, e.g. "PST8PDT". Syntax: see @@ -56,9 +53,7 @@ rpl_localtime (const time_t *tp) const char *tz = getenv ("TZ"); if (tz != NULL && strchr (tz, '/') != NULL) _putenv ("TZ="); -# endif +#endif return localtime (tp); } - -#endif diff --git a/m4/gettimeofday.m4 b/m4/gettimeofday.m4 index c72b3eacc6..578ed49b07 100644 --- a/m4/gettimeofday.m4 +++ b/m4/gettimeofday.m4 @@ -1,4 +1,4 @@ -# serial 27 +# serial 28 # Copyright (C) 2001-2003, 2005, 2007, 2009-2020 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -19,7 +19,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY], if test $ac_cv_func_gettimeofday != yes; then HAVE_GETTIMEOFDAY=0 else - gl_FUNC_GETTIMEOFDAY_CLOBBER AC_CACHE_CHECK([for gettimeofday with POSIX signature], [gl_cv_func_gettimeofday_posix_signature], [AC_COMPILE_IFELSE( @@ -66,63 +65,5 @@ int gettimeofday (struct timeval *restrict, struct timezone *restrict); declaration of the second argument to gettimeofday.]) ]) - -dnl See if gettimeofday clobbers the static buffer that localtime uses -dnl for its return value. The gettimeofday function from Mac OS X 10.0.4 -dnl (i.e., Darwin 1.3.7) has this problem. -dnl -dnl If it does, then arrange to use gettimeofday and localtime only via -dnl the wrapper functions that work around the problem. - -AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER], -[ - AC_REQUIRE([gl_HEADER_SYS_TIME_H]) - AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles - AC_REQUIRE([gl_LOCALTIME_BUFFER_DEFAULTS]) - - AC_CACHE_CHECK([whether gettimeofday clobbers localtime buffer], - [gl_cv_func_gettimeofday_clobber], - [AC_RUN_IFELSE( - [AC_LANG_PROGRAM( - [[#include - #include - #include - #include - ]], - [[ - time_t t = 0; - struct tm *lt; - struct tm saved_lt; - struct timeval tv; - lt = localtime (&t); - saved_lt = *lt; - gettimeofday (&tv, NULL); - return memcmp (lt, &saved_lt, sizeof (struct tm)) != 0; - ]])], - [gl_cv_func_gettimeofday_clobber=no], - [gl_cv_func_gettimeofday_clobber=yes], - [# When cross-compiling: - case "$host_os" in - # Guess all is fine on glibc systems. - *-gnu* | gnu*) gl_cv_func_gettimeofday_clobber="guessing no" ;; - # Guess all is fine on musl systems. - *-musl*) gl_cv_func_gettimeofday_clobber="guessing no" ;; - # Guess no on native Windows. - mingw*) gl_cv_func_gettimeofday_clobber="guessing no" ;; - # If we don't know, obey --enable-cross-guesses. - *) gl_cv_func_gettimeofday_clobber="$gl_cross_guess_inverted" ;; - esac - ])]) - - case "$gl_cv_func_gettimeofday_clobber" in - *yes) - REPLACE_GETTIMEOFDAY=1 - AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1], - [Define if gettimeofday clobbers the localtime buffer.]) - gl_LOCALTIME_BUFFER_NEEDED - ;; - esac -]) - # Prerequisites of lib/gettimeofday.c. AC_DEFUN([gl_PREREQ_GETTIMEOFDAY], [:]) diff --git a/m4/localtime-buffer.m4 b/m4/localtime-buffer.m4 deleted file mode 100644 index 09df3c97f2..0000000000 --- a/m4/localtime-buffer.m4 +++ /dev/null @@ -1,21 +0,0 @@ -# localtime-buffer.m4 serial 1 -dnl Copyright (C) 2017-2020 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_LOCALTIME_BUFFER_DEFAULTS], -[ - NEED_LOCALTIME_BUFFER=0 -]) - -dnl Macro invoked from other modules, to signal that the compilation of -dnl module 'localtime-buffer' is needed. -AC_DEFUN([gl_LOCALTIME_BUFFER_NEEDED], -[ - AC_REQUIRE([gl_LOCALTIME_BUFFER_DEFAULTS]) - AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) - NEED_LOCALTIME_BUFFER=1 - REPLACE_GMTIME=1 - REPLACE_LOCALTIME=1 -]) diff --git a/modules/gettimeofday b/modules/gettimeofday index 106e7a7765..b4bdcc37c7 100644 --- a/modules/gettimeofday +++ b/modules/gettimeofday @@ -7,7 +7,6 @@ m4/gettimeofday.m4 Depends-on: sys_time -localtime-buffer [test $NEED_LOCALTIME_BUFFER = 1] configure.ac: gl_FUNC_GETTIMEOFDAY diff --git a/modules/localtime-buffer b/modules/localtime-buffer deleted file mode 100644 index e511d437b3..0000000000 --- a/modules/localtime-buffer +++ /dev/null @@ -1,25 +0,0 @@ -Description: -Access to the internal buffer of the localtime() function and the gmtime() function. - -Files: -lib/localtime-buffer.h -lib/localtime-buffer.c -m4/localtime-buffer.m4 - -Depends-on: -time [false] - -configure.ac: -AC_REQUIRE([gl_LOCALTIME_BUFFER_DEFAULTS]) -AC_LIBOBJ([localtime-buffer]) - -Makefile.am: - -Include: -"localtime-buffer.h" - -License: -LGPLv2+ - -Maintainer: -all -- 2.39.5