[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge f
From: |
Jim Meyering |
Subject: |
Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs |
Date: |
Mon, 09 Jun 2003 08:37:49 +0200 |
I wrote:
...
> What do you think about using a tzset wrapper/replacement
> that does *not* clobber localtime's buffer on losing systems?
I've done that, and checked it in to coreutils,
but savannah has not been reachable, so here are diffs:
lib:
2003-06-08 Jim Meyering <address@hidden>
Clean up, as part of merge with emacs version of strftime.c.
* strftime.c (my_strftime) [!_LIBC && HAVE_TZNAME && HAVE_TZSET]:
Remove function, now that we can rely on a working tzset function.
[!_LIBC]: Ensure that the required autoconf test has been run.
* gettimeofday.c: Also undef tzset.
(rpl_tzset): New function, for use by new macro, gl_FUNC_TZSET_CLOBBER.
m4:
2003-06-08 Jim Meyering <address@hidden>
* tzset.m4 (gl_FUNC_TZSET_CLOBBER): New file/macro.
Used by strftime.m4.
* strftime.m4 (_jm_STRFTIME_PREREQS): Require gl_FUNC_TZSET_CLOBBER.
cvs diff -r1.71 lib/strftime.c
Index: lib/gettimeofday.c
===================================================================
RCS file: /fetish/cu/lib/gettimeofday.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -p -u -r1.4 -r1.5
--- lib/gettimeofday.c 27 May 2002 16:42:55 -0000 1.4
+++ lib/gettimeofday.c 8 Jun 2003 17:37:48 -0000 1.5
@@ -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,11 @@
#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 localtime
+#undef tzset
#include <sys/types.h>
@@ -83,4 +85,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: lib/strftime.c
===================================================================
RCS file: /fetish/cu/lib/strftime.c,v
retrieving revision 1.71
retrieving revision 1.73
diff -u -p -r1.71 -r1.73
--- lib/strftime.c 29 May 2003 12:09:06 -0000 1.71
+++ lib/strftime.c 8 Jun 2003 18:03:01 -0000 1.73
@@ -493,25 +493,11 @@ static CHAR_T const month_name[][10] =
# define ns 0
#endif
-#if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET
- /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime.
- Work around this bug by copying *tp before it might be munged. */
- size_t _strftime_copytm __P ((char *, size_t, const char *,
- const struct tm * extra_args_spec_iso));
- size_t
- my_strftime (s, maxsize, format, tp extra_args)
- CHAR_T *s;
- size_t maxsize;
- const CHAR_T *format;
- const struct tm *tp;
- extra_args_spec
- {
- struct tm tmcopy;
- tmcopy = *tp;
- return _strftime_copytm (s, maxsize, format, &tmcopy extra_args);
- }
-# undef my_strftime
-# define my_strftime _strftime_copytm
+#if ! defined _LIBC && ! HAVE_RUN_TZSET_TEST
+/* Solaris 2.5.x and 2.6 tzset sometimes modify the storage returned
+ by localtime. On such systems, we must use the tzset and localtime
+ wrappers to work around the bug. */
+"you must run the autoconf test for a working tzset function"
#endif
Index: m4/tzset.m4
===================================================================
RCS file: m4/tzset.m4
diff -N m4/tzset.m4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ m4/tzset.m4 8 Jun 2003 17:43:53 -0000 1.2
@@ -0,0 +1,63 @@
+#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
+ AC_LIBOBJ(gettimeofday)
+ AC_DEFINE(localtime, rpl_localtime,
+ [Define to rpl_localtime if the replacement function should be used.])
+ 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
+])
Index: m4/strftime.m4
===================================================================
RCS file: /fetish/cu/m4/strftime.m4,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -p -u -r1.25 -r1.26
--- m4/strftime.m4 7 Jun 2003 16:27:44 -0000 1.25
+++ m4/strftime.m4 8 Jun 2003 17:42:31 -0000 1.26
@@ -1,4 +1,4 @@
-#serial 19
+#serial 20
dnl This macro is intended to be used solely in this file.
dnl These are the prerequisite macros for GNU's strftime.c replacement.
@@ -18,6 +18,7 @@ AC_DEFUN([_jm_STRFTIME_PREREQS],
AC_TYPE_MBSTATE_T
AC_REQUIRE([gl_TM_GMTOFF])
+ AC_REQUIRE([gl_FUNC_TZSET_CLOBBER])
])
dnl From Jim Meyering.
- Re: [Bug-gnulib] strftime merge from Emacs, (continued)
- Re: [Bug-gnulib] strftime merge from Emacs, Paul Eggert, 2003/06/05
- Re: [Bug-gnulib] strftime merge from Emacs, Dave Love, 2003/06/05
- Re: [Bug-gnulib] strftime merge from Emacs, Jim Meyering, 2003/06/05
- Re: [Bug-gnulib] strftime merge from Emacs, Paul Eggert, 2003/06/05
- [Bug-gnulib] access to Solaris2.5 system? [Re: strftime merge from Emacs, Jim Meyering, 2003/06/06
- [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Paul Eggert, 2003/06/07
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Jim Meyering, 2003/06/07
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Paul Eggert, 2003/06/09
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Jim Meyering, 2003/06/09
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs,
Jim Meyering <=
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Paul Eggert, 2003/06/09
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Jim Meyering, 2003/06/09
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Paul Eggert, 2003/06/09
- Re: [Bug-gnulib] Re: access to Solaris2.5 system? [Re: strftime merge from Emacs, Jim Meyering, 2003/06/09
- Re: [Bug-gnulib] strftime merge from Emacs, Dave Love, 2003/06/06
Re: [Bug-gnulib] strftime merge from Emacs, Karl Berry, 2003/06/04
Re: [Bug-gnulib] strftime merge from Emacs, Karl Berry, 2003/06/05