[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] new module tzset; fixes for gettimeofday
From: |
Paul Eggert |
Subject: |
[Bug-gnulib] new module tzset; fixes for gettimeofday |
Date: |
Thu, 14 Aug 2003 15:03:43 -0700 |
I merged the following changes from coreutils. The
gl_GETTIMEOFDAY_REPLACE_LOCALTIME macro is my own invention, though;
it removes duplication from gettimeofday.m4 and tzset.m4.
2003-08-14 Paul Eggert <address@hidden>
* lib/gettimeofday.c (rpl_gmtime, rpl_tzset): New functions.
* m4/gettimeofday.m4 (gl_GETTIMEOFDAY_REPLACE_LOCALTIME): New macro.
(AC_FUNC_GETTIMEOFDAY_CLOBBER): Use it.
* m4/tzset.m4: New file.
* modules/tzset: New file.
Index: lib/gettimeofday.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/gettimeofday.c,v
retrieving revision 1.4
diff -p -u -r1.4 gettimeofday.c
--- lib/gettimeofday.c 27 May 2002 16:42:55 -0000 1.4
+++ lib/gettimeofday.c 14 Aug 2003 21:51:23 -0000
@@ -1,7 +1,8 @@
/* Work around the bug in some systems whereby gettimeofday clobbers the
static buffer that localtime uses for it's return value. The gettimeofday
function from Mac OS X 10.0.4, i.e. Darwin 1.3.7 has this problem.
- Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ The tzset replacement is necessary for at least Solaris 2.5, 2.5.1, and 2.6.
+ Copyright (C) 2001, 2002, 2003 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
@@ -21,10 +22,12 @@
#include <config.h>
-/* Disable the definitions of gettimeofday and localtime (from config.h)
+/* Disable the definitions of these functions (from config.h)
so we can use the library versions here. */
#undef gettimeofday
+#undef gmtime
#undef localtime
+#undef tzset
#include <sys/types.h>
@@ -60,6 +63,18 @@ rpl_localtime (const time_t *timep)
return tm;
}
+/* Same as above, since gmtime and localtime use the same buffer. */
+struct tm *
+rpl_gmtime (const time_t *timep)
+{
+ struct tm *tm = gmtime (timep);
+
+ if (! localtime_buffer_addr)
+ localtime_buffer_addr = tm;
+
+ return tm;
+}
+
/* This is a wrapper for gettimeofday. It is used only on systems for which
gettimeofday clobbers the static buffer used for localtime's result.
@@ -83,4 +98,24 @@ rpl_gettimeofday (struct timeval *tv, st
*localtime_buffer_addr = save;
return result;
+}
+
+/* This is a wrapper for tzset. It is used only on systems for which
+ tzset may clobber the static buffer used for localtime's result.
+ Save and restore the contents of the buffer used for localtime's
+ result around the call to tzset. */
+void
+rpl_tzset (void)
+{
+ struct tm save;
+
+ if (! localtime_buffer_addr)
+ {
+ time_t t = 0;
+ localtime_buffer_addr = localtime (&t);
+ }
+
+ save = *localtime_buffer_addr;
+ tzset ();
+ *localtime_buffer_addr = save;
}
Index: m4/gettimeofday.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/gettimeofday.m4,v
retrieving revision 1.6
diff -p -u -r1.6 gettimeofday.m4
--- m4/gettimeofday.m4 31 Dec 2002 13:43:06 -0000 1.6
+++ m4/gettimeofday.m4 14 Aug 2003 21:51:23 -0000
@@ -1,4 +1,4 @@
-#serial 3
+#serial 4
dnl From Jim Meyering.
dnl
@@ -58,15 +58,22 @@ main ()
jm_cv_func_gettimeofday_clobber=yes)
])
if test $jm_cv_func_gettimeofday_clobber = yes; then
- AC_LIBOBJ(gettimeofday)
- AC_DEFINE(localtime, rpl_localtime,
- [Define to rpl_localtime if the replacement function should be used.])
+ gl_GETTIMEOFDAY_REPLACE_LOCALTIME
+
AC_DEFINE(gettimeofday, rpl_gettimeofday,
[Define to rpl_gettimeofday if the replacement function should be used.])
AC_DEFINE(GETTIMEOFDAY_CLOBBERS_LOCALTIME_BUFFER, 1,
[Define if gettimeofday clobbers localtime's static buffer.])
gl_PREREQ_GETTIMEOFDAY
fi
+])
+
+AC_DEFUN([gl_GETTIMEOFDAY_REPLACE_LOCALTIME], [
+ AC_LIBOBJ(gettimeofday)
+ AC_DEFINE(gmtime, rpl_gmtime,
+ [Define to rpl_gmtime if the replacement function should be used.])
+ AC_DEFINE(localtime, rpl_localtime,
+ [Define to rpl_localtime if the replacement function should be used.])
])
# Prerequisites of lib/gettimeofday.c.
--- /dev/null Tue Mar 18 13:55:57 2003
+++ modules/tzset Mon Aug 11 21:22:49 2003
@@ -0,0 +1,20 @@
+Description:
+tzset - initialize time conversion information
+
+Files:
+m4/tzset.m4
+
+Depends-on:
+gettimeofday
+
+configure.ac:
+gl_FUNC_TZSET_CLOBBER
+
+Makefile.am:
+
+Include:
+<time.h>
+
+Maintainer:
+Jim Meyering
+
--- /dev/null Tue Mar 18 13:55:57 2003
+++ m4/tzset.m4 Mon Aug 11 21:24:17 2003
@@ -0,0 +1,62 @@
+#serial 1
+# See if we have a working tzset function.
+# If so, arrange to compile the wrapper function.
+# For at least Solaris 2.5.1 and 2.6, this is necessary
+# because tzset can clobber the contents of the buffer
+# used by localtime.
+
+# Written by Paul Eggert and Jim Meyering.
+
+AC_DEFUN([gl_FUNC_TZSET_CLOBBER],
+[
+ AC_REQUIRE([AC_HEADER_TIME])
+ AC_CACHE_CHECK([whether tzset clobbers localtime buffer],
+ gl_cv_func_tzset_clobber,
+ [
+ AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+#include <stdlib.h>
+
+int
+main ()
+{
+ time_t t1 = 853958121;
+ struct tm *p, s;
+ putenv ("TZ=GMT0");
+ p = localtime (&t1);
+ s = *p;
+ putenv ("TZ=EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00");
+ tzset ();
+ exit (p->tm_year != s.tm_year
+ || p->tm_mon != s.tm_mon
+ || p->tm_mday != s.tm_mday
+ || p->tm_hour != s.tm_hour
+ || p->tm_min != s.tm_min
+ || p->tm_sec != s.tm_sec);
+}
+ ]])],
+ [gl_cv_func_tzset_clobber=no],
+ [gl_cv_func_tzset_clobber=yes],
+ [gl_cv_func_tzset_clobber=yes])])
+
+ AC_DEFINE(HAVE_RUN_TZSET_TEST, 1,
+ [Define to 1 if you have run the test for working tzset.])
+
+ if test $gl_cv_func_tzset_clobber = yes; then
+ gl_GETTIMEOFDAY_REPLACE_LOCALTIME
+
+ AC_DEFINE(tzset, rpl_tzset,
+ [Define to rpl_tzset if the wrapper function should be used.])
+ AC_DEFINE(TZSET_CLOBBERS_LOCALTIME_BUFFER, 1,
+ [Define if tzset clobbers localtime's static buffer.])
+ fi
+])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-gnulib] new module tzset; fixes for gettimeofday,
Paul Eggert <=